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.



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

#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



7
8
9
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 7

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



13
14
15
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 13

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



27
28
29
# File 'lib/nanoc/rule_dsl/rules_collection.rb', line 27

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



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.

Parameters:

  • rule (Nanoc::Int::Rule)

    The item compilation rule to add



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.

Parameters:

  • rule (Nanoc::Int::Rule)

    The item routing rule to add



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.

Parameters:

Returns:

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

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



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.

Parameters:

Returns:

  • (Array, nil)

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

#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.



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.

Parameters:

  • item (Nanoc::Int::Item)

    The item for which the compilation rules should be retrieved

Returns:

  • (Array)

    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

#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



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.

Parameters:

Returns:

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

    The routing rules for the given rep



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