Skip to content

Commit

Permalink
Merge branch 'feature/add_group_matches_in_route_gh_478' of https://g…
Browse files Browse the repository at this point in the history
…ithub.com/mpapis/nanoc into mpapis-feature/add_group_matches_in_route_gh_478

Conflicts:
	test/base/test_rule.rb
  • Loading branch information
denisdefreyne committed Dec 6, 2014
2 parents 10cb521 + ddc9655 commit bad204b
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 @@ -65,7 +65,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
end
10 changes: 10 additions & 0 deletions test/base/test_rule.rb
Expand Up @@ -12,4 +12,14 @@ def test_applicable_to
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 bad204b

Please sign in to comment.