Unify routes naming by renaming router to routes

Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
Piotr Sarnacki 2010-07-02 00:29:20 +02:00 committed by José Valim
parent f8720a04d1
commit f7ba614c2d
15 changed files with 37 additions and 37 deletions

View File

@ -737,13 +737,13 @@ module ActionMailer #:nodoc:
raise "You can no longer call ActionMailer::Base.default_url_options " \ raise "You can no longer call ActionMailer::Base.default_url_options " \
"directly. You need to set config.action_mailer.default_url_options. " \ "directly. You need to set config.action_mailer.default_url_options. " \
"If you are using ActionMailer standalone, you need to include the " \ "If you are using ActionMailer standalone, you need to include the " \
"url_helpers of a router directly." "url_helpers of a routes directly."
end end
end end
# This module will complain if the user tries to set default_url_options # This module will complain if the user tries to set default_url_options
# directly instead of through the config object. In Action Mailer's Railtie, # directly instead of through the config object. In Action Mailer's Railtie,
# we include the url_helpers of the router, which will override this module # we include the url_helpers of the routes, which will override this module
extend DeprecatedUrlOptions extend DeprecatedUrlOptions
ActiveSupport.run_load_hooks(:action_mailer, self) ActiveSupport.run_load_hooks(:action_mailer, self)

View File

@ -50,8 +50,8 @@ module AbstractController
if controller.respond_to?(:_helpers) if controller.respond_to?(:_helpers)
include controller._helpers include controller._helpers
if controller.respond_to?(:_router) if controller.respond_to?(:_routes)
include controller._router.url_helpers include controller._routes.url_helpers
end end
# TODO: Fix RJS to not require this # TODO: Fix RJS to not require this

View File

@ -96,7 +96,7 @@ module ActionController
def resource_action_separator=(val) def resource_action_separator=(val)
ActiveSupport::Deprecation.warn "ActionController::Base.resource_action_separator is deprecated and only " \ ActiveSupport::Deprecation.warn "ActionController::Base.resource_action_separator is deprecated and only " \
"works with the deprecated router DSL." "works with the deprecated routes DSL."
@resource_action_separator = val @resource_action_separator = val
end end

View File

@ -47,7 +47,7 @@ module ActionController
# #
# In AbstractController, dispatching is triggered directly by calling #process on a new controller. # In AbstractController, dispatching is triggered directly by calling #process on a new controller.
# ActionController::Metal provides an #action method that returns a valid Rack application for a # ActionController::Metal provides an #action method that returns a valid Rack application for a
# given action. Other rack builders, such as Rack::Builder, Rack::URLMap, and the Rails router, # given action. Other rack builders, such as Rack::Builder, Rack::URLMap, and the Rails routes,
# can dispatch directly to the action returned by FooController.action(:index). # can dispatch directly to the action returned by FooController.action(:index).
class Metal < AbstractController::Base class Metal < AbstractController::Base
abstract! abstract!

View File

@ -12,15 +12,15 @@ module ActionController
).merge(:script_name => request.script_name) ).merge(:script_name => request.script_name)
end end
def _router def _routes
raise "In order to use #url_for, you must include the helpers of a particular " \ raise "In order to use #url_for, you must include the helpers of a particular " \
"router. For instance, `include Rails.application.routes.url_helpers" "routes. For instance, `include Rails.application.routes.url_helpers"
end end
module ClassMethods module ClassMethods
def action_methods def action_methods
@action_methods ||= begin @action_methods ||= begin
super - _router.named_routes.helper_names super - _routes.named_routes.helper_names
end end
end end
end end

View File

@ -30,8 +30,8 @@ module ActionDispatch
class DeprecatedMapper #:nodoc: class DeprecatedMapper #:nodoc:
def initialize(set) #:nodoc: def initialize(set) #:nodoc:
ActiveSupport::Deprecation.warn "You are using the old router DSL which will be removed in Rails 3.1. " << ActiveSupport::Deprecation.warn "You are using the old routes DSL which will be removed in Rails 3.1. " <<
"Please check how to update your router file at: http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/" "Please check how to update your routes file at: http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/"
@set = set @set = set
end end

View File

@ -308,7 +308,7 @@ module ActionDispatch
if name_prefix = options.delete(:name_prefix) if name_prefix = options.delete(:name_prefix)
options[:as] ||= name_prefix options[:as] ||= name_prefix
ActiveSupport::Deprecation.warn ":name_prefix was deprecated in the new router syntax. Use :as instead.", caller ActiveSupport::Deprecation.warn ":name_prefix was deprecated in the new routes syntax. Use :as instead.", caller
end end
case args.first case args.first

View File

@ -268,10 +268,10 @@ module ActionDispatch
# Yes plz - JP # Yes plz - JP
included do included do
routes.install_helpers(self) routes.install_helpers(self)
singleton_class.send(:define_method, :_router) { routes } singleton_class.send(:define_method, :_routes) { routes }
end end
define_method(:_router) { routes } define_method(:_routes) { routes }
end end
helpers helpers
@ -474,7 +474,7 @@ module ActionDispatch
path_options = yield(path_options) if block_given? path_options = yield(path_options) if block_given?
path = generate(path_options, path_segments || {}) path = generate(path_options, path_segments || {})
# ROUTES TODO: This can be called directly, so script_name should probably be set in the router # ROUTES TODO: This can be called directly, so script_name should probably be set in routes
rewritten_url << (options[:trailing_slash] ? path.sub(/\?|\z/) { "/" + $& } : path) rewritten_url << (options[:trailing_slash] ? path.sub(/\?|\z/) { "/" + $& } : path)
rewritten_url << "##{Rack::Mount::Utils.escape_uri(options[:anchor].to_param.to_s)}" if options[:anchor] rewritten_url << "##{Rack::Mount::Utils.escape_uri(options[:anchor].to_param.to_s)}" if options[:anchor]

View File

@ -128,7 +128,7 @@ module ActionDispatch
when String when String
options options
when nil, Hash when nil, Hash
_router.url_for(url_options.merge((options || {}).symbolize_keys)) _routes.url_for(url_options.merge((options || {}).symbolize_keys))
else else
polymorphic_url(options) polymorphic_url(options)
end end

View File

@ -173,7 +173,7 @@ module ActionView #:nodoc:
@@field_error_proc = Proc.new{ |html_tag, instance| "<div class=\"field_with_errors\">#{html_tag}</div>".html_safe } @@field_error_proc = Proc.new{ |html_tag, instance| "<div class=\"field_with_errors\">#{html_tag}</div>".html_safe }
class_attribute :helpers class_attribute :helpers
class_attribute :_router class_attribute :_routes
class << self class << self
delegate :erb_trim_mode=, :to => 'ActionView::Template::Handlers::ERB' delegate :erb_trim_mode=, :to => 'ActionView::Template::Handlers::ERB'

View File

@ -12,7 +12,7 @@ module ActionView
# and controllers. # and controllers.
module UrlHelper module UrlHelper
# This helper may be included in any class that includes the # This helper may be included in any class that includes the
# URL helpers of a router (router.url_helpers). Some methods # URL helpers of a routes (routes.url_helpers). Some methods
# provided here will only work in the4 context of a request # provided here will only work in the4 context of a request
# (link_to_unless_current, for instance), which must be provided # (link_to_unless_current, for instance), which must be provided
# as a method called #request on the context. # as a method called #request on the context.

View File

@ -151,7 +151,7 @@ module ActionView
@view ||= begin @view ||= begin
view = ActionView::Base.new(ActionController::Base.view_paths, {}, @controller) view = ActionView::Base.new(ActionController::Base.view_paths, {}, @controller)
view.singleton_class.send :include, _helpers view.singleton_class.send :include, _helpers
view.singleton_class.send :include, @controller._router.url_helpers view.singleton_class.send :include, @controller._routes.url_helpers
view.singleton_class.send :delegate, :alert, :notice, :to => "request.flash" view.singleton_class.send :delegate, :alert, :notice, :to => "request.flash"
view.extend(Locals) view.extend(Locals)
view.locals = self.locals view.locals = self.locals
@ -192,13 +192,13 @@ module ActionView
end end
end end
def _router def _routes
@controller._router if @controller.respond_to?(:_router) @controller._routes if @controller.respond_to?(:_routes)
end end
def method_missing(selector, *args) def method_missing(selector, *args)
if @controller.respond_to?(:_router) && if @controller.respond_to?(:_routes) &&
@controller._router.named_routes.helpers.include?(selector) @controller._routes.named_routes.helpers.include?(selector)
@controller.__send__(selector, *args) @controller.__send__(selector, *args)
else else
super super

View File

@ -41,7 +41,7 @@ require 'pp' # require 'pp' early to prevent hidden_methods from not picking up
module Rails module Rails
end end
# Monkey patch the old router initialization to be silenced. # Monkey patch the old routes initialization to be silenced.
class ActionDispatch::Routing::DeprecatedMapper class ActionDispatch::Routing::DeprecatedMapper
def initialize_with_silencer(*args) def initialize_with_silencer(*args)
ActiveSupport::Deprecation.silence { initialize_without_silencer(*args) } ActiveSupport::Deprecation.silence { initialize_without_silencer(*args) }
@ -275,9 +275,9 @@ end
class ActionController::Base class ActionController::Base
def self.test_routes(&block) def self.test_routes(&block)
router = ActionDispatch::Routing::RouteSet.new routes = ActionDispatch::Routing::RouteSet.new
router.draw(&block) routes.draw(&block)
include router.url_helpers include routes.url_helpers
end end
end end

View File

@ -120,7 +120,7 @@ module AbstractController
def test_relative_url_root_is_respected def test_relative_url_root_is_respected
# ROUTES TODO: Tests should not have to pass :relative_url_root directly. This # ROUTES TODO: Tests should not have to pass :relative_url_root directly. This
# should probably come from the router. # should probably come from routes.
add_host! add_host!
assert_equal('https://www.basecamphq.com/subdir/c/a/i', assert_equal('https://www.basecamphq.com/subdir/c/a/i',

View File

@ -2,24 +2,24 @@ require 'abstract_unit'
module TestUrlGeneration module TestUrlGeneration
class WithMountPoint < ActionDispatch::IntegrationTest class WithMountPoint < ActionDispatch::IntegrationTest
Router = ActionDispatch::Routing::RouteSet.new Routes = ActionDispatch::Routing::RouteSet.new
Router.draw { match "/foo", :to => "my_route_generating#index", :as => :foo } Routes.draw { match "/foo", :to => "my_route_generating#index", :as => :foo }
class ::MyRouteGeneratingController < ActionController::Base class ::MyRouteGeneratingController < ActionController::Base
include Router.url_helpers include Routes.url_helpers
def index def index
render :text => foo_path render :text => foo_path
end end
end end
include Router.url_helpers include Routes.url_helpers
def _router def _routes
Router Routes
end end
def app def app
Router Routes
end end
test "generating URLS normally" do test "generating URLS normally" do
@ -30,7 +30,7 @@ module TestUrlGeneration
assert_equal "/bar/foo", foo_path(:script_name => "/bar") assert_equal "/bar/foo", foo_path(:script_name => "/bar")
end end
test "the request's SCRIPT_NAME takes precedence over the router's" do test "the request's SCRIPT_NAME takes precedence over the routes'" do
get "/foo", {}, 'SCRIPT_NAME' => "/new" get "/foo", {}, 'SCRIPT_NAME' => "/new"
assert_equal "/new/foo", response.body assert_equal "/new/foo", response.body
end end