Class: Nanoc::RuleDSL::RulesCollection Private

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeRulesCollection

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

#dataString

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.

Returns:

  • (String)

    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_mappingHash (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.

Returns:

  • (Hash)

    The layout-to-filter mapping rules



15
16
17
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 15

def layout_filter_mapping
  @layout_filter_mapping
end

#postprocessorsHash

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.

Returns:

  • (Hash)

    The hash containing the 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

#preprocessorsHash

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.

Returns:

  • (Hash)

    The hash containing the 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.

Parameters:

  • rule (Nanoc::Int::Rule)

    The item compilation rule to add



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.

Parameters:

  • rule (Nanoc::Int::Rule)

    The item routing rule to add



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.

Parameters:

  • rep (Nanoc::Core::ItemRep)

    The item rep for which to fetch the rule

Returns:

  • (Nanoc::Int::Rule, nil)

    The compilation rule for the given item rep, or nil if no rules have been found



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.

Parameters:

  • layout (Nanoc::Core::Layout)

    The layout for which to fetch the filter.

Returns:

  • (Array, nil)

    A tuple containing the filter name and the filter arguments 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

#inspectObject

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.

Parameters:

  • item (Nanoc::Core::Item)

    The item for which the compilation rules should be retrieved

Returns:

  • (Array)

    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

#referenceObject

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.

Returns:

  • (Object)

    An unique reference to this object



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.

Parameters:

  • rep (Nanoc::Core::ItemRep)

    The item rep for which to fetch the rules

Returns:

  • (Hash<Symbol, Nanoc::Int::Rule>)

    The routing rules for the given rep



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