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.
29 30 31 32 33 34 35 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 29 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.
12 13 14 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 12 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.
16 17 18 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 16 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.
22 23 24 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 22 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.
26 27 28 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 26 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.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 45 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.
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 64 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.
181 182 183 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 181 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.
115 116 117 118 119 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 115 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.
167 168 169 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 167 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.
159 160 161 162 163 164 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 159 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.
185 186 187 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 185 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.
79 80 81 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 79 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.
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 86 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.
203 204 205 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 203 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.
193 194 195 196 197 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 193 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.
175 176 177 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 175 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.
127 128 129 130 131 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 127 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.
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 141 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.
223 224 225 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 223 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
212 213 214 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 212 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.
218 219 220 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 218 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.
102 103 104 105 106 |
# File 'lib/nanoc3/base/compilation/rules_collection.rb', line 102 def unload @item_compilation_rules = [] @item_routing_rules = [] @layout_filter_mapping = OrderedHash.new end |