Clean up regeneration missing-destination checks

Use easier-to-follow checks for missing-destinations in the regenerator.
This commit is contained in:
Nicholas Burlett 2015-03-24 21:21:37 -07:00
parent 706007ead9
commit 8f4194eea5
2 changed files with 16 additions and 17 deletions

View File

@ -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]

View File

@ -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