Class: Nanoc3::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/nanoc3/base/rule.rb

Overview

Contains the processing information for a item.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Rule) initialize(identifier_regex, rep_name, block)

Creates a new item compilation rule with the given identifier regex, compiler and block. The block will be called during compilation with the item rep as its argument.

to determine whether this rule is applicable to certain items.

where this rule can be applied to

compiled

Parameters:

  • identifier_regex (Regexp)

    A regular expression that will be used

  • rep_name (String, Symbol)

    The name of the item representation

  • block (Proc)

    A block that will be called when matching items are



29
30
31
32
33
34
# File 'lib/nanoc3/base/rule.rb', line 29

def initialize(identifier_regex, rep_name, block)
  @identifier_regex = identifier_regex
  @rep_name         = rep_name.to_sym

  @block = block
end

Instance Attribute Details

- (Regexp) identifier_regex (readonly)

applied to. This rule can be applied to items with a identifier matching this regex.

Returns:

  • (Regexp)

    The regex that determines which items this rule can be



11
12
13
# File 'lib/nanoc3/base/rule.rb', line 11

def identifier_regex
  @identifier_regex
end

- (Symbol) rep_name (readonly)

using this rule

Returns:

  • (Symbol)

    The name of the representation that will be compiled



15
16
17
# File 'lib/nanoc3/base/rule.rb', line 15

def rep_name
  @rep_name
end

Instance Method Details

- (Boolean) applicable_to?(item)

rep, false otherwise

Parameters:

Returns:

  • (Boolean)

    true if this rule can be applied to the given item



40
41
42
# File 'lib/nanoc3/base/rule.rb', line 40

def applicable_to?(item)
  item.identifier =~ @identifier_regex
end

- (void) apply_to(rep)

This method returns an undefined value.

Applies this rule to the given item rep.

should be applied to

Parameters:



50
51
52
# File 'lib/nanoc3/base/rule.rb', line 50

def apply_to(rep)
  Nanoc3::RuleContext.new(rep).instance_eval &@block
end