diff options
author | José Valim and Mikel Lindsaar <pair@programming.com> | 2010-01-25 09:50:01 +1100 |
---|---|---|
committer | José Valim and Mikel Lindsaar <pair@programming.com> | 2010-01-25 09:50:01 +1100 |
commit | 4e96442c4e404141830b2d7f0d850b6556190b39 (patch) | |
tree | a3ca088ad9d68b5be9ace4d431375bb3fd4ea045 /actionpack | |
parent | a74a655648618a6ed568b9b4ef3a17a8970e7774 (diff) | |
parent | 396003fc48d7c0ba206ad059646c7414bee22a36 (diff) | |
download | rails-4e96442c4e404141830b2d7f0d850b6556190b39.tar.gz rails-4e96442c4e404141830b2d7f0d850b6556190b39.tar.bz2 rails-4e96442c4e404141830b2d7f0d850b6556190b39.zip |
Merge branch 'master' of git://github.com/rails/rails
Conflicts:
actionmailer/lib/action_mailer/mail_helper.rb
railties/lib/rails/configuration.rb
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_controller/base.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal/helpers.rb | 17 | ||||
-rw-r--r-- | actionpack/lib/action_controller/railtie.rb | 19 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/callbacks.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/railtie.rb | 15 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/route_set.rb | 28 | ||||
-rw-r--r-- | actionpack/lib/action_view/railtie.rb | 2 | ||||
-rw-r--r-- | actionpack/test/abstract/helper_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/helper_test.rb | 4 | ||||
-rw-r--r-- | actionpack/test/fixtures/helpers/fun/games_helper.rb | 6 | ||||
-rw-r--r-- | actionpack/test/fixtures/helpers/fun/pdf_helper.rb | 6 |
11 files changed, 35 insertions, 68 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index f46231d72b..215b70734c 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -7,7 +7,6 @@ module ActionController include AbstractController::Translation include ActionController::Helpers - helper :all # By default, all helpers should be included include ActionController::HideActions include ActionController::UrlFor @@ -67,6 +66,7 @@ module ActionController def self.inherited(klass) ::ActionController::Base.subclasses << klass.to_s super + klass.helper :all end def self.subclasses diff --git a/actionpack/lib/action_controller/metal/helpers.rb b/actionpack/lib/action_controller/metal/helpers.rb index cdd14560e1..0e3db86861 100644 --- a/actionpack/lib/action_controller/metal/helpers.rb +++ b/actionpack/lib/action_controller/metal/helpers.rb @@ -50,9 +50,8 @@ module ActionController include AbstractController::Helpers included do - # Set the default directory for helpers - extlib_inheritable_accessor(:helpers_dir) do - defined?(Rails.root) ? "#{Rails.root}/app/helpers" : "app/helpers" + extlib_inheritable_accessor(:helpers_path) do + defined?(Rails::Application) ? Rails::Application.paths.app.helpers.to_a : [] end end @@ -105,10 +104,16 @@ module ActionController raise e unless e.missing_name? "#{module_name}Helper" end - # Extract helper names from files in app/helpers/**/*.rb + # Extract helper names from files in app/helpers/**/*_helper.rb def all_application_helpers - extract = /^#{Regexp.quote(helpers_dir)}\/?(.*)_helper.rb$/ - Dir["#{helpers_dir}/**/*_helper.rb"].map { |file| file.sub extract, '\1' } + helpers = [] + helpers_path.each do |path| + extract = /^#{Regexp.quote(path)}\/?(.*)_helper.rb$/ + helpers += Dir["#{path}/**/*_helper.rb"].map { |file| file.sub(extract, '\1') } + end + helpers.sort! + helpers.uniq! + helpers end end end diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index 7ea64c1923..f15c012471 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -3,7 +3,7 @@ require "rails" module ActionController class Railtie < Rails::Railtie - plugin_name :action_controller + railtie_name :action_controller require "action_controller/railties/subscriber" subscriber ActionController::Railties::Subscriber.new @@ -19,25 +19,8 @@ module ActionController ActionController::Base.logger ||= Rails.logger end - # Routing must be initialized after plugins to allow the former to extend the routes - initializer "action_controller.initialize_routing" do |app| - app.route_configuration_files << app.config.routes_configuration_file - app.route_configuration_files << app.config.builtin_routes_configuration_file - end - initializer "action_controller.initialize_framework_caches" do ActionController::Base.cache_store ||= RAILS_CACHE end - - # Sets +ActionController::Base#view_paths+ and +ActionMailer::Base#template_root+ - # (but only for those frameworks that are to be loaded). If the framework's - # paths have already been set, it is not changed, otherwise it is - # set to use Configuration#view_path. - initializer "action_controller.initialize_framework_views" do |app| - # TODO: this should be combined with the logic for default config.action_controller.view_paths - view_path = ActionView::PathSet.type_cast(app.config.view_path, app.config.cache_classes) - ActionController::Base.view_paths = view_path if ActionController::Base.view_paths.blank? - end - end end diff --git a/actionpack/lib/action_dispatch/middleware/callbacks.rb b/actionpack/lib/action_dispatch/middleware/callbacks.rb index d07841218a..7cf75ffe63 100644 --- a/actionpack/lib/action_dispatch/middleware/callbacks.rb +++ b/actionpack/lib/action_dispatch/middleware/callbacks.rb @@ -37,7 +37,7 @@ module ActionDispatch def initialize(app, prepare_each_request = false) @app, @prepare_each_request = app, prepare_each_request - run_callbacks(:prepare) + run_callbacks(:prepare) unless @prepare_each_request end def call(env) diff --git a/actionpack/lib/action_dispatch/railtie.rb b/actionpack/lib/action_dispatch/railtie.rb index e4bd143e78..335daafc01 100644 --- a/actionpack/lib/action_dispatch/railtie.rb +++ b/actionpack/lib/action_dispatch/railtie.rb @@ -3,24 +3,13 @@ require "rails" module ActionDispatch class Railtie < Rails::Railtie - plugin_name :action_dispatch + railtie_name :action_dispatch # Prepare dispatcher callbacks and run 'prepare' callbacks initializer "action_dispatch.prepare_dispatcher" do |app| # TODO: This used to say unless defined?(Dispatcher). Find out why and fix. require 'rails/dispatcher' - - unless app.config.cache_classes - # Setup dev mode route reloading - routes_last_modified = app.routes_changed_at - reload_routes = lambda do - unless app.routes_changed_at == routes_last_modified - routes_last_modified = app.routes_changed_at - app.reload_routes! - end - end - ActionDispatch::Callbacks.before { |callbacks| reload_routes.call } - end + ActionDispatch::Callbacks.to_prepare { app.routes_reloader.reload_if_changed } end end end
\ No newline at end of file diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 660d28dbec..c49ac70562 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -222,19 +222,18 @@ module ActionDispatch end end - attr_accessor :routes, :named_routes - attr_accessor :disable_clear_and_finalize + attr_accessor :routes, :named_routes, :controller_namespaces + attr_accessor :disable_clear_and_finalize, :resources_path_names def self.default_resources_path_names { :new => 'new', :edit => 'edit' } end - attr_accessor :resources_path_names - def initialize self.routes = [] self.named_routes = NamedRouteCollection.new - self.resources_path_names = self.class.default_resources_path_names + self.resources_path_names = self.class.default_resources_path_names.dup + self.controller_namespaces = Set.new @disable_clear_and_finalize = false end @@ -281,32 +280,19 @@ module ActionDispatch def controller_constraints @controller_constraints ||= begin - source = controller_namespaces.map { |ns| "#{Regexp.escape(ns)}/#{CONTROLLER_REGEXP.source}" } + namespaces = controller_namespaces + in_memory_controller_namespaces + source = namespaces.map { |ns| "#{Regexp.escape(ns)}/#{CONTROLLER_REGEXP.source}" } source << CONTROLLER_REGEXP.source Regexp.compile(source.sort.reverse.join('|')) end end - def controller_namespaces + def in_memory_controller_namespaces namespaces = Set.new - - # Find any nested controllers already in memory ActionController::Base.subclasses.each do |klass| controller_name = klass.underscore namespaces << controller_name.split('/')[0...-1].join('/') end - - # TODO: Move this into Railties - if defined?(Rails.application) - # Find namespaces in controllers/ directory - Rails.application.config.controller_paths.each do |load_path| - load_path = File.expand_path(load_path) - Dir["#{load_path}/**/*_controller.rb"].collect do |path| - namespaces << File.dirname(path).sub(/#{load_path}\/?/, '') - end - end - end - namespaces.delete('') namespaces end diff --git a/actionpack/lib/action_view/railtie.rb b/actionpack/lib/action_view/railtie.rb index 968dc7b25e..d9e2557d89 100644 --- a/actionpack/lib/action_view/railtie.rb +++ b/actionpack/lib/action_view/railtie.rb @@ -3,7 +3,7 @@ require "rails" module ActionView class Railtie < Rails::Railtie - plugin_name :action_view + railtie_name :action_view require "action_view/railties/subscriber" subscriber ActionView::Railties::Subscriber.new diff --git a/actionpack/test/abstract/helper_test.rb b/actionpack/test/abstract/helper_test.rb index ade29140ba..0cdf5c2298 100644 --- a/actionpack/test/abstract/helper_test.rb +++ b/actionpack/test/abstract/helper_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' -ActionController::Base.helpers_dir = File.dirname(__FILE__) + '/../fixtures/helpers' +ActionController::Base.helpers_path = [File.dirname(__FILE__) + '/../fixtures/helpers'] module AbstractController module Testing diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb index 9030e562bb..fe0961e575 100644 --- a/actionpack/test/controller/helper_test.rb +++ b/actionpack/test/controller/helper_test.rb @@ -1,7 +1,7 @@ require 'abstract_unit' require 'active_support/core_ext/kernel/reporting' -ActionController::Base.helpers_dir = File.dirname(__FILE__) + '/../fixtures/helpers' +ActionController::Base.helpers_path = [File.dirname(__FILE__) + '/../fixtures/helpers'] module Fun class GamesController < ActionController::Base @@ -106,7 +106,7 @@ class HelperTest < Test::Unit::TestCase end def test_all_helpers_with_alternate_helper_dir - @controller_class.helpers_dir = File.dirname(__FILE__) + '/../fixtures/alternate_helpers' + @controller_class.helpers_path = [File.dirname(__FILE__) + '/../fixtures/alternate_helpers'] # Reload helpers @controller_class._helpers = Module.new diff --git a/actionpack/test/fixtures/helpers/fun/games_helper.rb b/actionpack/test/fixtures/helpers/fun/games_helper.rb index bf60d9db0c..3b7adce086 100644 --- a/actionpack/test/fixtures/helpers/fun/games_helper.rb +++ b/actionpack/test/fixtures/helpers/fun/games_helper.rb @@ -1,3 +1,5 @@ -module Fun::GamesHelper - def stratego() "Iz guuut!" end +module Fun + module GamesHelper + def stratego() "Iz guuut!" end + end end
\ No newline at end of file diff --git a/actionpack/test/fixtures/helpers/fun/pdf_helper.rb b/actionpack/test/fixtures/helpers/fun/pdf_helper.rb index c4aea5a3f3..0171be8500 100644 --- a/actionpack/test/fixtures/helpers/fun/pdf_helper.rb +++ b/actionpack/test/fixtures/helpers/fun/pdf_helper.rb @@ -1,3 +1,5 @@ -module Fun::PdfHelper - def foobar() 'baz' end +module Fun + module PdfHelper + def foobar() 'baz' end + end end |