Class: Nanoc3::RulesCollection Private
- Inherits:
-
Object
- Object
- Nanoc3::RulesCollection
- Extended by:
- Memoization
- Defined in:
- lib/nanoc3/base/compilation/rules_collection.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Keeps track of the rules in a site.
Instance Attribute Summary collapse
-
#item_compilation_rules ⇒ Array<Nanoc3::Rule>
readonly
private
The list of item compilation rules that will be used to compile items.
-
#item_routing_rules ⇒ Array<Nanoc3::Rule>
readonly
private
The list of routing rules that will be used to give all items a path.
-
#layout_filter_mapping ⇒ Hash
readonly
private
The hash containing layout-to-filter mapping rules.
-
#preprocessor ⇒ Proc
private
The code block that will be executed after all data is loaded but before the site is compiled.
Instance Method Summary collapse
-
#add_item_compilation_rule(rule, position = :after) ⇒ void
private
Add the given rule to the list of item compilation rules.
-
#add_item_routing_rule(rule, position = :after) ⇒ void
private
Add the given rule to the list of item routing rules.
-
#checksum ⇒ String
private
The checksum for this object.
-
#compilation_rule_for(rep) ⇒ Nanoc3::Rule?
private
Finds the first matching compilation rule for the given item representation.
-
#dsl ⇒ Object
private
Returns the Nanoc3::CompilerDSL that should be used for this site.
-
#filter_for_layout(layout) ⇒ Array?
private
Finds the filter name and arguments to use for the given layout.
-
#initialize(compiler) ⇒ RulesCollection
constructor
private
A new instance of RulesCollection.
- #inspect ⇒ Object private
-
#item_compilation_rules_for(item) ⇒ Array
private
The list of item compilation rules for the given item.
-
#load ⇒ void
private
Loads this site’s rules.
-
#new_rule_memory_for_layout(layout) ⇒ Array
private
The rule memory for the given layout.
-
#new_rule_memory_for_rep(rep) ⇒ Array
private
The rule memory for the given item representation.
-
#reference ⇒ Object
private
Returns an object that can be used for uniquely identifying objects.
-
#routing_rule_for(rep) ⇒ Nanoc3::Rule?
private
Finds the first matching routing rule for the given item representation.
-
#routing_rules_for(rep) ⇒ Hash<Symbol, Nanoc3::Rule>
private
Returns the list of routing rules that can be applied to the given item representation.
-
#rule_memory_calculator ⇒ Nanoc3::RuleMemoryCalculator
private
The rule memory calculator.
-
#rule_memory_differs_for(obj) ⇒ Boolean
private
changed since the last compilation, false otherwise.
-
#rule_memory_store ⇒ Nanoc3::RuleMemoryStore
private
The rule memory store.
-
#unload ⇒ void
private
Unloads this site’s rules.
Methods included from Memoization
Constructor Details
#initialize(compiler) ⇒ RulesCollection
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of RulesCollection.
31 32 33 34 35 36 37 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 31 def initialize(compiler) @compiler = compiler @item_compilation_rules = [] @item_routing_rules = [] @layout_filter_mapping = OrderedHash.new end |
Instance Attribute Details
#item_compilation_rules ⇒ Array<Nanoc3::Rule> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The list of item compilation rules that will be used to compile items.
14 15 16 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 14 def item_compilation_rules @item_compilation_rules end |
#item_routing_rules ⇒ Array<Nanoc3::Rule> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The list of routing rules that will be used to give all items a path.
18 19 20 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 18 def item_routing_rules @item_routing_rules end |
#layout_filter_mapping ⇒ Hash (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The hash containing layout-to-filter mapping rules. This hash is ordered: iterating over the hash will happen in insertion order.
24 25 26 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 24 def layout_filter_mapping @layout_filter_mapping end |
#preprocessor ⇒ Proc
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The code block that will be executed after all data is loaded but before the site is compiled.
28 29 30 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 28 def preprocessor @preprocessor end |
Instance Method Details
#add_item_compilation_rule(rule, position = :after) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Add the given rule to the list of item compilation rules.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 47 def add_item_compilation_rule(rule, position=:after) case position when :before @item_compilation_rules.unshift(rule) when :after @item_compilation_rules << rule else raise "#add_item_routing_rule expected position to be :after or :before" end end |
#add_item_routing_rule(rule, position = :after) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Add the given rule to the list of item routing rules.
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 66 def add_item_routing_rule(rule, position=:after) case position when :before @item_routing_rules.unshift(rule) when :after @item_routing_rules << rule else raise "#add_item_routing_rule expected position to be :after or :before" end end |
#checksum ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The checksum for this object. If its contents change, the checksum will change as well.
183 184 185 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 183 def checksum @data.checksum end |
#compilation_rule_for(rep) ⇒ Nanoc3::Rule?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Finds the first matching compilation rule for the given item representation.
117 118 119 120 121 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 117 def compilation_rule_for(rep) @item_compilation_rules.find do |rule| rule.applicable_to?(rep.item) && rule.rep_name == rep.name end end |
#dsl ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the Nanoc3::CompilerDSL that should be used for this site.
169 170 171 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 169 def dsl Nanoc3::CompilerDSL.new(self, @compiler.site.config) end |
#filter_for_layout(layout) ⇒ Array?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Finds the filter name and arguments to use for the given layout.
161 162 163 164 165 166 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 161 def filter_for_layout(layout) @layout_filter_mapping.each_pair do |layout_identifier, filter_name_and_args| return filter_name_and_args if layout.identifier =~ layout_identifier end nil end |
#inspect ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
187 188 189 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 187 def inspect "<#{self.class}:0x#{self.object_id.to_s(16)}>" end |
#item_compilation_rules_for(item) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The list of item compilation rules for the given item.
81 82 83 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 81 def item_compilation_rules_for(item) @item_compilation_rules.select { |r| r.applicable_to?(item) } end |
#load ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Loads this site’s rules.
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 88 def load # Find rules file rules_filenames = [ 'Rules', 'rules', 'Rules.rb', 'rules.rb' ] rules_filename = rules_filenames.find { |f| File.file?(f) } raise Nanoc3::Errors::NoRulesFileFound.new if rules_filename.nil? # Get rule data @data = File.read(rules_filename) # Load DSL dsl.instance_eval(@data, "./#{rules_filename}") end |
#new_rule_memory_for_layout(layout) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The rule memory for the given layout.
205 206 207 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 205 def new_rule_memory_for_layout(layout) filter_for_layout(layout) end |
#new_rule_memory_for_rep(rep) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The rule memory for the given item representation.
195 196 197 198 199 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 195 def new_rule_memory_for_rep(rep) recording_proxy = rep.to_recording_proxy compilation_rule_for(rep).apply_to(recording_proxy, :compiler => @compiler) recording_proxy.rule_memory end |
#reference ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns an object that can be used for uniquely identifying objects.
177 178 179 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 177 def reference :rules end |
#routing_rule_for(rep) ⇒ Nanoc3::Rule?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Finds the first matching routing rule for the given item representation.
129 130 131 132 133 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 129 def routing_rule_for(rep) @item_routing_rules.find do |rule| rule.applicable_to?(rep.item) && rule.rep_name == rep.name end end |
#routing_rules_for(rep) ⇒ Hash<Symbol, Nanoc3::Rule>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the list of routing rules that can be applied to the given item representation. For each snapshot, the first matching rule will be returned. The result is a hash containing the corresponding rule for each snapshot.
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 143 def routing_rules_for(rep) rules = {} @item_routing_rules.each do |rule| next if !rule.applicable_to?(rep.item) next if rule.rep_name != rep.name next if rules.has_key?(rule.snapshot_name) rules[rule.snapshot_name] = rule end rules end |
#rule_memory_calculator ⇒ Nanoc3::RuleMemoryCalculator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The rule memory calculator.
225 226 227 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 225 def rule_memory_calculator @compiler.rule_memory_calculator end |
#rule_memory_differs_for(obj) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
changed since the last compilation, false otherwise
214 215 216 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 214 def rule_memory_differs_for(obj) !rule_memory_store[obj].eql?(rule_memory_calculator[obj]) end |
#rule_memory_store ⇒ Nanoc3::RuleMemoryStore
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The rule memory store.
220 221 222 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 220 def rule_memory_store @compiler.rule_memory_store end |
#unload ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Unloads this site’s rules.
104 105 106 107 108 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 104 def unload @item_compilation_rules = [] @item_routing_rules = [] @layout_filter_mapping = OrderedHash.new end |