aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorJosé Valim and Mikel Lindsaar <pair@programming.com>2010-01-24 23:59:29 +0100
committerJosé Valim and Mikel Lindsaar <pair@programming.com>2010-01-24 23:59:29 +0100
commit90e9e46576c0a8d57887484cd4f3f51b3b6cce3a (patch)
treede254a8fd31ae36f8b9371c9f0e645c7ed1b727d /actionpack/lib
parent0ece244feec236f57fb2f55ea564409f25475923 (diff)
parent4e96442c4e404141830b2d7f0d850b6556190b39 (diff)
downloadrails-90e9e46576c0a8d57887484cd4f3f51b3b6cce3a.tar.gz
rails-90e9e46576c0a8d57887484cd4f3f51b3b6cce3a.tar.bz2
rails-90e9e46576c0a8d57887484cd4f3f51b3b6cce3a.zip
Merge branch 'master' of github.com:mikel/rails
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller/base.rb2
-rw-r--r--actionpack/lib/action_controller/metal/helpers.rb17
-rw-r--r--actionpack/lib/action_controller/railtie.rb19
-rw-r--r--actionpack/lib/action_dispatch/middleware/callbacks.rb2
-rw-r--r--actionpack/lib/action_dispatch/railtie.rb15
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb28
-rw-r--r--actionpack/lib/action_view/railtie.rb2
7 files changed, 24 insertions, 61 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