support old request.path api
This commit is contained in:
parent
aa0832f549
commit
7da1edeb6e
6
features/current_page_request_path_backwards.feature
Normal file
6
features/current_page_request_path_backwards.feature
Normal file
|
@ -0,0 +1,6 @@
|
|||
Feature: Support old request.path object used by many extensions
|
||||
|
||||
Scenario: Viewing the root path
|
||||
Given the Server is running at "test-app"
|
||||
When I go to "/request-path.html"
|
||||
Then I should see "true"
|
|
@ -21,6 +21,7 @@ with_layout :content_for do
|
|||
end
|
||||
|
||||
with_layout false do
|
||||
page "/request-path.html"
|
||||
page "/lorem.html"
|
||||
page "/markdown.html"
|
||||
page "/relative_image.html"
|
||||
|
|
1
fixtures/test-app/source/request-path.html.erb
Normal file
1
fixtures/test-app/source/request-path.html.erb
Normal file
|
@ -0,0 +1 @@
|
|||
<%= current_path == request.path %>
|
|
@ -235,14 +235,24 @@ class Middleman::Base
|
|||
Middleman::Extensions.register(:sitemap_tree) {
|
||||
Middleman::Extensions::SitemapTree }
|
||||
|
||||
# Backwards-compatibility with old request.path signature
|
||||
attr :request
|
||||
|
||||
# Accessor for current path
|
||||
# @return [String]
|
||||
attr :current_path
|
||||
def current_path
|
||||
@_current_path
|
||||
end
|
||||
|
||||
def current_path=(path)
|
||||
@_current_path = path
|
||||
@request = Thor::CoreExt::HashWithIndifferentAccess.new({ :path => path })
|
||||
end
|
||||
|
||||
# Initialize the Middleman project
|
||||
def initialize(&block)
|
||||
# Current path defaults to nil, used in views.
|
||||
@current_path = nil
|
||||
self.current_path = nil
|
||||
|
||||
# Clear the static class cache
|
||||
cache.clear
|
||||
|
@ -357,7 +367,7 @@ class Middleman::Base
|
|||
return send_file(sitemap_page.source_file) unless sitemap_page.template?
|
||||
|
||||
# Set the current path for use in helpers
|
||||
@current_path = @request_path.dup
|
||||
self.current_path = @request_path.dup
|
||||
|
||||
# Set a HTTP content type based on the request's extensions
|
||||
content_type sitemap_page.mime_type
|
||||
|
|
Loading…
Reference in a new issue