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