From fe6bfc6f1b2540dad111153d855a5ec91b2fbf33 Mon Sep 17 00:00:00 2001 From: Alfred Xing Date: Fri, 21 Nov 2014 21:54:18 -0800 Subject: [PATCH] Fix failing tests --- lib/jekyll/cleaner.rb | 3 ++- lib/jekyll/metadata.rb | 15 ++++++++++++--- lib/jekyll/renderer.rb | 2 +- lib/jekyll/site.rb | 5 ++--- lib/jekyll/tags/include.rb | 10 ++++++---- test/helper.rb | 1 + test/test_document.rb | 3 ++- test/test_site.rb | 15 +++++++++++---- 8 files changed, 37 insertions(+), 17 deletions(-) diff --git a/lib/jekyll/cleaner.rb b/lib/jekyll/cleaner.rb index 79f97f47..e7ee44a0 100644 --- a/lib/jekyll/cleaner.rb +++ b/lib/jekyll/cleaner.rb @@ -13,6 +13,7 @@ module Jekyll # Cleans up the site's destination directory def cleanup! FileUtils.rm_rf(obsolete_files) + FileUtils.rm_rf(metadata_file) if @site.config["clean"] end private @@ -21,7 +22,7 @@ module Jekyll # # Returns an Array of the file and directory paths def obsolete_files - (existing_files - new_files - new_dirs + replaced_files + metadata_file).to_a + (existing_files - new_files - new_dirs + replaced_files).to_a end # Private: The metadata file storing dependency tree and build history diff --git a/lib/jekyll/metadata.rb b/lib/jekyll/metadata.rb index 72cf8d15..275ee9da 100644 --- a/lib/jekyll/metadata.rb +++ b/lib/jekyll/metadata.rb @@ -33,10 +33,18 @@ module Jekyll @cache[path] = true end + # Clear the metadata and cache + # + # Returns nothing + def clear + @metadata = {} + @cache = {} + end + # Checks if a path should be regenerated # # Returns a boolean. - def regenerate?(path) + def regenerate?(path, add = true) # Check for path in cache if @cache.has_key? path return @cache[path] @@ -52,18 +60,19 @@ module Jekyll if data["mtime"] == File.mtime(path) return @cache[path] = false else - return add(path) + return !add || add(path) end end # Path does not exist in metadata, add it - return add(path) + return !add || add(path) end # Add a dependency of a path # # Returns nothing. def add_dependency(path, dependency) + add(path) if @metadata[path].nil? @metadata[path]["deps"] << dependency unless @metadata[path]["deps"].include? dependency regenerate? dependency end diff --git a/lib/jekyll/renderer.rb b/lib/jekyll/renderer.rb index 61839353..d2dd095f 100644 --- a/lib/jekyll/renderer.rb +++ b/lib/jekyll/renderer.rb @@ -142,7 +142,7 @@ module Jekyll site.metadata.add_dependency( Jekyll.sanitized_path(site.source, document.path), Jekyll.sanitized_path(site.source, layout.path) - ) + ) if document.write? if layout = site.layouts[layout.data["layout"]] if used.include?(layout) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 3894a2ba..f00e24c9 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -53,7 +53,7 @@ module Jekyll read generate render - cleanup if config['clean'] + cleanup write end @@ -294,10 +294,9 @@ module Jekyll collections.each do |label, collection| collection.docs.each do |document| document.output = Jekyll::Renderer.new(self, document).run if ( - @metadata.regenerate?(document.path) || + @metadata.regenerate?(document.path, document.write?) || document.data['regenerate'] ) - end end end diff --git a/lib/jekyll/tags/include.rb b/lib/jekyll/tags/include.rb index 8f7da2ca..49e7357e 100644 --- a/lib/jekyll/tags/include.rb +++ b/lib/jekyll/tags/include.rb @@ -115,10 +115,12 @@ eos validate_path(path, dir, site.safe) # Add include to dependency tree - site.metadata.add_dependency( - Jekyll.sanitized_path(site.source, context.registers[:page]["path"]), - path - ) + if context.registers[:page] and context.registers[:page].has_key? "path" + site.metadata.add_dependency( + Jekyll.sanitized_path(site.source, context.registers[:page]["path"]), + path + ) + end begin partial = Liquid::Template.parse(source(path, context)) diff --git a/test/helper.rb b/test/helper.rb index ea3777ed..58d9e24a 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -46,6 +46,7 @@ class Test::Unit::TestCase def clear_dest FileUtils.rm_rf(dest_dir) + FileUtils.rm_rf(source_dir('.jekyll-metadata')) end def test_dir(*subdirs) diff --git a/test/test_document.rb b/test/test_document.rb index 90c16b82..cf6c2cbf 100644 --- a/test/test_document.rb +++ b/test/test_document.rb @@ -246,7 +246,8 @@ class TestDocument < Test::Unit::TestCase } }, "source" => source_dir, - "destination" => dest_dir + "destination" => dest_dir, + "clean" => true })) @site.process @document = @site.collections["slides"].files.find { |doc| doc.relative_path == "_slides/octojekyll.png" } diff --git a/test/test_site.rb b/test/test_site.rb index 4b8409e7..2fd6ad36 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -99,6 +99,7 @@ class TestSite < Test::Unit::TestCase should "write only modified static files" do clear_dest StaticFile.reset_cache + @site.metadata.clear @site.process some_static_file = @site.static_files[0].path @@ -128,6 +129,7 @@ class TestSite < Test::Unit::TestCase should "write static files if not modified but missing in destination" do clear_dest StaticFile.reset_cache + @site.metadata.clear @site.process some_static_file = @site.static_files[0].path @@ -241,6 +243,7 @@ class TestSite < Test::Unit::TestCase context 'with orphaned files in destination' do setup do clear_dest + @site.metadata.clear @site.process # generate some orphaned files: # single file @@ -328,7 +331,7 @@ class TestSite < Test::Unit::TestCase end bad_processor = "Custom::Markdown" - s = Site.new(site_configuration('markdown' => bad_processor)) + s = Site.new(site_configuration('markdown' => bad_processor, 'clean' => true)) assert_raise Jekyll::Errors::FatalException do s.process end @@ -348,7 +351,7 @@ class TestSite < Test::Unit::TestCase should 'throw FatalException at process time' do bad_processor = 'not a processor name' - s = Site.new(site_configuration('markdown' => bad_processor)) + s = Site.new(site_configuration('markdown' => bad_processor, 'clean' => true)) assert_raise Jekyll::Errors::FatalException do s.process end @@ -418,7 +421,9 @@ class TestSite < Test::Unit::TestCase context "manipulating the Jekyll environment" do setup do - @site = Site.new(site_configuration) + @site = Site.new(site_configuration({ + "clean" => true + })) @site.process @page = @site.pages.find { |p| p.name == "environment.html" } end @@ -430,7 +435,9 @@ class TestSite < Test::Unit::TestCase context "in production" do setup do ENV["JEKYLL_ENV"] = "production" - @site = Site.new(site_configuration) + @site = Site.new(site_configuration({ + "clean" => true + })) @site.process @page = @site.pages.find { |p| p.name == "environment.html" } end