diff --git a/features/current_page_request_path_backwards.feature b/features/current_page_request_path_backwards.feature new file mode 100644 index 00000000..05040c2a --- /dev/null +++ b/features/current_page_request_path_backwards.feature @@ -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" \ No newline at end of file diff --git a/fixtures/test-app/config.rb b/fixtures/test-app/config.rb index f421d8db..ac793ef7 100644 --- a/fixtures/test-app/config.rb +++ b/fixtures/test-app/config.rb @@ -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" diff --git a/fixtures/test-app/source/request-path.html.erb b/fixtures/test-app/source/request-path.html.erb new file mode 100644 index 00000000..cb134235 --- /dev/null +++ b/fixtures/test-app/source/request-path.html.erb @@ -0,0 +1 @@ +<%= current_path == request.path %> \ No newline at end of file diff --git a/lib/middleman/base.rb b/lib/middleman/base.rb index 630d0f4e..8393c8db 100644 --- a/lib/middleman/base.rb +++ b/lib/middleman/base.rb @@ -11,7 +11,7 @@ require "middleman/vendor/hooks-0.2.0/lib/hooks" require "active_support" require "active_support/json" require "active_support/core_ext/string/inflections" - + # Core Middleman Class class Middleman::Base # Uses callbacks @@ -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