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

Projects
None yet
3 participants
@mpapis
Copy link
Member

commented Sep 9, 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

This comment has been minimized.

Copy link
Member

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!

@ddfreyne ddfreyne added the feature label Sep 9, 2014

@mpapis mpapis force-pushed the mpapis:feature/add_group_matches_in_route_gh_478 branch from a472289 to df33cbb Sep 9, 2014

@ddfreyne ddfreyne added the to review label Sep 11, 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)

This comment has been minimized.

Copy link
@ddfreyne

ddfreyne Sep 11, 2014

Member

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.

@mpapis mpapis force-pushed the mpapis:feature/add_group_matches_in_route_gh_478 branch from f40f36b to 4311f0f Sep 11, 2014

@mpapis

This comment has been minimized.

Copy link
Member Author

commented Sep 11, 2014

updated

@mpapis

This comment has been minimized.

Copy link
Member Author

commented Sep 11, 2014

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

@ddfreyne

This comment has been minimized.

Copy link
Member

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.

@mpapis mpapis force-pushed the mpapis:feature/add_group_matches_in_route_gh_478 branch from 4311f0f to ddc9655 Nov 15, 2014

@mpapis

This comment has been minimized.

Copy link
Member Author

commented Nov 15, 2014

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

@coveralls

This comment has been minimized.

Copy link

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.

@ddfreyne

This comment has been minimized.

Copy link
Member

commented Nov 16, 2014

Yeah, will merge this tomorrow!

@ddfreyne ddfreyne modified the milestone: 3.8 Nov 29, 2014

@ddfreyne

This comment has been minimized.

Copy link
Member

commented Dec 6, 2014

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

@ddfreyne ddfreyne removed the to review label Dec 6, 2014

@ddfreyne ddfreyne merged commit ddc9655 into nanoc:master Dec 6, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.