Sha256: 6fd6f7e3a58a39a987ed4f55ae80d743610e3b4b919c212fd1e0db1faa18a308

Contents?: true

Size: 1.03 KB

Versions: 10

Compression:

Stored size: 1.03 KB

Contents

# encoding: utf-8

module Nanoc3

  # Nanoc3::Rule contains the processing information for a item.
  class Rule

    # The regex that determines which items this rule can be applied to. This
    # rule can be applied to items with a identifier matching this regex.
    attr_reader :identifier_regex

    # The name of the representation that will be compiled using this rule.
    attr_reader :rep_name

    # 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.
    def initialize(identifier_regex, rep_name, block)
      @identifier_regex = identifier_regex
      @rep_name         = rep_name.to_sym

      @block = block
    end

    # Returns true if this rule can be applied to the given item rep.
    def applicable_to?(item)
      item.identifier =~ @identifier_regex
    end

    # Applies this rule to the given item rep.
    def apply_to(rep)
      Nanoc3::RuleContext.new(rep).instance_eval &@block
    end

  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
nanoc3-3.0.9 lib/nanoc3/base/rule.rb
nanoc3-3.0.8 lib/nanoc3/base/rule.rb
nanoc3-3.0.7 lib/nanoc3/base/rule.rb
nanoc3-3.0.6 lib/nanoc3/base/rule.rb
nanoc3-3.0.5 lib/nanoc3/base/rule.rb
nanoc3-3.0.4 lib/nanoc3/base/rule.rb
nanoc3-3.0.3 lib/nanoc3/base/rule.rb
nanoc3-3.0.2 lib/nanoc3/base/rule.rb
nanoc3-3.0.1 lib/nanoc3/base/rule.rb
nanoc3-3.0.0 lib/nanoc3/base/rule.rb