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 " \
"directly. You need to set config.action_mailer.default_url_options. " \
"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
# 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,
# 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
ActiveSupport.run_load_hooks(:action_mailer, self)

View File

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

View File

@ -96,7 +96,7 @@ module ActionController
def resource_action_separator=(val)
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
end

View File

@ -47,7 +47,7 @@ module ActionController
#
# 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
# 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).
class Metal < AbstractController::Base
abstract!

View File

@ -12,15 +12,15 @@ module ActionController
).merge(:script_name => request.script_name)
end
def _router
def _routes
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
module ClassMethods
def action_methods
@action_methods ||= begin
super - _router.named_routes.helper_names
super - _routes.named_routes.helper_names
end
end
end

View File

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

View File

@ -308,7 +308,7 @@ module ActionDispatch
if name_prefix = options.delete(: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
case args.first

View File

@ -268,10 +268,10 @@ module ActionDispatch
# Yes plz - JP
included do
routes.install_helpers(self)
singleton_class.send(:define_method, :_router) { routes }
singleton_class.send(:define_method, :_routes) { routes }
end
define_method(:_router) { routes }
define_method(:_routes) { routes }
end
helpers
@ -474,7 +474,7 @@ module ActionDispatch
path_options = yield(path_options) if block_given?
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 << "##{Rack::Mount::Utils.escape_uri(options[:anchor].to_param.to_s)}" if options[:anchor]

View File

@ -128,7 +128,7 @@ module ActionDispatch
when String
options
when nil, Hash
_router.url_for(url_options.merge((options || {}).symbolize_keys))
_routes.url_for(url_options.merge((options || {}).symbolize_keys))
else
polymorphic_url(options)
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 }
class_attribute :helpers
class_attribute :_router
class_attribute :_routes
class << self
delegate :erb_trim_mode=, :to => 'ActionView::Template::Handlers::ERB'

View File

@ -12,7 +12,7 @@ module ActionView
# and controllers.
module UrlHelper
# 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
# (link_to_unless_current, for instance), which must be provided
# as a method called #request on the context.

View File

@ -151,7 +151,7 @@ module ActionView
@view ||= begin
view = ActionView::Base.new(ActionController::Base.view_paths, {}, @controller)
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.extend(Locals)
view.locals = self.locals
@ -192,13 +192,13 @@ module ActionView
end
end
def _router
@controller._router if @controller.respond_to?(:_router)
def _routes
@controller._routes if @controller.respond_to?(:_routes)
end
def method_missing(selector, *args)
if @controller.respond_to?(:_router) &&
@controller._router.named_routes.helpers.include?(selector)
if @controller.respond_to?(:_routes) &&
@controller._routes.named_routes.helpers.include?(selector)
@controller.__send__(selector, *args)
else
super

View File

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

View File

@ -120,7 +120,7 @@ module AbstractController
def test_relative_url_root_is_respected
# 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!
assert_equal('https://www.basecamphq.com/subdir/c/a/i',

View File

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