From 8f4194eea522ca4a721e30b138ffd3c5ae5b1e18 Mon Sep 17 00:00:00 2001 From: Nicholas Burlett Date: Tue, 24 Mar 2015 21:21:37 -0700 Subject: [PATCH] Clean up regeneration missing-destination checks Use easier-to-follow checks for missing-destinations in the regenerator. --- lib/jekyll/regenerator.rb | 27 +++++++++++++-------------- test/test_site.rb | 6 +++--- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/jekyll/regenerator.rb b/lib/jekyll/regenerator.rb index efe3c14c..7bff5327 100644 --- a/lib/jekyll/regenerator.rb +++ b/lib/jekyll/regenerator.rb @@ -18,21 +18,19 @@ module Jekyll def regenerate?(document) case document when Post, Page - return ( document.asset_file? || - document.data['regenerate'] || - source_modified_or_dest_missing?( - site.in_source_dir(document.relative_path), - document.destination(@site.dest)) ) + document.asset_file? || document.data['regenerate'] || + source_modified_or_dest_missing?( + site.in_source_dir(document.relative_path), document.destination(@site.dest) + ) when Document - return ( !document.write? || - document.data['regenerate'] || - source_modified_or_dest_missing?( - document.path, - document.destination(@site.dest)) ) + !document.write? || document.data['regenerate'] || + source_modified_or_dest_missing?( + document.path, document.destination(@site.dest) + ) else source_path = document.respond_to?(:path) ? document.path : nil dest_path = document.respond_to?(:destination) ? document.destination(@site.dest) : nil - return source_modified_or_dest_missing?(source_path, dest_path) + source_modified_or_dest_missing?(source_path, dest_path) end end @@ -78,9 +76,7 @@ module Jekyll # # returns a boolean def source_modified_or_dest_missing?(source_path, dest_path) - source_modified = source_path ? modified?(source_path) : true - dest_missing = dest_path ? !File.exist?(dest_path) : false - return source_modified || dest_missing + modified?(source_path) || ((dest_path and !File.exist?(dest_path)) or false) end # Checks if a path's (or one of its dependencies) @@ -90,6 +86,9 @@ module Jekyll def modified?(path) return true if disabled? + # objects that don't have a path are always regenerated + return true if path.nil? + # Check for path in cache if cache.has_key? path return cache[path] diff --git a/test/test_site.rb b/test/test_site.rb index db0e490f..23fe9f7c 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -505,11 +505,11 @@ class TestSite < JekyllUnitTest # simulate file modification by user File.unlink dest - refute File.exist?(dest) + refute File.file?(dest) - sleep 1 + sleep 1 # sleep for 1 second, since mtimes have 1s resolution @site.process - assert File.exist?(dest) + assert File.file?(dest) mtime2 = File.stat(dest).mtime.to_i refute_equal mtime1, mtime2 # must be regenerated end