Skip to content

Commit

Permalink
Merge ddc9655 into 01e0f37
Browse files Browse the repository at this point in the history
  • Loading branch information
mpapis committed Nov 15, 2014
2 parents 01e0f37 + ddc9655 commit 00856b4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/nanoc/base/compilation/rule.rb
Expand Up @@ -67,7 +67,26 @@ def apply_to(rep, params = {})
raise ArgumentError, 'Required :compiler option is missing'
end
rep = Nanoc::ItemRepProxy.new(rep, compiler) unless rep.proxy?
Nanoc::RuleContext.new(:rep => rep, :compiler => compiler).instance_eval(&@block)
Nanoc::RuleContext.new(
:rep => rep,
:compiler => compiler
).instance_exec(
matches(rep.item.identifier),
&@block
)
end

protected

# Matches the rule regexp against items identifier and gives back group
# captures if any
#
# @param String items identifier to check
#
# @return [nil, Array] array of group captures if any
def matches(identifier)
matches = @identifier_regex.match(identifier)
matches && matches.captures
end

end
Expand Down
10 changes: 10 additions & 0 deletions test/base/test_rule.rb
Expand Up @@ -14,4 +14,14 @@ def test_apply_to
# TODO implement
end

def test_matches
regexp = %r</(.*)/(.*)/>
identifier = '/anything/else/'
expected = ['anything', 'else']

rule = Nanoc::Rule.new(regexp, :string, Proc.new {})

assert_equal expected, rule.send(:matches, identifier)
end

end

0 comments on commit 00856b4

Please sign in to comment.