Permalink
Browse files

Merge branch 'master' of git://github.com/rails/rails

Conflicts:
	actionmailer/lib/action_mailer/mail_helper.rb
	railties/lib/rails/configuration.rb
  • Loading branch information...
2 parents a74a655 + 396003f commit 4e96442c4e404141830b2d7f0d850b6556190b39 José Valim and Mikel Lindsaar committed Jan 24, 2010
Showing with 1,214 additions and 914 deletions.
  1. +1 −7 actionmailer/lib/action_mailer/railtie.rb
  2. +1 −1 actionpack/lib/action_controller/base.rb
  3. +11 −6 actionpack/lib/action_controller/metal/helpers.rb
  4. +1 −18 actionpack/lib/action_controller/railtie.rb
  5. +1 −1 actionpack/lib/action_dispatch/middleware/callbacks.rb
  6. +2 −13 actionpack/lib/action_dispatch/railtie.rb
  7. +7 −21 actionpack/lib/action_dispatch/routing/route_set.rb
  8. +1 −1 actionpack/lib/action_view/railtie.rb
  9. +1 −1 actionpack/test/abstract/helper_test.rb
  10. +2 −2 actionpack/test/controller/helper_test.rb
  11. +4 −2 actionpack/test/fixtures/helpers/fun/games_helper.rb
  12. +4 −2 actionpack/test/fixtures/helpers/fun/pdf_helper.rb
  13. +6 −6 activerecord/lib/active_record/railtie.rb
  14. +7 −1 activeresource/lib/active_resource/railtie.rb
  15. +60 −0 activesupport/lib/active_support/railtie.rb
  16. +1 −1 railties/lib/generators/rails/app/templates/Rakefile
  17. +2 −2 railties/lib/generators/rails/app/templates/config/boot.rb
  18. +1 −1 railties/lib/generators/rails/app/templates/script/console.tt
  19. +1 −1 railties/lib/generators/rails/app/templates/script/dbconsole.tt
  20. +1 −1 railties/lib/generators/rails/metal/templates/metal.rb
  21. +1 −1 railties/lib/generators/rails/plugin/plugin_generator.rb
  22. 0 railties/lib/generators/rails/plugin/templates/{ → lib}/tasks/%file_name%_tasks.rake.tt
  23. +0 −9 railties/lib/rails.rb
  24. +1 −0 railties/lib/rails/all.rb
  25. +68 −110 railties/lib/rails/application.rb
  26. +81 −0 railties/lib/rails/application/bootstrap.rb
  27. +85 −0 railties/lib/rails/application/configuration.rb
  28. +43 −0 railties/lib/rails/application/finisher.rb
  29. +31 −0 railties/lib/rails/application/railties.rb
  30. +49 −0 railties/lib/rails/application/routes_reloader.rb
  31. +0 −161 railties/lib/rails/bootstrap.rb
  32. +4 −4 railties/lib/rails/commands/console.rb
  33. +126 −269 railties/lib/rails/configuration.rb
  34. +6 −5 railties/lib/rails/{console_app.rb → console/app.rb}
  35. 0 railties/lib/rails/{console_with_helpers.rb → console/helpers.rb}
  36. 0 railties/lib/rails/{console_sandbox.rb → console/sandbox.rb}
  37. +128 −0 railties/lib/rails/engine.rb
  38. +25 −0 railties/lib/rails/engine/configurable.rb
  39. +49 −0 railties/lib/rails/engine/configuration.rb
  40. +5 −14 railties/lib/rails/initializable.rb
  41. +24 −20 railties/lib/rails/paths.rb
  42. +26 −37 railties/lib/rails/plugin.rb
  43. +22 −7 railties/lib/rails/rack/metal.rb
  44. +52 −32 railties/lib/rails/railtie.rb
  45. +23 −0 railties/lib/rails/railtie/configurable.rb
  46. +9 −0 railties/lib/rails/railtie/configuration.rb
  47. +31 −23 railties/lib/rails/tasks/documentation.rake
  48. +1 −1 railties/lib/rails/tasks/middleware.rake
  49. +1 −0 railties/lib/rails/tasks/routes.rake
  50. +2 −2 railties/test/application/console_test.rb
  51. +13 −2 railties/test/application/initializer_test.rb
  52. +0 −27 railties/test/application/notifications_test.rb
  53. +1 −1 railties/test/generators/plugin_generator_test.rb
  54. +11 −17 railties/test/initializable_test.rb
  55. +0 −55 railties/test/initializer/initialize_i18n_test.rb
  56. +9 −14 railties/test/initializer/path_test.rb
  57. +15 −12 railties/test/paths_test.rb
  58. +3 −3 railties/test/plugins/configuration_test.rb
  59. +154 −0 railties/test/plugins/vendored_test.rb
@@ -3,7 +3,7 @@
module ActionMailer
class Railtie < Rails::Railtie
- plugin_name :action_mailer
+ railtie_name :action_mailer
require "action_mailer/railties/subscriber"
subscriber ActionMailer::Railties::Subscriber.new
@@ -18,11 +18,5 @@ class Railtie < Rails::Railtie
initializer "action_mailer.logger" do
ActionMailer::Base.logger ||= Rails.logger
end
-
- initializer "action_mailer.view_paths" do |app|
- # TODO: this should be combined with the logic for default config.action_mailer.view_paths
- view_path = ActionView::PathSet.type_cast(app.config.view_path, app.config.cache_classes)
- ActionMailer::Base.template_root = view_path if ActionMailer::Base.view_paths.blank?
- end
end
end
@@ -7,7 +7,6 @@ class Base < Metal
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 @@ def method_for_action(action_name)
def self.inherited(klass)
::ActionController::Base.subclasses << klass.to_s
super
+ klass.helper :all
end
def self.subclasses
@@ -50,9 +50,8 @@ module Helpers
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 @@ def default_helper_module!
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
@@ -3,7 +3,7 @@
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 @@ class Railtie < Rails::Railtie
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
@@ -37,7 +37,7 @@ def self.after(*args, &block)
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)
@@ -3,24 +3,13 @@
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
@@ -222,19 +222,18 @@ def #{selector}(*args)
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 @@ def empty?
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
@@ -3,7 +3,7 @@
module ActionView
class Railtie < Rails::Railtie
- plugin_name :action_view
+ railtie_name :action_view
require "action_view/railties/subscriber"
subscriber ActionView::Railties::Subscriber.new
@@ -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
@@ -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 @@ def test_all_helpers
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
@@ -1,3 +1,5 @@
-module Fun::GamesHelper
- def stratego() "Iz guuut!" end
+module Fun
+ module GamesHelper
+ def stratego() "Iz guuut!" end
+ end
end
@@ -1,3 +1,5 @@
-module Fun::PdfHelper
- def foobar() 'baz' end
+module Fun
+ module PdfHelper
+ def foobar() 'baz' end
+ end
end
@@ -8,7 +8,7 @@
module ActiveRecord
class Railtie < Rails::Railtie
- plugin_name :active_record
+ railtie_name :active_record
rake_tasks do
load "active_record/railties/databases.rake"
@@ -18,6 +18,11 @@ class Railtie < Rails::Railtie
require "active_record/railties/subscriber"
subscriber ActiveRecord::Railties::Subscriber.new
+ initializer "active_record.initialize_timezone" do
+ ActiveRecord::Base.time_zone_aware_attributes = true
+ ActiveRecord::Base.default_timezone = :utc
+ end
+
initializer "active_record.set_configs" do |app|
app.config.active_record.each do |k,v|
ActiveRecord::Base.send "#{k}=", v
@@ -31,11 +36,6 @@ class Railtie < Rails::Railtie
ActiveRecord::Base.establish_connection
end
- initializer "active_record.initialize_timezone" do
- ActiveRecord::Base.time_zone_aware_attributes = true
- ActiveRecord::Base.default_timezone = :utc
- end
-
# Expose database runtime to controller for logging.
initializer "active_record.log_runtime" do |app|
require "active_record/railties/controller_runtime"
@@ -3,9 +3,15 @@
module ActiveResource
class Railtie < Rails::Railtie
- plugin_name :active_resource
+ railtie_name :active_resource
require "active_resource/railties/subscriber"
subscriber ActiveResource::Railties::Subscriber.new
+
+ initializer "active_resource.set_configs" do |app|
+ app.config.active_resource.each do |k,v|
+ ActiveResource::Base.send "#{k}=", v
+ end
+ end
end
end
@@ -0,0 +1,60 @@
+require "active_support"
+require "rails"
+
+module I18n
+ class Railtie < Rails::Railtie
+ railtie_name :i18n
+
+ # Initialize I18n load paths to an array
+ config.i18n.load_path = []
+
+ initializer :initialize_i18n do
+ require 'active_support/i18n'
+
+ ActionDispatch::Callbacks.to_prepare do
+ I18n.reload!
+ end
+ end
+
+ # Set the i18n configuration from config.i18n but special-case for
+ # the load_path which should be appended to what's already set instead of overwritten.
+ config.after_initialize do |app|
+ app.config.i18n.each do |setting, value|
+ if setting == :load_path
+ I18n.load_path += value
+ else
+ I18n.send("#{setting}=", value)
+ end
+ end
+
+ I18n.reload!
+ end
+ end
+end
+
+module ActiveSupport
+ class Railtie < Rails::Railtie
+ railtie_name :active_support
+
+ # Loads support for "whiny nil" (noisy warnings when methods are invoked
+ # on +nil+ values) if Configuration#whiny_nils is true.
+ initializer :initialize_whiny_nils do |app|
+ require 'active_support/whiny_nil' if app.config.whiny_nils
+ end
+
+ # Sets the default value for Time.zone
+ # If assigned value cannot be matched to a TimeZone, an exception will be raised.
+ initializer :initialize_time_zone do |app|
+ require 'active_support/core_ext/time/zones'
+ zone_default = Time.__send__(:get_zone, app.config.time_zone)
+
+ unless zone_default
+ raise \
+ 'Value assigned to config.time_zone not recognized.' +
+ 'Run "rake -D time" for a list of tasks for finding appropriate time zone names.'
+ end
+
+ Time.zone_default = zone_default
+ end
+ end
+end
@@ -7,4 +7,4 @@ require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
-<%= app_const %>.load_tasks
+Rails::Application.load_tasks
@@ -19,7 +19,7 @@
# To pick the frameworks you want, remove 'require "rails/all"'
# and list the framework railties that you want:
#
-# require "active_model/railtie"
+# require "active_support/railtie"
# require "active_record/railtie"
# require "action_controller/railtie"
# require "action_view/railtie"
@@ -28,7 +28,7 @@
<% else -%>
# Pick the frameworks you want:
# require "active_record/railtie"
-require "active_model/railtie"
+require "active_support/railtie"
require "action_controller/railtie"
require "action_view/railtie"
require "action_mailer/railtie"
@@ -2,4 +2,4 @@ require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands/console'
require File.expand_path('../../config/application', __FILE__)
-Rails::Console.start(<%= app_const %>)
+Rails::Console.start(Rails::Application)
Oops, something went wrong.

0 comments on commit 4e96442

Please sign in to comment.