Class: Nanoc::RulesCollection Private
- Inherits:
-
Object
- Object
- Nanoc::RulesCollection
- Extended by:
- Memoization
- Defined in:
- lib/nanoc/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)
-
- (String) data
private
The contents of the Rules file.
-
- (Array<Nanoc::Rule>) item_compilation_rules
readonly
private
The list of item compilation rules that will be used to compile items.
-
- (Array<Nanoc::Rule>) item_routing_rules
readonly
private
The list of routing rules that will be used to give all items a path.
-
- (Hash) layout_filter_mapping
readonly
private
The hash containing layout-to-filter mapping rules.
-
- (Hash) preprocessors
private
The hash containing preprocessor code blocks that will be executed after all data is loaded but before the site is compiled.
Instance Method Summary (collapse)
-
- (void) add_item_compilation_rule(rule)
private
Add the given rule to the list of item compilation rules.
-
- (void) add_item_routing_rule(rule)
private
Add the given rule to the list of item routing rules.
-
- (String) checksum
private
The checksum for this object.
-
- (Nanoc::Rule?) compilation_rule_for(rep)
private
Finds the first matching compilation rule for the given item representation.
-
- (Object) dsl
private
Returns the Nanoc::CompilerDSL that should be used for this site.
-
- (Array?) filter_for_layout(layout)
private
Finds the filter name and arguments to use for the given layout.
-
- (RulesCollection) initialize(compiler)
constructor
private
A new instance of RulesCollection.
-
- (Object) inspect
private
-
- (Array) item_compilation_rules_for(item)
private
The list of item compilation rules for the given item.
-
- (void) load
private
Loads this site’s rules.
-
- (Array) make_rule_memory_serializable(rs)
private
Makes the given rule memory serializable by calling
Nanoc::Checksummer#calc
on the filter arguments, so that objects such as classes and filenames can be serialized. -
- (Array) new_rule_memory_for_layout(layout)
private
The rule memory for the given layout.
-
- (Array) new_rule_memory_for_rep(rep)
private
The rule memory for the given item representation.
-
- (Object) parse(rules_filename)
private
-
- (Object) reference
private
Returns an object that can be used for uniquely identifying objects.
-
- (Nanoc::Rule?) routing_rule_for(rep)
private
Finds the first matching routing rule for the given item representation.
-
- (Hash<Symbol, Nanoc::Rule>) routing_rules_for(rep)
private
Returns the list of routing rules that can be applied to the given item representation.
-
- (Nanoc::RuleMemoryCalculator) rule_memory_calculator
private
The rule memory calculator.
-
- (Boolean) rule_memory_differs_for(obj)
private
changed since the last compilation, false otherwise.
-
- (Nanoc::RuleMemoryStore) rule_memory_store
private
The rule memory store.
-
- (Array) snapshots_for(rep)
private
A list of snapshots, represented as arrays where the first element is the snapshot name (a Symbol) and the last element is a Boolean indicating whether the snapshot is final or not.
-
- (void) unload
private
Unloads this site’s rules.
Methods included from Memoization
Constructor Details
- (RulesCollection) initialize(compiler)
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
39 40 41 42 43 44 45 46 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 39 def initialize(compiler) @compiler = compiler @item_compilation_rules = [] @item_routing_rules = [] @layout_filter_mapping = OrderedHash.new @preprocessors = OrderedHash.new end |
Instance Attribute Details
- (String) data
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 contents of the Rules file
13 14 15 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 13 def data @data end |
- (Array<Nanoc::Rule>) item_compilation_rules (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.
19 20 21 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 19 def item_compilation_rules @item_compilation_rules end |
- (Array<Nanoc::Rule>) item_routing_rules (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.
23 24 25 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 23 def item_routing_rules @item_routing_rules end |
- (Hash) layout_filter_mapping (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.
29 30 31 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 29 def layout_filter_mapping @layout_filter_mapping end |
- (Hash) preprocessors
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 preprocessor code blocks that will be executed after all data is loaded but before the site is compiled.
36 37 38 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 36 def preprocessors @preprocessors end |
Instance Method Details
- (void) add_item_compilation_rule(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.
This method returns an undefined value.
Add the given rule to the list of item compilation rules.
53 54 55 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 53 def add_item_compilation_rule(rule) @item_compilation_rules << rule end |
- (void) add_item_routing_rule(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.
This method returns an undefined value.
Add the given rule to the list of item routing rules.
62 63 64 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 62 def add_item_routing_rule(rule) @item_routing_rules << rule end |
- (String) checksum
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/nanoc/base/compilation/rules_collection.rb', line 181 def checksum Nanoc::Checksummer.calc(self) end |
- (Nanoc::Rule?) compilation_rule_for(rep)
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/nanoc/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 |
- (Object) dsl
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 Nanoc::CompilerDSL that should be used for this site.
167 168 169 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 167 def dsl Nanoc::CompilerDSL.new(self, @compiler.site.config) end |
- (Array?) filter_for_layout(layout)
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/nanoc/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 |
- (Object) inspect
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/nanoc/base/compilation/rules_collection.rb', line 185 def inspect "<#{self.class}>" end |
- (Array) item_compilation_rules_for(item)
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
70 71 72 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 70 def item_compilation_rules_for(item) @item_compilation_rules.select { |r| r.applicable_to?(item) } end |
- (void) load
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.
77 78 79 80 81 82 83 84 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 77 def load # Find rules file rules_filenames = [ 'Rules', 'rules', 'Rules.rb', 'rules.rb' ] rules_filename = rules_filenames.find { |f| File.file?(f) } raise Nanoc::Errors::NoRulesFileFound.new if rules_filename.nil? parse(rules_filename) end |
- (Array) make_rule_memory_serializable(rs)
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.
Makes the given rule memory serializable by calling
Nanoc::Checksummer#calc
on the filter arguments, so that objects such as
classes and filenames can be serialized.
208 209 210 211 212 213 214 215 216 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 208 def make_rule_memory_serializable(rs) rs.map do |r| if r[0] == :filter [ r[0], r[1], r[2].to_a.map { |a| Nanoc::Checksummer.calc(a) } ] else r end end end |
- (Array) new_rule_memory_for_layout(layout)
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
221 222 223 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 221 def new_rule_memory_for_layout(layout) filter_for_layout(layout) end |
- (Array) new_rule_memory_for_rep(rep)
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 198 |
# File 'lib/nanoc/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 << [ :write, rep.path ] make_rule_memory_serializable(recording_proxy.rule_memory) end |
- (Object) parse(rules_filename)
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.
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 86 def parse(rules_filename) rules_filename = File.absolute_path(rules_filename) # Get rule data @data = File.read(rules_filename) old_rules_filename = dsl.rules_filename dsl.rules_filename = rules_filename dsl.instance_eval(@data, rules_filename) dsl.rules_filename = old_rules_filename end |
- (Object) reference
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/nanoc/base/compilation/rules_collection.rb', line 175 def reference :rules end |
- (Nanoc::Rule?) routing_rule_for(rep)
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/nanoc/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 |
- (Hash<Symbol, Nanoc::Rule>) routing_rules_for(rep)
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/nanoc/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.key?(rule.snapshot_name) rules[rule.snapshot_name] = rule end rules end |
- (Nanoc::RuleMemoryCalculator) rule_memory_calculator
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
253 254 255 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 253 def rule_memory_calculator @compiler.rule_memory_calculator end |
- (Boolean) rule_memory_differs_for(obj)
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
242 243 244 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 242 def rule_memory_differs_for(obj) !rule_memory_store[obj].eql?(rule_memory_calculator[obj]) end |
- (Nanoc::RuleMemoryStore) rule_memory_store
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
248 249 250 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 248 def rule_memory_store @compiler.rule_memory_store end |
- (Array) snapshots_for(rep)
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 list of snapshots, represented as arrays where the first element is the snapshot name (a Symbol) and the last element is a Boolean indicating whether the snapshot is final or not
232 233 234 235 236 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 232 def snapshots_for(rep) new_rule_memory_for_rep(rep).select { |e| e[0] == :snapshot }.map do |e| [ e[1], e[2].fetch(:final) { true } ] end end |
- (void) unload
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.
101 102 103 104 105 106 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 101 def unload @item_compilation_rules = [] @item_routing_rules = [] @layout_filter_mapping = OrderedHash.new @preprocessors = OrderedHash.new end |