Class: Nanoc::RuleDSL::RulesCollection Private
- Inherits:
-
Object
- Object
- Nanoc::RuleDSL::RulesCollection
- Defined in:
- lib/nanoc/rule_dsl/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
-
#data ⇒ String
private
The contents of the Rules file.
-
#layout_filter_mapping ⇒ Hash
readonly
private
The hash containing layout-to-filter mapping rules.
-
#postprocessors ⇒ Hash
private
The hash containing postprocessor code blocks that will be executed after all data is loaded and the site is compiled.
-
#preprocessors ⇒ Hash
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
-
#add_item_compilation_rule(rule) ⇒ void
private
Add the given rule to the list of item compilation rules.
-
#add_item_routing_rule(rule) ⇒ void
private
Add the given rule to the list of item routing rules.
-
#compilation_rule_for(rep) ⇒ Nanoc::Int::Rule?
private
Finds the first matching compilation rule for the given item representation.
-
#filter_for_layout(layout) ⇒ Array?
private
Finds the filter name and arguments to use for the given layout.
-
#initialize ⇒ 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.
-
#reference ⇒ Object
private
Returns an object that can be used for uniquely identifying objects.
-
#routing_rules_for(rep) ⇒ Hash<Symbol, Nanoc::Int::Rule>
private
Returns the list of routing rules that can be applied to the given item representation.
Constructor Details
#initialize ⇒ 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/nanoc/rule_dsl/rules_collection.rb', line 31 def initialize @item_compilation_rules = [] @item_routing_rules = [] @layout_filter_mapping = {} @preprocessors = {} @postprocessors = {} end |
Instance Attribute Details
#data ⇒ 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 contents of the Rules file.
9 10 11 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 9 def data @data 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.
15 16 17 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 15 def layout_filter_mapping @layout_filter_mapping end |
#postprocessors ⇒ Hash
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 postprocessor code blocks that will be executed after
all data is loaded and the site is compiled.
29 30 31 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 29 def postprocessors @postprocessors end |
#preprocessors ⇒ Hash
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.
22 23 24 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 22 def preprocessors @preprocessors end |
Instance Method Details
#add_item_compilation_rule(rule) ⇒ 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.
44 45 46 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 44 def add_item_compilation_rule(rule) @item_compilation_rules << rule end |
#add_item_routing_rule(rule) ⇒ 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.
53 54 55 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 53 def add_item_routing_rule(rule) @item_routing_rules << rule end |
#compilation_rule_for(rep) ⇒ Nanoc::Int::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.
72 73 74 75 76 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 72 def compilation_rule_for(rep) @item_compilation_rules.find do |rule| rule.applicable_to?(rep.item) && rule.rep_name == rep.name end 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.
104 105 106 107 108 109 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 104 def filter_for_layout(layout) @layout_filter_mapping.each_pair do |pattern, filter_name_and_args| return filter_name_and_args if pattern.match?(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.
118 119 120 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 118 def inspect "<#{self.class}>" 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.
61 62 63 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 61 def item_compilation_rules_for(item) @item_compilation_rules.select { |r| r.applicable_to?(item) } 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.
114 115 116 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 114 def reference 'rules' end |
#routing_rules_for(rep) ⇒ Hash<Symbol, Nanoc::Int::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.
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 86 def routing_rules_for(rep) rules = {} @item_routing_rules.each do |rule| next unless 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 |