Permalink
Browse files

Merge commit 'mainstream/master'

  • Loading branch information...
2 parents 91ab753 + 441e4e2 commit 21b80f8144f8f05a105b2989c79d3ed2f2d0d4cd @lifo lifo committed Feb 22, 2009
Showing with 450 additions and 230 deletions.
  1. +3 −1 actionmailer/lib/action_mailer/base.rb
  2. +1 −1 actionmailer/test/mail_service_test.rb
  3. +1 −0 actionpack/lib/action_controller.rb
  4. +27 −14 actionpack/lib/action_controller/dispatcher.rb
  5. +26 −32 actionpack/lib/action_controller/layout.rb
  6. +13 −3 actionpack/lib/action_controller/middleware_stack.rb
  7. +2 −11 actionpack/lib/action_controller/middlewares.rb
  8. +14 −0 actionpack/lib/action_controller/reloader.rb
  9. +12 −20 actionpack/lib/action_controller/routing/segments.rb
  10. +2 −2 actionpack/lib/action_view/base.rb
  11. +37 −40 actionpack/lib/action_view/reloadable_template.rb
  12. +10 −14 actionpack/lib/action_view/template.rb
  13. +2 −2 actionpack/test/activerecord/render_partial_with_record_identification_test.rb
  14. +8 −5 actionpack/test/controller/dispatcher_test.rb
  15. +14 −0 actionpack/test/controller/layout_test.rb
  16. +14 −0 actionpack/test/controller/middleware_stack_test.rb
  17. +34 −0 actionpack/test/controller/routing_test.rb
  18. +1 −1 actionpack/test/controller/session/cookie_store_test.rb
  19. +11 −15 actionpack/test/controller/view_paths_test.rb
  20. 0 actionpack/test/fixtures/layout_tests/alt/layouts/alt.rhtml
  21. +103 −25 actionpack/test/template/compiled_templates_test.rb
  22. +2 −0 activesupport/CHANGELOG
  23. +19 −5 activesupport/lib/active_support/core_ext/array/conversions.rb
  24. +1 −1 activesupport/lib/active_support/core_ext/file/atomic.rb
  25. +16 −0 activesupport/lib/active_support/core_ext/uri.rb
  26. +18 −0 activesupport/test/core_ext/array_ext_test.rb
  27. +12 −0 activesupport/test/core_ext/uri_ext_test.rb
  28. +1 −2 railties/lib/console_app.rb
  29. +9 −5 railties/lib/initializer.rb
  30. +26 −24 railties/lib/rails/plugin/loader.rb
  31. +2 −2 railties/lib/tasks/gems.rake
  32. +3 −2 railties/test/initializer_test.rb
  33. +6 −3 railties/test/plugin_loader_test.rb
@@ -254,6 +254,8 @@ class Base
private_class_method :new #:nodoc:
class_inheritable_accessor :view_paths
+ self.view_paths = []
+
cattr_accessor :logger
@@smtp_settings = {
@@ -594,7 +596,7 @@ def template_path
end
def initialize_template_class(assigns)
- template = ActionView::Base.new(view_paths, assigns, self)
+ template = ActionView::Base.new(self.class.view_paths, assigns, self)
template.template_format = default_template_format
template
end
@@ -975,7 +975,7 @@ def test_starttls_is_not_enabled
class InheritableTemplateRootTest < Test::Unit::TestCase
def test_attr
- expected = ("#{File.dirname(__FILE__)}/fixtures/path.with.dots").sub(/\.\//, '')
+ expected = "#{File.dirname(__FILE__)}/fixtures/path.with.dots"
assert_equal expected, FunkyPathMailer.template_root.to_s
sub = Class.new(FunkyPathMailer)
@@ -59,6 +59,7 @@ def self.load_all!
autoload :ParamsParser, 'action_controller/params_parser'
autoload :PolymorphicRoutes, 'action_controller/polymorphic_routes'
autoload :RecordIdentifier, 'action_controller/record_identifier'
+ autoload :Reloader, 'action_controller/reloader'
autoload :Request, 'action_controller/request'
autoload :RequestForgeryProtection, 'action_controller/request_forgery_protection'
autoload :Rescue, 'action_controller/rescue'
@@ -5,8 +5,9 @@ class Dispatcher
class << self
def define_dispatcher_callbacks(cache_classes)
unless cache_classes
- # Development mode callbacks
- before_dispatch :reload_application
+ unless self.middleware.include?(Reloader)
+ self.middleware.insert_after(Failsafe, Reloader)
+ end
ActionView::Helpers::AssetTagHelper.cache_asset_timestamps = false
end
@@ -41,6 +42,30 @@ def to_prepare(identifier = nil, &block)
callback = ActiveSupport::Callbacks::Callback.new(:prepare_dispatch, block, :identifier => identifier)
@prepare_dispatch_callbacks.replace_or_append!(callback)
end
+
+ def run_prepare_callbacks
+ if defined?(Rails) && Rails.logger
+ logger = Rails.logger
+ else
+ logger = Logger.new($stderr)
+ end
+
+ new(logger).send :run_callbacks, :prepare_dispatch
+ end
+
+ def reload_application
+ # Run prepare callbacks before every request in development mode
+ run_prepare_callbacks
+
+ Routing::Routes.reload
+ end
+
+ def cleanup_application
+ # Cleanup the application before processing the current request.
+ ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord)
+ ActiveSupport::Dependencies.clear
+ ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord)
+ end
end
cattr_accessor :middleware
@@ -87,18 +112,6 @@ def _call(env)
dispatch
end
- def reload_application
- # Cleanup the application before processing the current request.
- ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord)
- ActiveSupport::Dependencies.clear
- ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord)
-
- # Run prepare callbacks before every request in development mode
- run_callbacks :prepare_dispatch
-
- Routing::Routes.reload
- end
-
def flush_logger
Base.logger.flush
end
@@ -172,23 +172,10 @@ def layout_conditions #:nodoc:
@layout_conditions ||= read_inheritable_attribute(:layout_conditions)
end
- def default_layout(format) #:nodoc:
- layout = read_inheritable_attribute(:layout) unless format == :js
- return layout unless read_inheritable_attribute(:auto_layout)
- find_layout(layout, format)
- end
-
def layout_list #:nodoc:
Array(view_paths).sum([]) { |path| Dir["#{path.to_str}/layouts/**/*"] }
end
- def find_layout(layout, *formats) #:nodoc:
- return layout if layout.respond_to?(:render)
- view_paths.find_template(layout.to_s =~ /layouts\// ? layout : "layouts/#{layout}", *formats)
- rescue ActionView::MissingTemplate
- nil
- end
-
private
def inherited_with_layout(child)
inherited_without_layout(child)
@@ -212,35 +199,29 @@ def normalize_conditions(conditions)
# object). If the layout was defined without a directory, layouts is assumed. So <tt>layout "weblog/standard"</tt> will return
# weblog/standard, but <tt>layout "standard"</tt> will return layouts/standard.
def active_layout(passed_layout = nil)
- layout = passed_layout || self.class.default_layout(default_template_format)
+ layout = passed_layout || default_layout
+ return layout if layout.respond_to?(:render)
active_layout = case layout
when Symbol then __send__(layout)
when Proc then layout.call(self)
else layout
end
-
- if active_layout
- if layout = self.class.find_layout(active_layout, @template.template_format)
- layout
- else
- raise ActionView::MissingTemplate.new(self.class.view_paths, active_layout)
- end
- end
+
+ find_layout(active_layout, @template.template_format) if active_layout
end
private
- def candidate_for_layout?(options)
- template = options[:template] || default_template(options[:action])
- if options.values_at(:text, :xml, :json, :file, :inline, :partial, :nothing, :update).compact.empty?
- begin
- !self.view_paths.find_template(template, default_template_format).exempt_from_layout?
- rescue ActionView::MissingTemplate
- true
- end
- end
+ def default_layout #:nodoc:
+ layout = self.class.read_inheritable_attribute(:layout) unless default_template_format == :js
+ return layout unless self.class.read_inheritable_attribute(:auto_layout)
+ find_layout(layout, default_template_format)
rescue ActionView::MissingTemplate
- false
+ nil
+ end
+
+ def find_layout(layout, *formats) #:nodoc:
+ view_paths.find_template(layout.to_s =~ /layouts\// ? layout : "layouts/#{layout}", *formats)
end
def pick_layout(options)
@@ -273,6 +254,19 @@ def action_has_layout?
end
end
+ def candidate_for_layout?(options)
+ template = options[:template] || default_template(options[:action])
+ if options.values_at(:text, :xml, :json, :file, :inline, :partial, :nothing, :update).compact.empty?
+ begin
+ !self.view_paths.find_template(template, default_template_format).exempt_from_layout?
+ rescue ActionView::MissingTemplate
+ true
+ end
+ end
+ rescue ActionView::MissingTemplate
+ false
+ end
+
def default_template_format
response.template.template_format
end
@@ -27,7 +27,9 @@ def initialize(klass, *args, &block)
end
def klass
- if @klass.is_a?(Class)
+ if @klass.respond_to?(:call)
+ @klass.call
+ elsif @klass.is_a?(Class)
@klass
else
@klass.to_s.constantize
@@ -37,6 +39,8 @@ def klass
end
def active?
+ return false unless klass
+
if @conditional.respond_to?(:call)
@conditional.call
else
@@ -63,11 +67,17 @@ def inspect
def build(app)
if block
- klass.new(app, *args, &block)
+ klass.new(app, *build_args, &block)
else
- klass.new(app, *args)
+ klass.new(app, *build_args)
end
end
+
+ private
+
+ def build_args
+ Array(args).map { |arg| arg.respond_to?(:call) ? arg.call : arg }
+ end
end
def initialize(*args, &block)
@@ -4,17 +4,8 @@
use "ActionController::Failsafe"
-["ActionController::Session::CookieStore",
- "ActionController::Session::MemCacheStore",
- "ActiveRecord::SessionStore"].each do |store|
- use(store, ActionController::Base.session_options,
- :if => lambda {
- if session_store = ActionController::Base.session_store
- session_store.name == store
- end
- }
- )
-end
+use lambda { ActionController::Base.session_store },
+ lambda { ActionController::Base.session_options }
use "ActionController::RewindableInput"
use "ActionController::ParamsParser"
@@ -0,0 +1,14 @@
+module ActionController
+ class Reloader
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ Dispatcher.reload_application
+ @app.call(env)
+ ensure
+ Dispatcher.cleanup_application
+ end
+ end
+end
@@ -191,23 +191,19 @@ def value_regexp
end
def regexp_chunk
- if regexp
- if regexp_has_modifiers?
- "(#{regexp.to_s})"
- else
- "(#{regexp.source})"
- end
- else
- "([^#{Routing::SEPARATORS.join}]+)"
- end
+ regexp ? regexp_string : default_regexp_chunk
+ end
+
+ def regexp_string
+ regexp_has_modifiers? ? "(#{regexp.to_s})" : "(#{regexp.source})"
+ end
+
+ def default_regexp_chunk
+ "([^#{Routing::SEPARATORS.join}]+)"
end
def number_of_captures
- if regexp
- regexp.number_of_captures + 1
- else
- 1
- end
+ regexp ? regexp.number_of_captures + 1 : 1
end
def build_pattern(pattern)
@@ -244,10 +240,6 @@ def regexp_chunk
"(?i-:(#{(regexp || Regexp.union(*possible_names)).source}))"
end
- def number_of_captures
- 1
- end
-
# Don't URI.escape the controller name since it may contain slashes.
def interpolation_chunk(value_code = local_name)
"\#{#{value_code}.to_s}"
@@ -289,8 +281,8 @@ def match_extraction(next_capture)
"params[:#{key}] = PathSegment::Result.new_escaped((match[#{next_capture}]#{" || " + default.inspect if default}).split('/'))#{" if match[" + next_capture + "]" if !default}"
end
- def regexp_chunk
- regexp || "(.*)"
+ def default_regexp_chunk
+ "(.*)"
end
def number_of_captures
@@ -254,8 +254,8 @@ def render(options = {}, local_assigns = {}, &block) #:nodoc:
if options[:layout]
_render_with_layout(options, local_assigns, &block)
elsif options[:file]
- tempalte = self.view_paths.find_template(options[:file], template_format)
- tempalte.render_template(self, options[:locals])
+ template = self.view_paths.find_template(options[:file], template_format)
+ template.render_template(self, options[:locals])
elsif options[:partial]
render_partial(options)
elsif options[:inline]
Oops, something went wrong.

0 comments on commit 21b80f8

Please sign in to comment.