class Nanoc::RuleDSL::ActionProvider
Attributes
rules_collection[R]
@api private
Public Class Methods
for(site)
click to toggle source
# File lib/nanoc/rule_dsl/action_provider.rb, line 10 def self.for(site) rules_collection = Nanoc::RuleDSL::RulesCollection.new action_sequence_calculator = Nanoc::RuleDSL::ActionSequenceCalculator.new( rules_collection:, site:, ) action_provider = new(rules_collection, action_sequence_calculator) Nanoc::RuleDSL::RulesLoader.new(site.config, rules_collection).load action_provider end
new(rules_collection, action_sequence_calculator)
click to toggle source
# File lib/nanoc/rule_dsl/action_provider.rb, line 25 def initialize(rules_collection, action_sequence_calculator) @rules_collection = rules_collection @action_sequence_calculator = action_sequence_calculator end
Public Instance Methods
action_sequence_for(obj)
click to toggle source
# File lib/nanoc/rule_dsl/action_provider.rb, line 37 def action_sequence_for(obj) @action_sequence_calculator[obj] end
need_preprocessing?()
click to toggle source
# File lib/nanoc/rule_dsl/action_provider.rb, line 41 def need_preprocessing? @rules_collection.preprocessors.any? end
new_postprocessor_context(site, view_context)
click to toggle source
@api private
# File lib/nanoc/rule_dsl/action_provider.rb, line 90 def new_postprocessor_context(site, view_context) Nanoc::Core::Context.new( config: Nanoc::Core::ConfigView.new(site.config, view_context), items: Nanoc::Core::PostCompileItemCollectionView.new(site.items, view_context), ) end
new_preprocessor_context(site)
click to toggle source
@api private
# File lib/nanoc/rule_dsl/action_provider.rb, line 78 def new_preprocessor_context(site) view_context = Nanoc::Core::ViewContextForPreCompilation.new(items: site.items) Nanoc::Core::Context.new( config: Nanoc::Core::MutableConfigView.new(site.config, view_context), items: Nanoc::Core::MutableItemCollectionView.new(site.items, view_context), layouts: Nanoc::Core::MutableLayoutCollectionView.new(site.layouts, view_context), ) end
postprocess(site, compiler)
click to toggle source
# File lib/nanoc/rule_dsl/action_provider.rb, line 56 def postprocess(site, compiler) dependency_tracker = Nanoc::Core::DependencyTracker::Null.new res = compiler.run_until_reps_built reps = res.fetch(:reps) view_context = Nanoc::Core::ViewContextForCompilation.new( reps:, items: site.items, dependency_tracker:, compilation_context: compiler.compilation_context(reps:), compiled_content_store: Nanoc::Core::CompiledContentStore.new, ) ctx = new_postprocessor_context(site, view_context) @rules_collection.postprocessors.each_value do |postprocessor| ctx.instance_eval(&postprocessor) end end
preprocess(site)
click to toggle source
# File lib/nanoc/rule_dsl/action_provider.rb, line 45 def preprocess(site) ctx = new_preprocessor_context(site) @rules_collection.preprocessors.each_value do |preprocessor| ctx.instance_eval(&preprocessor) end site.data_source = Nanoc::Core::InMemoryDataSource.new(ctx.items._unwrap, ctx.layouts._unwrap, site.data_source) end
rep_names_for(item)
click to toggle source
# File lib/nanoc/rule_dsl/action_provider.rb, line 30 def rep_names_for(item) matching_rules = @rules_collection.item_compilation_rules_for(item) raise Nanoc::RuleDSL::Errors::NoMatchingCompilationRuleFound.new(item) if matching_rules.empty? matching_rules.map(&:rep_name).uniq end