Class: Nanoc::RuleDSL::Rule Private

Inherits:
Object
  • Object
show all
Defined in:
lib/nanoc/rule_dsl/rule.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.

Contains the processing information for a item.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, rep_name, block, snapshot_name: nil) ⇒ 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.

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.

Parameters:

  • pattern (Nanoc::Int::Pattern)
  • rep_name (String, Symbol)

    The name of the item representation where this rule can be applied to

  • block (Proc)

    A block that will be called when matching items are compiled

  • snapshot_name (Symbol, nil) (defaults to: nil)

    The name of the snapshot this rule will apply to. Ignored for compilation rules, but used for routing rules.



32
33
34
35
36
37
# File 'lib/nanoc/rule_dsl/rule.rb', line 32

def initialize(pattern, rep_name, block, snapshot_name: nil)
  @pattern = pattern
  @rep_name = rep_name.to_sym
  @snapshot_name = snapshot_name
  @block = block
end

Instance Attribute Details

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



16
17
18
# File 'lib/nanoc/rule_dsl/rule.rb', line 16

def pattern
  @pattern
end

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

Returns The name of the representation that will be compiled using this rule.

Returns:

  • (Symbol)

    The name of the representation that will be compiled using this rule



8
9
10
# File 'lib/nanoc/rule_dsl/rule.rb', line 8

def rep_name
  @rep_name
end

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

Returns The name of the snapshot this rule will apply to. Ignored for compilation rules, but used for routing rules.

Returns:

  • (Symbol)

    The name of the snapshot this rule will apply to. Ignored for compilation rules, but used for routing rules.

Since:

  • 3.2.0



14
15
16
# File 'lib/nanoc/rule_dsl/rule.rb', line 14

def snapshot_name
  @snapshot_name
end

Instance Method Details

#applicable_to?(item) ⇒ Boolean

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 true if this rule can be applied to the given item rep, false otherwise.

Parameters:

Returns:

  • (Boolean)

    true if this rule can be applied to the given item rep, false otherwise



43
44
45
# File 'lib/nanoc/rule_dsl/rule.rb', line 43

def applicable_to?(item)
  @pattern.match?(item.identifier)
end

#apply_to(rep, site:, executor:, view_context:) ⇒ 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.

Applies this rule to the given item rep.



55
56
57
58
59
60
# File 'lib/nanoc/rule_dsl/rule.rb', line 55

def apply_to(rep, site:, executor:, view_context:)
  context = Nanoc::RuleDSL::RuleContext.new(
    rep: rep, executor: executor, site: site, view_context: view_context,
  )
  context.instance_exec(matches(rep.item.identifier), &@block)
end