Skip to content

Commit

Permalink
[padrino-core] current_path impl
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Hull committed May 5, 2011
1 parent c0b2362 commit 221ae9f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions padrino-core/lib/padrino-core/application/routing.rb
Expand Up @@ -440,6 +440,7 @@ def route(verb, path, *args, &block)
# Now we can eval route, but because we have "throw halt" we need to be
# (en)sure to reset old layout and run controller after filters.
begin
@route = route
@_response_buffer = catch(:halt) { route_eval(&block) }
processed = true
ensure
Expand Down Expand Up @@ -662,6 +663,15 @@ def recognize_path(path)
self.class.recognize_path(path)
end

def current_path(*path_params)
if path_params.last.is_a?(Hash)
path_params[-1] = params.merge(path_params[-1])
else
path_params << params
end
@route.url(*path_params)
end

##
# This is mostly just a helper so request.path_info isn't changed when
# serving files from the public directory
Expand Down
4 changes: 2 additions & 2 deletions padrino-core/test/test_routing.rb
Expand Up @@ -1408,7 +1408,7 @@ def authorize(username, password)
assert_equal [:with_format, { :id => "9", :format => "js" }], @app.recognize_path(@app.url(:with_format, :id => 9, :format => :js))
end

should_eventually 'have current_path' do
should 'have current_path' do
mock_app do
controller :foo do
get :bar, :map => "/paginate/:page" do
Expand All @@ -1420,7 +1420,7 @@ def authorize(username, password)
assert_equal "/paginate/10", body
end

should_eventually 'change params in current_path' do
should 'change params in current_path' do
mock_app do
get :index, :map => "/paginate/:page" do
current_path(:page => 66)
Expand Down

0 comments on commit 221ae9f

Please sign in to comment.