Class: Nanoc::RuleDSL::ActionProvider
- Inherits:
-
Int::ActionProvider
- Object
- Int::ActionProvider
- Nanoc::RuleDSL::ActionProvider
- Defined in:
- lib/nanoc/rule_dsl/action_provider.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#action_sequence_for(rep) ⇒ Object
-
#initialize(rules_collection, action_sequence_calculator) ⇒ ActionProvider
constructor
A new instance of ActionProvider.
-
#need_preprocessing? ⇒ Boolean
-
#postprocess(site, compiler, reps) ⇒ Object
-
#preprocess(site) ⇒ Object
-
#rep_names_for(item) ⇒ Object
Constructor Details
#initialize(rules_collection, action_sequence_calculator) ⇒ ActionProvider
Returns a new instance of ActionProvider
25 26 27 28 |
# 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 |
Class Method Details
.for(site) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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: rules_collection, site: site, ) action_provider = new(rules_collection, action_sequence_calculator) Nanoc::RuleDSL::RulesLoader.new(site.config, rules_collection).load action_provider end |
Instance Method Details
#action_sequence_for(rep) ⇒ Object
37 38 39 |
# File 'lib/nanoc/rule_dsl/action_provider.rb', line 37 def action_sequence_for(rep) @action_sequence_calculator[rep] end |
#need_preprocessing? ⇒ Boolean
41 42 43 |
# File 'lib/nanoc/rule_dsl/action_provider.rb', line 41 def need_preprocessing? @rules_collection.preprocessors.any? end |
#postprocess(site, compiler, reps) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/nanoc/rule_dsl/action_provider.rb', line 56 def postprocess(site, compiler, reps) dependency_tracker = Nanoc::Int::DependencyTracker::Null.new res = compiler.run_until_reps_built reps = res.fetch(:reps) view_context = Nanoc::ViewContextForCompilation.new( reps: reps, items: site.items, dependency_tracker: dependency_tracker, compilation_context: compiler.compilation_context(reps: reps), snapshot_repo: nil, ) ctx = new_postprocessor_context(site, view_context) @rules_collection.postprocessors.each_value do |postprocessor| ctx.instance_eval(&postprocessor) end end |
#preprocess(site) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# 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::Int::InMemDataSource.new(ctx.items.unwrap, ctx.layouts.unwrap) end |
#rep_names_for(item) ⇒ Object
30 31 32 33 34 35 |
# 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::Int::Errors::NoMatchingCompilationRuleFound.new(item) if matching_rules.empty? matching_rules.map(&:rep_name).uniq end |