Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add access to regular expressions group matches used in route #478

Merged

Conversation

@mpapis
Copy link
Member

@mpapis mpapis commented Sep 8, 2014

$ nanoc --version
nanoc 3.7.3 © 2007-2014 Denis Defreyne.
Running ruby 2.0.0 (2014-05-08) on x86_64-linux with RubyGems 2.2.2.

my current example:

blog_regexp = %r</blog/([0-9]+)\-([0-9]+)\-([0-9]+)\-([^\/]+)>
route blog_regexp do
  y,m,d,slug = blog_regexp.match(item.identifier)[1..-1]
  "/blog/#{y}/#{m}/#{slug}/index.html"
end

would be nice if t could be reduced to:

route %r</blog/([0-9]+)\-([0-9]+)\-([0-9]+)\-([^\/]+)> do |y, m, d, slug|
  "/blog/#{y}/#{m}/#{slug}/index.html"
end

although adding matches for simplicity would be fine with me too:

route %r</blog/([0-9]+)\-([0-9]+)\-([0-9]+)\-([^\/]+)> do
  y, m, d, slug = matches
  "/blog/#{y}/#{m}/#{slug}/index.html"
end

I did not looked in to the code yet, wanted to make sure such change would be welcome

@ddfreyne
Copy link
Member

@ddfreyne ddfreyne commented Sep 9, 2014

Good suggestion! This is something that could be tackled for 3.8, I suppose.

If you want to implement this, be my guest!

Loading

@mpapis mpapis force-pushed the feature/add_group_matches_in_route_gh_478 branch from a472289 to df33cbb Sep 9, 2014
@@ -49,7 +50,9 @@ def initialize(identifier_regex, rep_name, block, params = {})
# @return [Boolean] true if this rule can be applied to the given item
# rep, false otherwise
def applicable_to?(item)
item.identifier =~ @identifier_regex
matches = @identifier_regex.match(item.identifier)
Copy link
Member

@ddfreyne ddfreyne Sep 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating state here is troublesome, because this method should only return a boolean, and because the stored state depends on the item param.

I’d prefer the matches to be not stored at all. They will have to be recomputed, but I do not believe this is a big issue.

Loading

@mpapis mpapis force-pushed the feature/add_group_matches_in_route_gh_478 branch from f40f36b to 4311f0f Sep 11, 2014
@mpapis
Copy link
Member Author

@mpapis mpapis commented Sep 11, 2014

updated

Loading

@mpapis
Copy link
Member Author

@mpapis mpapis commented Sep 11, 2014

not sure about documentation, is there anything else I should update?

Loading

@ddfreyne
Copy link
Member

@ddfreyne ddfreyne commented Sep 12, 2014

This PR looks quite nice now. I can handle documentation!

I’m not around in the next few days so I’ll likely only have the time to properly handle this PR some time next week.

Loading

@mpapis mpapis force-pushed the feature/add_group_matches_in_route_gh_478 branch from 4311f0f to ddc9655 Nov 15, 2014
@mpapis
Copy link
Member Author

@mpapis mpapis commented Nov 15, 2014

rebased on top of master in case you are ready to merge it ;)

Loading

@coveralls
Copy link

@coveralls coveralls commented Nov 15, 2014

Coverage Status

Coverage remained the same when pulling ddc9655 on mpapis:feature/add_group_matches_in_route_gh_478 into 01e0f37 on nanoc:master.

Loading

@ddfreyne
Copy link
Member

@ddfreyne ddfreyne commented Nov 16, 2014

Yeah, will merge this tomorrow!

Loading

@ddfreyne ddfreyne added this to the 3.8 milestone Nov 29, 2014
@ddfreyne ddfreyne added this to the 3.8 milestone Nov 29, 2014
@ddfreyne
Copy link
Member

@ddfreyne ddfreyne commented Dec 6, 2014

… for a very loose definition of “tomorrow”—apologies!

Loading

@ddfreyne ddfreyne removed the to review label Dec 6, 2014
@ddfreyne ddfreyne merged commit ddc9655 into nanoc:master Dec 6, 2014
1 check passed
Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants