class Nanoc::RuleDSL::RulesCollection
Keeps track of the rules in a site.
@api private
Attributes
@return [String] the contents of the Rules file
The hash containing layout-to-filter mapping rules. This hash is ordered: iterating over the hash will happen in insertion order.
@return [Hash] The layout-to-filter mapping rules
The hash containing postprocessor code blocks that will be executed after
all data is loaded and the site is compiled.
@return [Hash] The hash containing the postprocessor code blocks that will
be executed after all data is loaded and the site is compiled
The hash containing preprocessor code blocks that will be executed after
all data is loaded but before the site is compiled.
@return [Hash] The hash containing the preprocessor code blocks that will
be executed after all data is loaded but before the site is compiled
Public Class Methods
# File lib/nanoc/rule_dsl/rules_collection.rb, line 29 def initialize @item_compilation_rules = [] @item_routing_rules = [] @layout_filter_mapping = {} @preprocessors = {} @postprocessors = {} end
Public Instance Methods
Add the given rule to the list of item compilation rules.
@param [Nanoc::Int::Rule] rule The item compilation rule to add
@return [void]
# File lib/nanoc/rule_dsl/rules_collection.rb, line 42 def add_item_compilation_rule(rule) @item_compilation_rules << rule end
Add the given rule to the list of item routing rules.
@param [Nanoc::Int::Rule] rule The item routing rule to add
@return [void]
# File lib/nanoc/rule_dsl/rules_collection.rb, line 51 def add_item_routing_rule(rule) @item_routing_rules << rule end
Finds the first matching compilation rule for the given item representation.
@param [Nanoc::Int::ItemRep] rep The item rep for which to fetch the rule
@return [Nanoc::Int::Rule, nil] The compilation rule for the given item rep,
or nil if no rules have been found
# 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
Finds the filter name and arguments to use for the given layout.
@param [Nanoc::Int::Layout] layout The layout for which to fetch the filter.
@return [Array, nil] A tuple containing the filter name and the filter
arguments for the given layout.
# 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
# File lib/nanoc/rule_dsl/rules_collection.rb, line 116 def inspect "<#{self.class}>" end
@param [Nanoc::Int::Item] item The item for which the compilation rules
should be retrieved
@return [Array] The list of item compilation rules for the given item
# 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
Returns an object that can be used for uniquely identifying objects.
@return [Object] An unique reference to this object
# File lib/nanoc/rule_dsl/rules_collection.rb, line 112 def reference :rules end
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.
@param [Nanoc::Int::ItemRep] rep The item rep for which to fetch the rules
@return [Hash<Symbol, Nanoc::Int::Rule>] The routing rules for the given rep
# 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