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.
29 30 31 32 33 34 35 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 29 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.
7 8 9 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 7 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.
13 14 15 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 13 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.
27 28 29 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 27 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.
20 21 22 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 20 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.
42 43 44 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 42 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.
51 52 53 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 51 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.
70 71 72 73 74 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 70 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.
102 103 104 105 106 107 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 102 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.
116 117 118 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 116 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.
59 60 61 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 59 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.
112 113 114 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 112 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.
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 84 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 |