lib/nanoc/base/compilation/compiler.rb in nanoc-4.1.0a1 vs lib/nanoc/base/compilation/compiler.rb in nanoc-4.1.0b1
- old
+ new
@@ -47,68 +47,49 @@
#
# @return [Array] The compilation stack
attr_reader :stack
# @api private
- attr_reader :rules_collection
-
- # @api private
attr_reader :compiled_content_cache
# @api private
attr_reader :checksum_store
# @api private
attr_reader :rule_memory_store
# @api private
- attr_reader :rule_memory_calculator
+ attr_reader :action_provider
# @api private
attr_reader :dependency_store
# @api private
attr_reader :outdatedness_checker
# @api private
attr_reader :reps
- def initialize(site, rules_collection, compiled_content_cache:, checksum_store:, rule_memory_store:, rule_memory_calculator:, dependency_store:, outdatedness_checker:, reps:)
+ def initialize(site, compiled_content_cache:, checksum_store:, rule_memory_store:, action_provider:, dependency_store:, outdatedness_checker:, reps:)
@site = site
- @rules_collection = rules_collection
@compiled_content_cache = compiled_content_cache
@checksum_store = checksum_store
@rule_memory_store = rule_memory_store
- @rule_memory_calculator = rule_memory_calculator
@dependency_store = dependency_store
@outdatedness_checker = outdatedness_checker
@reps = reps
+ @action_provider = action_provider
@stack = []
end
- # 1. Load site
- # 2. Load rules
- # 3. Preprocess
- # 4. Build item reps
- # 5. Compile
- # 6. Postprocess
-
- # TODO: move elsewhere
def run_all
- # Preprocess
- Nanoc::Int::Preprocessor.new(site: @site, rules_collection: @rules_collection).run
-
- # Build reps
+ @action_provider.preprocess(@site)
build_reps
-
- # Compile
run
-
- # Postprocess
- Nanoc::Int::Postprocessor.new(create_view_context, site: @site, rules_collection: @rules_collection).run
+ @action_provider.postprocess(@site, @reps)
end
def run
load_stores
@site.freeze
@@ -137,34 +118,27 @@
#
# @return [void]
def store
# Calculate rule memory
(@reps.to_a + @site.layouts.to_a).each do |obj|
- rule_memory_store[obj] = rule_memory_calculator[obj].serialize
+ rule_memory_store[obj] = action_provider.memory_for(obj).serialize
end
# Calculate checksums
- objects.each do |obj|
+ objects_to_checksum =
+ site.items.to_a + site.layouts.to_a + site.code_snippets + [site.config]
+ objects_to_checksum.each do |obj|
checksum_store[obj] = Nanoc::Int::Checksummer.calc(obj)
end
# Store
stores.each(&:store)
end
- # Returns all objects managed by the site (items, layouts, code snippets,
- # site configuration and the rules).
- #
- # @api private
- def objects
- site.items.to_a + site.layouts.to_a + site.code_snippets +
- [site.config, rules_collection]
- end
-
def build_reps
builder = Nanoc::Int::ItemRepBuilder.new(
- site, rules_collection, rule_memory_calculator, @reps)
+ site, action_provider, @reps)
builder.run
end
# @param [Nanoc::Int::ItemRep] rep The item representation for which the
# assigns should be fetched
@@ -196,20 +170,30 @@
def create_view_context
Nanoc::ViewContext.new(reps: @reps, items: @site.items)
end
+ # @api private
+ def filter_name_and_args_for_layout(layout)
+ mem = action_provider.memory_for(layout)
+ if mem.nil? || mem.size != 1 || !mem[0].is_a?(Nanoc::Int::RuleMemoryActions::Filter)
+ # FIXME: Provide a nicer error message
+ raise Nanoc::Int::Errors::Generic, "No rule memory found for #{layout.identifier}"
+ end
+ [mem[0].filter_name, mem[0].params]
+ end
+
private
def compile_reps
# Listen to processing start/stop
Nanoc::Int::NotificationCenter.on(:processing_started, self) { |obj| @stack.push(obj) }
Nanoc::Int::NotificationCenter.on(:processing_ended, self) { |_obj| @stack.pop }
# Assign snapshots
@reps.each do |rep|
- rep.snapshot_defs = rule_memory_calculator.snapshots_defs_for(rep)
+ rep.snapshot_defs = action_provider.snapshots_defs_for(rep)
end
# Find item reps to compile and compile them
selector = Nanoc::Int::ItemRepSelector.new(@reps)
selector.each do |rep|
@@ -262,15 +246,21 @@
# @return [void]
def recalculate_content_for_rep(rep)
executor = Nanoc::Int::Executor.new(self)
- executor.snapshot(rep, :raw)
- executor.snapshot(rep, :pre, final: false)
- rules_collection.compilation_rule_for(rep)
- .apply_to(rep, executor: executor, site: @site, view_context: create_view_context)
- executor.snapshot(rep, :post) if rep.has_snapshot?(:post)
- executor.snapshot(rep, :last)
+ action_provider.memory_for(rep).each do |action|
+ case action
+ when Nanoc::Int::RuleMemoryActions::Filter
+ executor.filter(rep, action.filter_name, action.params)
+ when Nanoc::Int::RuleMemoryActions::Layout
+ executor.layout(rep, action.layout_identifier, action.params)
+ when Nanoc::Int::RuleMemoryActions::Snapshot
+ executor.snapshot(rep, action.snapshot_name, final: action.final?, path: action.path)
+ else
+ raise "Internal inconsistency: unknown action #{action.inspect}"
+ end
+ end
end
# Clears the list of dependencies for items that will be recompiled.
#
# @return [void]