support old request.path api

This commit is contained in:
Thomas Reynolds 2011-12-09 10:25:51 -08:00
parent aa0832f549
commit 7da1edeb6e
4 changed files with 23 additions and 5 deletions

View 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"

View file

@ -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"

View file

@ -0,0 +1 @@
<%= current_path == request.path %>

View file

@ -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