Move all regenerate? checking to Regenerator

This commit is contained in:
Alfred Xing
2015-01-18 11:05:06 -08:00
parent e58f8776b9
commit fe5f0d124c
12 changed files with 239 additions and 180 deletions

View File

@@ -51,11 +51,11 @@ module Jekyll
autoload :Layout, 'jekyll/layout'
autoload :LayoutReader, 'jekyll/layout_reader'
autoload :LogAdapter, 'jekyll/log_adapter'
autoload :Metadata, 'jekyll/metadata'
autoload :Page, 'jekyll/page'
autoload :PluginManager, 'jekyll/plugin_manager'
autoload :Post, 'jekyll/post'
autoload :Publisher, 'jekyll/publisher'
autoload :Regenerator, 'jekyll/regenerator'
autoload :RelatedPosts, 'jekyll/related_posts'
autoload :Renderer, 'jekyll/renderer'
autoload :Site, 'jekyll/site'

View File

@@ -29,7 +29,7 @@ module Jekyll
#
# Returns an Array with the metdata file as the only item
def metadata_file
[site.metadata.metadata_file]
[site.regenerator.metadata_file]
end
# Private: The list of existing files, apart from those included in keep_files and hidden files.

View File

@@ -168,15 +168,6 @@ module Jekyll
true
end
# Determine whether to regenerate the file based on metadata.
#
# Returns true if file needs to be regenerated
def regenerate?
asset_file? ||
data['regenerate'] ||
site.metadata.regenerate?(site.in_source_dir(relative_path))
end
# Determine whether the file should be placed into layouts.
#
# Returns false if the document is an asset file.
@@ -217,7 +208,7 @@ module Jekyll
File.join(site.config['layouts'], layout.name))
# Add layout to dependency tree
site.metadata.add_dependency(
site.regenerator.add_dependency(
site.in_source_dir(path),
site.in_source_dir(layout.path)
)

View File

@@ -107,13 +107,6 @@ module Jekyll
!(coffeescript_file? || yaml_file?)
end
# Determine whether the document should be regenerated based on metadata.
#
# Returns true if the document needs to be regenerated.
def regenerate?
data['regenerate'] || site.metadata.regenerate?(path, write?)
end
# Determine whether the file should be placed into layouts.
#
# Returns false if the document is either an asset file or a yaml file,

View File

@@ -1,5 +1,5 @@
module Jekyll
class Metadata
class Regenerator
attr_reader :site, :metadata, :cache
def initialize(site)
@@ -12,6 +12,25 @@ module Jekyll
@cache = {}
end
# Checks if a renderable object needs to be regenerated
#
# Returns a boolean.
def regenerate?(document)
case document
when Post, Page
document.asset_file? || document.data['regenerate'] ||
modified?(site.in_source_dir(document.relative_path))
when Document
!document.write? || document.data['regenerate'] || modified?(document.path)
else
if document.respond_to?(:path)
modified?(document.path)
else
true
end
end
end
# Add a path to the metadata
#
# Returns true, also on failure.
@@ -40,10 +59,11 @@ module Jekyll
@cache = {}
end
# Checks if a path should be regenerated
# Checks if a path's (or one of its dependencies)
# mtime has changed
#
# Returns a boolean.
def regenerate?(path, add = true)
def modified?(path)
return true if disabled?
# Check for path in cache
@@ -55,19 +75,19 @@ module Jekyll
data = metadata[path]
if data
data["deps"].each do |dependency|
if regenerate?(dependency)
if modified?(dependency)
return cache[dependency] = cache[path] = true
end
end
if data["mtime"].eql? File.mtime(path)
return cache[path] = false
else
return !add || add(path)
return add(path)
end
end
# Path does not exist in metadata, add it
return !add || add(path)
return add(path)
end
# Add a dependency of a path

View File

@@ -140,7 +140,7 @@ module Jekyll
)
# Add layout to dependency tree
site.metadata.add_dependency(
site.regenerator.add_dependency(
site.in_source_dir(document.path),
site.in_source_dir(layout.path)
) if document.write?

View File

@@ -11,7 +11,7 @@ module Jekyll
:gems, :plugin_manager
attr_accessor :converters, :generators
attr_reader :metadata
attr_reader :regenerator
# Public: Initialize a new Site.
#
@@ -28,8 +28,8 @@ module Jekyll
@source = File.expand_path(config['source']).freeze
@dest = File.expand_path(config['destination']).freeze
# Build metadata
@metadata = Metadata.new(self)
# Initialize incremental regenerator
@regenerator = Regenerator.new(self)
self.plugin_manager = Jekyll::PluginManager.new(self)
self.plugins = plugin_manager.plugins_path
@@ -295,13 +295,17 @@ module Jekyll
payload = site_payload
collections.each do |label, collection|
collection.docs.each do |document|
document.output = Jekyll::Renderer.new(self, document, payload).run if document.regenerate?
if regenerator.regenerate?(document)
document.output = Jekyll::Renderer.new(self, document, payload).run
end
end
end
payload = site_payload
[posts, pages].flatten.each do |page_or_post|
page_or_post.render(layouts, payload) if page_or_post.regenerate?
if regenerator.regenerate?(page_or_post)
page_or_post.render(layouts, payload)
end
end
rescue Errno::ENOENT
# ignore missing layout dir
@@ -319,9 +323,9 @@ module Jekyll
# Returns nothing.
def write
each_site_file { |item|
item.write(dest) if item.regenerate?
item.write(dest) if regenerator.regenerate?(item)
}
metadata.write unless full_rebuild?
regenerator.write unless full_rebuild?
end
# Construct a Hash of Posts indexed by the specified Post attribute.
@@ -487,7 +491,7 @@ module Jekyll
@frontmatter_defaults ||= FrontmatterDefaults.new(self)
end
# Whether to perform a full rebuild without metadata
# Whether to perform a full rebuild without incremental regeneration
#
# Returns a Boolean: true for a full rebuild, false for normal build
def full_rebuild?(override = {})

View File

@@ -65,8 +65,6 @@ module Jekyll
true
end
alias_method :regenerate?, :write?
# Write the static file to the destination directory (if modified).
#
# dest - The String path to the destination dir.

View File

@@ -116,7 +116,7 @@ eos
# Add include to dependency tree
if context.registers[:page] and context.registers[:page].has_key? "path"
site.metadata.add_dependency(
site.regenerator.add_dependency(
site.in_source_dir(context.registers[:page]["path"]),
path
)