aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-08-07 13:27:36 -0300
committerEmilio Tagua <miloops@gmail.com>2009-08-07 13:27:36 -0300
commit04abe538ac80b8d82658acaa3de5ef6c961d3e39 (patch)
tree7c82eb9267eb2a0987e83a45bb84f61378a981b3
parent945ef58533e93d0abbf7ccdb3768e8654cbe6370 (diff)
parentbfe58ac05d4b7ba5d5c04c3aa9a719e340b2111e (diff)
downloadrails-04abe538ac80b8d82658acaa3de5ef6c961d3e39.tar.gz
rails-04abe538ac80b8d82658acaa3de5ef6c961d3e39.tar.bz2
rails-04abe538ac80b8d82658acaa3de5ef6c961d3e39.zip
Merge commit 'rails/master'
-rw-r--r--actionmailer/lib/action_mailer/base.rb4
-rw-r--r--actionmailer/test/mail_service_test.rb10
-rw-r--r--actionpack/examples/minimal.rb8
-rw-r--r--actionpack/examples/very_simple.rb6
-rw-r--r--actionpack/lib/abstract_controller.rb16
-rw-r--r--actionpack/lib/abstract_controller/base.rb (renamed from actionpack/lib/action_controller/abstract/base.rb)2
-rw-r--r--actionpack/lib/abstract_controller/benchmarker.rb (renamed from actionpack/lib/action_controller/abstract/benchmarker.rb)0
-rw-r--r--actionpack/lib/abstract_controller/callbacks.rb (renamed from actionpack/lib/action_controller/abstract/callbacks.rb)0
-rw-r--r--actionpack/lib/abstract_controller/exceptions.rb (renamed from actionpack/lib/action_controller/abstract/exceptions.rb)0
-rw-r--r--actionpack/lib/abstract_controller/helpers.rb (renamed from actionpack/lib/action_controller/abstract/helpers.rb)0
-rw-r--r--actionpack/lib/abstract_controller/layouts.rb (renamed from actionpack/lib/action_controller/abstract/layouts.rb)16
-rw-r--r--actionpack/lib/abstract_controller/logger.rb (renamed from actionpack/lib/action_controller/abstract/logger.rb)0
-rw-r--r--actionpack/lib/abstract_controller/renderer.rb (renamed from actionpack/lib/action_controller/abstract/renderer.rb)16
-rw-r--r--actionpack/lib/action_controller.rb74
-rw-r--r--actionpack/lib/action_controller/abstract.rb16
-rw-r--r--actionpack/lib/action_controller/base.rb (renamed from actionpack/lib/action_controller/base/base.rb)2
-rw-r--r--actionpack/lib/action_controller/caching/actions.rb3
-rw-r--r--actionpack/lib/action_controller/metal.rb (renamed from actionpack/lib/action_controller/base/http.rb)12
-rw-r--r--actionpack/lib/action_controller/metal/compatibility.rb (renamed from actionpack/lib/action_controller/base/compatibility.rb)4
-rw-r--r--actionpack/lib/action_controller/metal/conditional_get.rb (renamed from actionpack/lib/action_controller/base/conditional_get.rb)0
-rw-r--r--actionpack/lib/action_controller/metal/cookies.rb (renamed from actionpack/lib/action_controller/base/cookies.rb)0
-rw-r--r--actionpack/lib/action_controller/metal/exceptions.rb (renamed from actionpack/lib/action_controller/base/exceptions.rb)0
-rw-r--r--actionpack/lib/action_controller/metal/filter_parameter_logging.rb (renamed from actionpack/lib/action_controller/base/filter_parameter_logging.rb)0
-rw-r--r--actionpack/lib/action_controller/metal/flash.rb (renamed from actionpack/lib/action_controller/base/flash.rb)0
-rw-r--r--actionpack/lib/action_controller/metal/helpers.rb (renamed from actionpack/lib/action_controller/base/helpers.rb)0
-rw-r--r--actionpack/lib/action_controller/metal/hide_actions.rb (renamed from actionpack/lib/action_controller/base/hide_actions.rb)0
-rw-r--r--actionpack/lib/action_controller/metal/http_authentication.rb (renamed from actionpack/lib/action_controller/base/http_authentication.rb)0
-rw-r--r--actionpack/lib/action_controller/metal/layouts.rb (renamed from actionpack/lib/action_controller/base/layouts.rb)0
-rw-r--r--actionpack/lib/action_controller/metal/mime_responds.rb (renamed from actionpack/lib/action_controller/base/mime_responds.rb)0
-rw-r--r--actionpack/lib/action_controller/metal/rack_convenience.rb (renamed from actionpack/lib/action_controller/base/rack_convenience.rb)2
-rw-r--r--actionpack/lib/action_controller/metal/redirector.rb (renamed from actionpack/lib/action_controller/base/redirector.rb)0
-rw-r--r--actionpack/lib/action_controller/metal/render_options.rb (renamed from actionpack/lib/action_controller/base/render_options.rb)14
-rw-r--r--actionpack/lib/action_controller/metal/renderer.rb (renamed from actionpack/lib/action_controller/base/renderer.rb)15
-rw-r--r--actionpack/lib/action_controller/metal/request_forgery_protection.rb (renamed from actionpack/lib/action_controller/base/request_forgery_protection.rb)0
-rw-r--r--actionpack/lib/action_controller/metal/rescuable.rb (renamed from actionpack/lib/action_controller/base/rescuable.rb)0
-rw-r--r--actionpack/lib/action_controller/metal/session.rb (renamed from actionpack/lib/action_controller/base/session.rb)0
-rw-r--r--actionpack/lib/action_controller/metal/session_management.rb (renamed from actionpack/lib/action_controller/base/session_management.rb)0
-rw-r--r--actionpack/lib/action_controller/metal/streaming.rb (renamed from actionpack/lib/action_controller/base/streaming.rb)0
-rw-r--r--actionpack/lib/action_controller/metal/testing.rb (renamed from actionpack/lib/action_controller/base/testing.rb)0
-rw-r--r--actionpack/lib/action_controller/metal/url_for.rb (renamed from actionpack/lib/action_controller/base/url_for.rb)0
-rw-r--r--actionpack/lib/action_controller/metal/verification.rb (renamed from actionpack/lib/action_controller/base/verification.rb)0
-rw-r--r--actionpack/lib/action_controller/old_base.rb84
-rw-r--r--actionpack/lib/action_controller/record_identifier.rb15
-rw-r--r--actionpack/lib/action_view/context.rb4
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb4
-rw-r--r--actionpack/lib/action_view/render/partials.rb142
-rw-r--r--actionpack/lib/action_view/render/rendering.rb104
-rw-r--r--actionpack/lib/action_view/test_case.rb6
-rw-r--r--actionpack/test/abstract_controller/test_helper.rb2
-rw-r--r--actionpack/test/abstract_unit.rb3
-rw-r--r--actionpack/test/controller/logging_test.rb3
-rw-r--r--actionpack/test/controller/record_identifier_test.rb57
-rw-r--r--actionpack/test/controller/render_test.rb3
53 files changed, 241 insertions, 406 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index b5a0d0ab96..7b03a7f9ff 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -566,7 +566,7 @@ module ActionMailer #:nodoc:
@template = initialize_template_class(body)
layout = _pick_layout(layout, true) unless
ActionController::Base.exempt_from_layout.include?(template.handler)
- @template._render_template_with_layout(template, layout, {})
+ @template._render_template(template, layout, {})
ensure
@current_template_content_type = nil
end
@@ -592,7 +592,7 @@ module ActionMailer #:nodoc:
!template || ActionController::Base.exempt_from_layout.include?(template.handler))
if template
- @template._render_template_with_layout(template, layout, opts)
+ @template._render_template(template, layout, opts)
elsif inline = opts[:inline]
@template._render_inline(inline, layout, opts)
end
diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb
index 30d1b836c4..f2a8c2303c 100644
--- a/actionmailer/test/mail_service_test.rb
+++ b/actionmailer/test/mail_service_test.rb
@@ -573,12 +573,14 @@ class ActionMailerTest < Test::Unit::TestCase
@info_contents, @debug_contents = "", ""
end
- def info(str)
- @info_contents << str
+ def info(str = nil, &blk)
+ @info_contents << str if str
+ @info_contents << blk.call if block_given?
end
- def debug(str)
- @debug_contents << str
+ def debug(str = nil, &blk)
+ @debug_contents << str if str
+ @debug_contents << blk.call if block_given?
end
end
diff --git a/actionpack/examples/minimal.rb b/actionpack/examples/minimal.rb
index 9eb92cd8e7..7106149fa2 100644
--- a/actionpack/examples/minimal.rb
+++ b/actionpack/examples/minimal.rb
@@ -45,11 +45,9 @@ end
OK = [200, {}, []]
MetalPostController = lambda { OK }
-if ActionController.const_defined?(:Http)
- class HttpPostController < ActionController::Http
- def index
- self.response_body = ''
- end
+class HttpPostController < ActionController::Metal
+ def index
+ self.response_body = ''
end
end
diff --git a/actionpack/examples/very_simple.rb b/actionpack/examples/very_simple.rb
index 8d01cb39bd..422c4c3298 100644
--- a/actionpack/examples/very_simple.rb
+++ b/actionpack/examples/very_simple.rb
@@ -3,7 +3,7 @@ $:.push "rails/actionpack/lib"
require "action_controller"
-class Kaigi < ActionController::Http
+class Kaigi < ActionController::Metal
include AbstractController::Callbacks
include ActionController::RackConvenience
include ActionController::Renderer
@@ -13,7 +13,7 @@ class Kaigi < ActionController::Http
before_filter :set_name
append_view_path "views"
- def _action_view
+ def view_context
self
end
@@ -23,7 +23,7 @@ class Kaigi < ActionController::Http
DEFAULT_LAYOUT = Object.new.tap {|l| def l.render(*) yield end }
- def _render_template_from_controller(template, layout = DEFAULT_LAYOUT, options = {}, partial = false)
+ def render_template(template, layout = DEFAULT_LAYOUT, options = {}, partial = false)
ret = template.render(self, {})
layout.render(self, {}) { ret }
end
diff --git a/actionpack/lib/abstract_controller.rb b/actionpack/lib/abstract_controller.rb
new file mode 100644
index 0000000000..f020abaa45
--- /dev/null
+++ b/actionpack/lib/abstract_controller.rb
@@ -0,0 +1,16 @@
+require "active_support/core_ext/module/attr_internal"
+require "active_support/core_ext/module/delegation"
+
+module AbstractController
+ autoload :Base, "abstract_controller/base"
+ autoload :Benchmarker, "abstract_controller/benchmarker"
+ autoload :Callbacks, "abstract_controller/callbacks"
+ autoload :Helpers, "abstract_controller/helpers"
+ autoload :Layouts, "abstract_controller/layouts"
+ autoload :Logger, "abstract_controller/logger"
+ autoload :Renderer, "abstract_controller/renderer"
+ # === Exceptions
+ autoload :ActionNotFound, "abstract_controller/exceptions"
+ autoload :DoubleRenderError, "abstract_controller/exceptions"
+ autoload :Error, "abstract_controller/exceptions"
+end
diff --git a/actionpack/lib/action_controller/abstract/base.rb b/actionpack/lib/abstract_controller/base.rb
index ca00e66349..b93e6ce634 100644
--- a/actionpack/lib/action_controller/abstract/base.rb
+++ b/actionpack/lib/abstract_controller/base.rb
@@ -30,7 +30,7 @@ module AbstractController
# instance methods on that abstract class. Public instance methods of
# a controller would normally be considered action methods, so we
# are removing those methods on classes declared as abstract
- # (ActionController::Http and ActionController::Base are defined
+ # (ActionController::Metal and ActionController::Base are defined
# as abstract)
def internal_methods
controller = self
diff --git a/actionpack/lib/action_controller/abstract/benchmarker.rb b/actionpack/lib/abstract_controller/benchmarker.rb
index 58e9564c2f..58e9564c2f 100644
--- a/actionpack/lib/action_controller/abstract/benchmarker.rb
+++ b/actionpack/lib/abstract_controller/benchmarker.rb
diff --git a/actionpack/lib/action_controller/abstract/callbacks.rb b/actionpack/lib/abstract_controller/callbacks.rb
index ea4b59466e..ea4b59466e 100644
--- a/actionpack/lib/action_controller/abstract/callbacks.rb
+++ b/actionpack/lib/abstract_controller/callbacks.rb
diff --git a/actionpack/lib/action_controller/abstract/exceptions.rb b/actionpack/lib/abstract_controller/exceptions.rb
index b671516de1..b671516de1 100644
--- a/actionpack/lib/action_controller/abstract/exceptions.rb
+++ b/actionpack/lib/abstract_controller/exceptions.rb
diff --git a/actionpack/lib/action_controller/abstract/helpers.rb b/actionpack/lib/abstract_controller/helpers.rb
index 5efa37fde3..5efa37fde3 100644
--- a/actionpack/lib/action_controller/abstract/helpers.rb
+++ b/actionpack/lib/abstract_controller/helpers.rb
diff --git a/actionpack/lib/action_controller/abstract/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb
index f021dd8b62..038598a3b3 100644
--- a/actionpack/lib/action_controller/abstract/layouts.rb
+++ b/actionpack/lib/abstract_controller/layouts.rb
@@ -88,6 +88,22 @@ module AbstractController
end
end
+ def render_to_body(options = {})
+ response = super
+
+ if options.key?(:partial)
+ # This is a little bit messy. We need to explicitly handle partial
+ # layouts here since the core lookup logic is in the view, but
+ # we need to determine the layout based on the controller
+ if options.key?(:layout)
+ layout = _layout_for_option(options[:layout], options[:_template].details)
+ response = layout.render(view_context, options[:locals]) { response }
+ end
+ end
+
+ response
+ end
+
private
# This will be overwritten by _write_layout_method
def _layout(details) end
diff --git a/actionpack/lib/action_controller/abstract/logger.rb b/actionpack/lib/abstract_controller/logger.rb
index fd33bd2ddd..fd33bd2ddd 100644
--- a/actionpack/lib/action_controller/abstract/logger.rb
+++ b/actionpack/lib/abstract_controller/logger.rb
diff --git a/actionpack/lib/action_controller/abstract/renderer.rb b/actionpack/lib/abstract_controller/renderer.rb
index 41b7d47458..da57d0ff4d 100644
--- a/actionpack/lib/action_controller/abstract/renderer.rb
+++ b/actionpack/lib/abstract_controller/renderer.rb
@@ -1,4 +1,4 @@
-require "action_controller/abstract/logger"
+require "abstract_controller/logger"
module AbstractController
module Renderer
@@ -19,11 +19,11 @@ module AbstractController
# The view class must have the following methods:
# View.for_controller[controller] Create a new ActionView instance for a
# controller
- # View#_render_partial_from_controller[options]
+ # View#render_partial[options]
# - responsible for setting options[:_template]
# - Returns String with the rendered partial
# options<Hash>:: see _render_partial in ActionView::Base
- # View#_render_template_from_controller[template, layout, options, partial]
+ # View#render_template[template, layout, options, partial]
# - Returns String with the rendered template
# template<ActionView::Template>:: The template to render
# layout<ActionView::Template>:: The layout to render around the template
@@ -31,8 +31,8 @@ module AbstractController
# partial<Boolean>:: Whether or not the template to render is a partial
#
# Override this method in a to change the default behavior.
- def _action_view
- @_action_view ||= ActionView::Base.for_controller(self)
+ def view_context
+ @_view_context ||= ActionView::Base.for_controller(self)
end
# Mostly abstracts the fact that calling render twice is a DoubleRenderError.
@@ -54,8 +54,8 @@ module AbstractController
# :api: plugin
def render_to_body(options = {})
# TODO: Refactor so we can just use the normal template logic for this
- if options[:_partial_object]
- _action_view._render_partial_from_controller(options)
+ if options.key?(:partial)
+ view_context.render_partial(options)
else
_determine_template(options)
_render_template(options)
@@ -77,7 +77,7 @@ module AbstractController
# _layout<ActionView::Template>:: The layout to wrap the template in (optional)
# _partial<TrueClass, FalseClass>:: Whether or not the template to be rendered is a partial
def _render_template(options)
- _action_view._render_template_from_controller(options[:_template], options[:_layout], options, options[:_partial])
+ view_context.render_template(options)
end
# The list of view paths for this controller. See ActionView::ViewPathSet for
diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb
index 32572c93c0..22c2c4f499 100644
--- a/actionpack/lib/action_controller.rb
+++ b/actionpack/lib/action_controller.rb
@@ -1,62 +1,62 @@
module ActionController
- autoload :Base, "action_controller/base/base"
- autoload :ConditionalGet, "action_controller/base/conditional_get"
- autoload :HideActions, "action_controller/base/hide_actions"
- autoload :Http, "action_controller/base/http"
- autoload :Layouts, "action_controller/base/layouts"
- autoload :RackConvenience, "action_controller/base/rack_convenience"
- autoload :Rails2Compatibility, "action_controller/base/compatibility"
- autoload :Redirector, "action_controller/base/redirector"
- autoload :Renderer, "action_controller/base/renderer"
- autoload :RenderOptions, "action_controller/base/render_options"
- autoload :Renderers, "action_controller/base/render_options"
- autoload :Rescue, "action_controller/base/rescuable"
- autoload :Testing, "action_controller/base/testing"
- autoload :UrlFor, "action_controller/base/url_for"
- autoload :Session, "action_controller/base/session"
- autoload :Helpers, "action_controller/base/helpers"
+ autoload :Base, "action_controller/base"
+ autoload :ConditionalGet, "action_controller/metal/conditional_get"
+ autoload :HideActions, "action_controller/metal/hide_actions"
+ autoload :Metal, "action_controller/metal"
+ autoload :Layouts, "action_controller/metal/layouts"
+ autoload :RackConvenience, "action_controller/metal/rack_convenience"
+ autoload :Rails2Compatibility, "action_controller/metal/compatibility"
+ autoload :Redirector, "action_controller/metal/redirector"
+ autoload :Renderer, "action_controller/metal/renderer"
+ autoload :RenderOptions, "action_controller/metal/render_options"
+ autoload :Renderers, "action_controller/metal/render_options"
+ autoload :Rescue, "action_controller/metal/rescuable"
+ autoload :Testing, "action_controller/metal/testing"
+ autoload :UrlFor, "action_controller/metal/url_for"
+ autoload :Session, "action_controller/metal/session"
+ autoload :Helpers, "action_controller/metal/helpers"
# Ported modules
# require 'action_controller/routing'
autoload :Caching, 'action_controller/caching'
autoload :Dispatcher, 'action_controller/dispatch/dispatcher'
autoload :Integration, 'action_controller/testing/integration'
- autoload :MimeResponds, 'action_controller/base/mime_responds'
+ autoload :MimeResponds, 'action_controller/metal/mime_responds'
autoload :PolymorphicRoutes, 'action_controller/routing/generation/polymorphic_routes'
autoload :RecordIdentifier, 'action_controller/record_identifier'
autoload :Resources, 'action_controller/routing/resources'
- autoload :SessionManagement, 'action_controller/base/session_management'
+ autoload :SessionManagement, 'action_controller/metal/session_management'
autoload :TestCase, 'action_controller/testing/test_case'
autoload :TestProcess, 'action_controller/testing/process'
autoload :UrlRewriter, 'action_controller/routing/generation/url_rewriter'
autoload :UrlWriter, 'action_controller/routing/generation/url_rewriter'
- autoload :Verification, 'action_controller/base/verification'
- autoload :Flash, 'action_controller/base/flash'
- autoload :RequestForgeryProtection, 'action_controller/base/request_forgery_protection'
- autoload :Streaming, 'action_controller/base/streaming'
- autoload :HttpAuthentication, 'action_controller/base/http_authentication'
- autoload :FilterParameterLogging, 'action_controller/base/filter_parameter_logging'
+ autoload :Verification, 'action_controller/metal/verification'
+ autoload :Flash, 'action_controller/metal/flash'
+ autoload :RequestForgeryProtection, 'action_controller/metal/request_forgery_protection'
+ autoload :Streaming, 'action_controller/metal/streaming'
+ autoload :HttpAuthentication, 'action_controller/metal/http_authentication'
+ autoload :FilterParameterLogging, 'action_controller/metal/filter_parameter_logging'
autoload :Translation, 'action_controller/translation'
- autoload :Cookies, 'action_controller/base/cookies'
+ autoload :Cookies, 'action_controller/metal/cookies'
- autoload :ActionControllerError, 'action_controller/base/exceptions'
- autoload :SessionRestoreError, 'action_controller/base/exceptions'
- autoload :RenderError, 'action_controller/base/exceptions'
- autoload :RoutingError, 'action_controller/base/exceptions'
- autoload :MethodNotAllowed, 'action_controller/base/exceptions'
- autoload :NotImplemented, 'action_controller/base/exceptions'
- autoload :UnknownController, 'action_controller/base/exceptions'
- autoload :MissingFile, 'action_controller/base/exceptions'
- autoload :RenderError, 'action_controller/base/exceptions'
- autoload :SessionOverflowError, 'action_controller/base/exceptions'
- autoload :UnknownHttpMethod, 'action_controller/base/exceptions'
+ autoload :ActionControllerError, 'action_controller/metal/exceptions'
+ autoload :SessionRestoreError, 'action_controller/metal/exceptions'
+ autoload :RenderError, 'action_controller/metal/exceptions'
+ autoload :RoutingError, 'action_controller/metal/exceptions'
+ autoload :MethodNotAllowed, 'action_controller/metal/exceptions'
+ autoload :NotImplemented, 'action_controller/metal/exceptions'
+ autoload :UnknownController, 'action_controller/metal/exceptions'
+ autoload :MissingFile, 'action_controller/metal/exceptions'
+ autoload :RenderError, 'action_controller/metal/exceptions'
+ autoload :SessionOverflowError, 'action_controller/metal/exceptions'
+ autoload :UnknownHttpMethod, 'action_controller/metal/exceptions'
autoload :Routing, 'action_controller/routing'
end
autoload :HTML, 'action_controller/vendor/html-scanner'
-autoload :AbstractController, 'action_controller/abstract'
+autoload :AbstractController, 'abstract_controller'
autoload :Rack, 'action_dispatch'
autoload :ActionDispatch, 'action_dispatch'
diff --git a/actionpack/lib/action_controller/abstract.rb b/actionpack/lib/action_controller/abstract.rb
deleted file mode 100644
index d0eba253b8..0000000000
--- a/actionpack/lib/action_controller/abstract.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-require "active_support/core_ext/module/attr_internal"
-require "active_support/core_ext/module/delegation"
-
-module AbstractController
- autoload :Base, "action_controller/abstract/base"
- autoload :Benchmarker, "action_controller/abstract/benchmarker"
- autoload :Callbacks, "action_controller/abstract/callbacks"
- autoload :Helpers, "action_controller/abstract/helpers"
- autoload :Layouts, "action_controller/abstract/layouts"
- autoload :Logger, "action_controller/abstract/logger"
- autoload :Renderer, "action_controller/abstract/renderer"
- # === Exceptions
- autoload :ActionNotFound, "action_controller/abstract/exceptions"
- autoload :DoubleRenderError, "action_controller/abstract/exceptions"
- autoload :Error, "action_controller/abstract/exceptions"
-end
diff --git a/actionpack/lib/action_controller/base/base.rb b/actionpack/lib/action_controller/base.rb
index e541d24e31..9d9f735e27 100644
--- a/actionpack/lib/action_controller/base/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -1,5 +1,5 @@
module ActionController
- class Base < Http
+ class Base < Metal
abstract!
include AbstractController::Benchmarker
diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb
index d8a1662acc..cb0c3a1384 100644
--- a/actionpack/lib/action_controller/caching/actions.rb
+++ b/actionpack/lib/action_controller/caching/actions.rb
@@ -129,8 +129,7 @@ module ActionController #:nodoc:
end
def content_for_layout(controller)
- # TODO: Remove this when new base is merged in
- template = controller.respond_to?(:template) ? controller.template : controller._action_view
+ template = controller.view_context
template.layout && template.instance_variable_get('@cached_content_for_layout')
end
end
diff --git a/actionpack/lib/action_controller/base/http.rb b/actionpack/lib/action_controller/metal.rb
index 3efd1b656f..5333ca497c 100644
--- a/actionpack/lib/action_controller/base/http.rb
+++ b/actionpack/lib/action_controller/metal.rb
@@ -1,13 +1,11 @@
-require 'action_controller/abstract'
-
module ActionController
- # ActionController::Http provides a way to get a valid Rack application from a controller.
+ # ActionController::Metal provides a way to get a valid Rack application from a controller.
#
# In AbstractController, dispatching is triggered directly by calling #process on a new controller.
- # ActionController::Http provides an #action method that returns a valid Rack application for a
+ # 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,
# can dispatch directly to the action returned by FooController.action(:index).
- class Http < AbstractController::Base
+ class Metal < AbstractController::Base
abstract!
# :api: public
@@ -72,11 +70,11 @@ module ActionController
def call(name, env)
@_env = env
process(name)
- to_rack
+ to_a
end
# :api: private
- def to_rack
+ def to_a
[status, headers, response_body]
end
diff --git a/actionpack/lib/action_controller/base/compatibility.rb b/actionpack/lib/action_controller/metal/compatibility.rb
index 13813ffd17..23e7b1b3af 100644
--- a/actionpack/lib/action_controller/base/compatibility.rb
+++ b/actionpack/lib/action_controller/metal/compatibility.rb
@@ -72,7 +72,7 @@ module ActionController
# TODO: Remove this after we flip
def template
- @template ||= _action_view
+ @template ||= view_context
end
def process_action(*)
@@ -141,7 +141,7 @@ module ActionController
end
def view_paths
- _action_view.view_paths
+ view_context.view_paths
end
end
end
diff --git a/actionpack/lib/action_controller/base/conditional_get.rb b/actionpack/lib/action_controller/metal/conditional_get.rb
index 6d35137428..6d35137428 100644
--- a/actionpack/lib/action_controller/base/conditional_get.rb
+++ b/actionpack/lib/action_controller/metal/conditional_get.rb
diff --git a/actionpack/lib/action_controller/base/cookies.rb b/actionpack/lib/action_controller/metal/cookies.rb
index d4806623c3..d4806623c3 100644
--- a/actionpack/lib/action_controller/base/cookies.rb
+++ b/actionpack/lib/action_controller/metal/cookies.rb
diff --git a/actionpack/lib/action_controller/base/exceptions.rb b/actionpack/lib/action_controller/metal/exceptions.rb
index d0811254cb..d0811254cb 100644
--- a/actionpack/lib/action_controller/base/exceptions.rb
+++ b/actionpack/lib/action_controller/metal/exceptions.rb
diff --git a/actionpack/lib/action_controller/base/filter_parameter_logging.rb b/actionpack/lib/action_controller/metal/filter_parameter_logging.rb
index 065e62a37f..065e62a37f 100644
--- a/actionpack/lib/action_controller/base/filter_parameter_logging.rb
+++ b/actionpack/lib/action_controller/metal/filter_parameter_logging.rb
diff --git a/actionpack/lib/action_controller/base/flash.rb b/actionpack/lib/action_controller/metal/flash.rb
index 590f9be3ac..590f9be3ac 100644
--- a/actionpack/lib/action_controller/base/flash.rb
+++ b/actionpack/lib/action_controller/metal/flash.rb
diff --git a/actionpack/lib/action_controller/base/helpers.rb b/actionpack/lib/action_controller/metal/helpers.rb
index 7c52779064..7c52779064 100644
--- a/actionpack/lib/action_controller/base/helpers.rb
+++ b/actionpack/lib/action_controller/metal/helpers.rb
diff --git a/actionpack/lib/action_controller/base/hide_actions.rb b/actionpack/lib/action_controller/metal/hide_actions.rb
index af68c772b1..af68c772b1 100644
--- a/actionpack/lib/action_controller/base/hide_actions.rb
+++ b/actionpack/lib/action_controller/metal/hide_actions.rb
diff --git a/actionpack/lib/action_controller/base/http_authentication.rb b/actionpack/lib/action_controller/metal/http_authentication.rb
index 525787bf92..525787bf92 100644
--- a/actionpack/lib/action_controller/base/http_authentication.rb
+++ b/actionpack/lib/action_controller/metal/http_authentication.rb
diff --git a/actionpack/lib/action_controller/base/layouts.rb b/actionpack/lib/action_controller/metal/layouts.rb
index 365351b421..365351b421 100644
--- a/actionpack/lib/action_controller/base/layouts.rb
+++ b/actionpack/lib/action_controller/metal/layouts.rb
diff --git a/actionpack/lib/action_controller/base/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb
index f4a4007a43..f4a4007a43 100644
--- a/actionpack/lib/action_controller/base/mime_responds.rb
+++ b/actionpack/lib/action_controller/metal/mime_responds.rb
diff --git a/actionpack/lib/action_controller/base/rack_convenience.rb b/actionpack/lib/action_controller/metal/rack_convenience.rb
index 805157b0e3..5fac445dab 100644
--- a/actionpack/lib/action_controller/base/rack_convenience.rb
+++ b/actionpack/lib/action_controller/metal/rack_convenience.rb
@@ -20,7 +20,7 @@ module ActionController
end
# :api: private
- def to_rack
+ def to_a
@_response.prepare!
@_response.to_a
end
diff --git a/actionpack/lib/action_controller/base/redirector.rb b/actionpack/lib/action_controller/metal/redirector.rb
index 20060b001f..20060b001f 100644
--- a/actionpack/lib/action_controller/base/redirector.rb
+++ b/actionpack/lib/action_controller/metal/redirector.rb
diff --git a/actionpack/lib/action_controller/base/render_options.rb b/actionpack/lib/action_controller/metal/render_options.rb
index fc9a02626f..c6a965472f 100644
--- a/actionpack/lib/action_controller/base/render_options.rb
+++ b/actionpack/lib/action_controller/metal/render_options.rb
@@ -13,7 +13,7 @@ module ActionController
<<-RUBY_EVAL
if options.key?(:#{r})
_process_options(options)
- return _render_#{r}(options[:#{r}], options)
+ return render_#{r}(options[:#{r}], options)
end
RUBY_EVAL
end
@@ -52,7 +52,7 @@ module ActionController
extend RenderOption
register_renderer :json
- def _render_json(json, options)
+ def render_json(json, options)
json = ActiveSupport::JSON.encode(json) unless json.respond_to?(:to_str)
json = "#{options[:callback]}(#{json})" unless options[:callback].blank?
self.content_type ||= Mime::JSON
@@ -64,9 +64,9 @@ module ActionController
extend RenderOption
register_renderer :js
- def _render_js(js, options)
+ def render_js(js, options)
self.content_type ||= Mime::JS
- self.response_body = js
+ self.response_body = js.respond_to?(:to_js) ? js.to_js : js
end
end
@@ -74,7 +74,7 @@ module ActionController
extend RenderOption
register_renderer :xml
- def _render_xml(xml, options)
+ def render_xml(xml, options)
self.content_type ||= Mime::XML
self.response_body = xml.respond_to?(:to_xml) ? xml.to_xml : xml
end
@@ -84,8 +84,8 @@ module ActionController
extend RenderOption
register_renderer :update
- def _render_update(proc, options)
- generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(_action_view, &proc)
+ def render_update(proc, options)
+ generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(view_context, &proc)
self.content_type = Mime::JS
self.response_body = generator.to_s
end
diff --git a/actionpack/lib/action_controller/base/renderer.rb b/actionpack/lib/action_controller/metal/renderer.rb
index 572da451ff..31ba7e582a 100644
--- a/actionpack/lib/action_controller/base/renderer.rb
+++ b/actionpack/lib/action_controller/metal/renderer.rb
@@ -22,7 +22,8 @@ module ActionController
_process_options(options)
if options.key?(:partial)
- _render_partial(options[:partial], options)
+ options[:partial] = action_name if options[:partial] == true
+ options[:_details] = {:formats => formats}
end
super
@@ -53,18 +54,6 @@ module ActionController
end
def _render_partial(partial, options)
- case partial
- when true
- options[:_prefix] = _prefix
- when String
- options[:_prefix] = _prefix unless partial.index('/')
- options[:_template_name] = partial
- else
- options[:_partial_object] = true
- return
- end
-
- options[:_partial] = options[:object] || true
end
def _process_options(options)
diff --git a/actionpack/lib/action_controller/base/request_forgery_protection.rb b/actionpack/lib/action_controller/metal/request_forgery_protection.rb
index ad06657f86..ad06657f86 100644
--- a/actionpack/lib/action_controller/base/request_forgery_protection.rb
+++ b/actionpack/lib/action_controller/metal/request_forgery_protection.rb
diff --git a/actionpack/lib/action_controller/base/rescuable.rb b/actionpack/lib/action_controller/metal/rescuable.rb
index 029e643d93..029e643d93 100644
--- a/actionpack/lib/action_controller/base/rescuable.rb
+++ b/actionpack/lib/action_controller/metal/rescuable.rb
diff --git a/actionpack/lib/action_controller/base/session.rb b/actionpack/lib/action_controller/metal/session.rb
index bcedd6e1c7..bcedd6e1c7 100644
--- a/actionpack/lib/action_controller/base/session.rb
+++ b/actionpack/lib/action_controller/metal/session.rb
diff --git a/actionpack/lib/action_controller/base/session_management.rb b/actionpack/lib/action_controller/metal/session_management.rb
index ffce8e1bd1..ffce8e1bd1 100644
--- a/actionpack/lib/action_controller/base/session_management.rb
+++ b/actionpack/lib/action_controller/metal/session_management.rb
diff --git a/actionpack/lib/action_controller/base/streaming.rb b/actionpack/lib/action_controller/metal/streaming.rb
index f0317c6e99..f0317c6e99 100644
--- a/actionpack/lib/action_controller/base/streaming.rb
+++ b/actionpack/lib/action_controller/metal/streaming.rb
diff --git a/actionpack/lib/action_controller/base/testing.rb b/actionpack/lib/action_controller/metal/testing.rb
index a4a1116d9e..a4a1116d9e 100644
--- a/actionpack/lib/action_controller/base/testing.rb
+++ b/actionpack/lib/action_controller/metal/testing.rb
diff --git a/actionpack/lib/action_controller/base/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb
index 7119c14cd3..7119c14cd3 100644
--- a/actionpack/lib/action_controller/base/url_for.rb
+++ b/actionpack/lib/action_controller/metal/url_for.rb
diff --git a/actionpack/lib/action_controller/base/verification.rb b/actionpack/lib/action_controller/metal/verification.rb
index 951ae1bee1..951ae1bee1 100644
--- a/actionpack/lib/action_controller/base/verification.rb
+++ b/actionpack/lib/action_controller/metal/verification.rb
diff --git a/actionpack/lib/action_controller/old_base.rb b/actionpack/lib/action_controller/old_base.rb
deleted file mode 100644
index dd22bfd617..0000000000
--- a/actionpack/lib/action_controller/old_base.rb
+++ /dev/null
@@ -1,84 +0,0 @@
-#--
-# Copyright (c) 2004-2009 David Heinemeier Hansson
-#
-# Permission is hereby granted, free of charge, to any person obtaining
-# a copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sublicense, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice shall be
-# included in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#++
-
-activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
-$:.unshift activesupport_path if File.directory?(activesupport_path)
-require 'active_support'
-
-require File.join(File.dirname(__FILE__), "action_pack")
-
-module ActionController
- # TODO: Review explicit to see if they will automatically be handled by
- # the initilizer if they are really needed.
- def self.load_all!
- [Base, Request, Response, UrlRewriter, UrlWriter]
- [ActionDispatch::Http::Headers]
- end
-
- autoload :Base, 'action_controller/base/base'
- autoload :Benchmarking, 'action_controller/base/chained/benchmarking'
- autoload :Caching, 'action_controller/caching'
- autoload :Cookies, 'action_controller/base/cookies'
- autoload :Dispatcher, 'action_controller/dispatch/dispatcher'
- autoload :Filters, 'action_controller/base/chained/filters'
- autoload :Flash, 'action_controller/base/chained/flash'
- autoload :Helpers, 'action_controller/base/helpers'
- autoload :HttpAuthentication, 'action_controller/base/http_authentication'
- autoload :Integration, 'action_controller/testing/integration'
- autoload :IntegrationTest, 'action_controller/testing/integration'
- autoload :Layout, 'action_controller/base/layout'
- autoload :MimeResponds, 'action_controller/base/mime_responds'
- autoload :PolymorphicRoutes, 'action_controller/routing/generation/polymorphic_routes'
- autoload :RecordIdentifier, 'action_controller/record_identifier'
- autoload :Redirector, 'action_controller/base/redirect'
- autoload :Renderer, 'action_controller/base/render'
- autoload :RequestForgeryProtection, 'action_controller/base/request_forgery_protection'
- autoload :Rescue, 'action_controller/base/rescue'
- autoload :Resources, 'action_controller/routing/resources'
- autoload :Responder, 'action_controller/base/responder'
- autoload :Routing, 'action_controller/routing'
- autoload :SessionManagement, 'action_controller/base/session_management'
- autoload :Streaming, 'action_controller/base/streaming'
- autoload :TestCase, 'action_controller/testing/test_case'
- autoload :TestProcess, 'action_controller/testing/process'
- autoload :Translation, 'action_controller/translation'
- autoload :UrlEncodedPairParser, 'action_controller/dispatch/url_encoded_pair_parser'
- autoload :UrlRewriter, 'action_controller/routing/generation/url_rewriter'
- autoload :UrlWriter, 'action_controller/routing/generation/url_rewriter'
- autoload :Verification, 'action_controller/base/verification'
- autoload :FilterParameterLogging, 'action_controller/base/filter_parameter_logging'
-
- module Assertions
- autoload :DomAssertions, 'action_controller/testing/assertions/dom'
- autoload :ModelAssertions, 'action_controller/testing/assertions/model'
- autoload :ResponseAssertions, 'action_controller/testing/assertions/response'
- autoload :RoutingAssertions, 'action_controller/testing/assertions/routing'
- autoload :SelectorAssertions, 'action_controller/testing/assertions/selector'
- autoload :TagAssertions, 'action_controller/testing/assertions/tag'
- end
-end
-
-autoload :HTML, 'action_controller/vendor/html-scanner'
-
-require 'action_dispatch'
-require 'action_view'
diff --git a/actionpack/lib/action_controller/record_identifier.rb b/actionpack/lib/action_controller/record_identifier.rb
index b4408e4e1d..1165c3b7c5 100644
--- a/actionpack/lib/action_controller/record_identifier.rb
+++ b/actionpack/lib/action_controller/record_identifier.rb
@@ -36,21 +36,6 @@ module ActionController
JOIN = '_'.freeze
NEW = 'new'.freeze
- # Returns plural/singular for a record or class. Example:
- #
- # partial_path(post) # => "posts/post"
- # partial_path(Person) # => "people/person"
- # partial_path(Person, "admin/games") # => "admin/people/person"
- def partial_path(record_or_class, controller_path = nil)
- name = model_name_from_record_or_class(record_or_class)
-
- if controller_path && controller_path.include?("/")
- "#{File.dirname(controller_path)}/#{name.partial_path}"
- else
- name.partial_path
- end
- end
-
# The DOM class convention is to use the singular form of an object or class. Examples:
#
# dom_class(post) # => "post"
diff --git a/actionpack/lib/action_view/context.rb b/actionpack/lib/action_view/context.rb
index f212fe25eb..df078a7151 100644
--- a/actionpack/lib/action_view/context.rb
+++ b/actionpack/lib/action_view/context.rb
@@ -12,11 +12,11 @@ module ActionView
#
# Context.for_controller[controller] Create a new ActionView instance for a
# controller
- # Context#_render_partial_from_controller[options]
+ # Context#render_partial[options]
# - responsible for setting options[:_template]
# - Returns String with the rendered partial
# options<Hash>:: see _render_partial in ActionView::Base
- # Context#_render_template_from_controller[template, layout, options, partial]
+ # Context#render_template[template, layout, options, partial]
# - Returns String with the rendered template
# template<ActionView::Template>:: The template to render
# layout<ActionView::Template>:: The layout to render around the template
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index 2d1d19d5f3..6e2990e084 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -932,6 +932,10 @@ module ActionView
attr_accessor :object_name, :object, :options
+ def self.model_name
+ @model_name ||= Struct.new(:partial_path).new(name.demodulize.underscore.sub!(/_builder$/, ''))
+ end
+
def initialize(object_name, object, template, options, proc)
@nested_child_index = {}
@object_name, @object, @template, @options, @proc = object_name, object, template, options, proc
diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb
index ccb14d513a..48cba9c02b 100644
--- a/actionpack/lib/action_view/render/partials.rb
+++ b/actionpack/lib/action_view/render/partials.rb
@@ -172,131 +172,93 @@ module ActionView
module Partials
extend ActiveSupport::Memoizable
extend ActiveSupport::Concern
-
+
included do
- attr_accessor :_partial
+ attr_accessor :_partial
+ end
+
+ module ClassMethods
+ def _partial_names
+ @_partial_names ||= ActiveSupport::ConcurrentHash.new
+ end
end
- def _render_partial_from_controller(*args)
+ def render_partial(options)
@assigns_added = false
- _render_partial(*args)
+ # TODO: Handle other details here.
+ self.formats = options[:_details][:formats]
+ _render_partial(options)
end
- def _render_partial(options = {}) #:nodoc:
+ def _render_partial(options, &block) #:nodoc:
options[:locals] ||= {}
- case path = partial = options[:partial]
- when *_array_like_objects
- return _render_partial_collection(partial, options)
- else
- if partial.is_a?(ActionView::Helpers::FormBuilder)
- path = partial.class.to_s.demodulize.underscore.sub(/_builder$/, '')
- options[:locals].merge!(path.to_sym => partial)
- elsif !partial.is_a?(String)
- options[:object] = object = partial
- path = ActionController::RecordIdentifier.partial_path(object, controller_path)
- end
- _, _, prefix, object = parts = partial_parts(path, options)
- parts[1] = {:formats => parts[1]}
- template = find_by_parts(*parts)
- _render_partial_object(template, options, (object unless object == true))
+ path = partial = options[:partial]
+
+ if partial.respond_to?(:to_ary)
+ return _render_partial_collection(partial, options, &block)
+ elsif !partial.is_a?(String)
+ options[:object] = object = partial
+ path = _partial_path(object)
end
+
+ _render_partial_object(_pick_partial_template(path), options, &block)
end
private
- def partial_parts(name, options)
- segments = name.split("/")
- parts = segments.pop.split(".")
-
- case parts.size
- when 1
- parts
- when 2, 3
- extension = parts.delete_at(1).to_sym
- if formats.include?(extension)
- self.formats.replace [extension]
+ def _partial_path(object)
+ self.class._partial_names[[controller.class, object.class]] ||= begin
+ name = object.class.model_name
+ if controller_path && controller_path.include?("/")
+ File.join(File.dirname(controller_path), name.partial_path)
+ else
+ name.partial_path
end
- parts.pop if parts.size == 2
end
-
- path = parts.join(".")
- prefix = segments[0..-1].join("/")
- prefix = prefix.blank? ? controller_path : prefix
- parts = [path, formats, prefix]
- parts.push options[:object] || true
- end
-
- def _render_partial_with_block(layout, block, options)
- @_proc_for_layout = block
- concat(_render_partial(options.merge(:partial => layout)))
- ensure
- @_proc_for_layout = nil
end
- def _render_partial_with_layout(layout, options)
- if layout
- prefix = controller && !layout.include?("/") ? controller.controller_path : nil
- layout = find_by_parts(layout, {:formats => formats}, prefix, true)
- end
- content = _render_partial(options)
- return _render_content_with_layout(content, layout, options[:locals])
- end
+ def _render_partial_template(template, locals, object, options = {}, &block)
+ options[:_template] = template
+ locals[:object] = locals[template.variable_name] = object
+ locals[options[:as]] = object if options[:as]
- def _array_like_objects
- array_like = [Array]
- if defined?(ActiveRecord)
- array_like.push(ActiveRecord::Associations::AssociationCollection, ActiveRecord::NamedScope::Scope)
- end
- array_like
+ _render_single_template(template, locals, &block)
end
- def _render_partial_object(template, options, object = nil)
+ def _render_partial_object(template, options, &block)
if options.key?(:collection)
- _render_partial_collection(options.delete(:collection), options, template)
+ _render_partial_collection(options.delete(:collection), options, template, &block)
else
locals = (options[:locals] ||= {})
- object ||= locals[:object] || locals[template.variable_name]
-
- _set_locals(object, locals, template, options)
-
- options[:_template] = template
-
- _render_template(template, locals)
+ object = options[:object] || locals[:object] || locals[template.variable_name]
+
+ _render_partial_template(template, locals, object, options, &block)
end
end
- def _set_locals(object, locals, template, options)
- locals[:object] = locals[template.variable_name] = object
- locals[options[:as]] = object if options[:as]
- end
+ def _render_partial_collection(collection, options = {}, template = nil, &block) #:nodoc:
+ options[:_template] ||= template
- def _render_partial_collection(collection, options = {}, passed_template = nil) #:nodoc:
return nil if collection.blank?
-
- spacer = options[:spacer_template] ? _render_partial(:partial => options[:spacer_template]) : ''
- locals = (options[:locals] ||= {})
- index, @_partial_path = 0, nil
- collection.map do |object|
- options[:_template] = template = passed_template || begin
- _partial_path =
- ActionController::RecordIdentifier.partial_path(object, controller_path)
- template = _pick_partial_template(_partial_path)
- end
+ if options.key?(:spacer_template)
+ spacer = _render_partial(:partial => options[:spacer_template])
+ end
- _set_locals(object, locals, template, options)
- locals[template.counter_name] = index
-
+ locals, index = options[:locals] || {}, 0
+
+ collection.map do |object|
+ tmp = template || _pick_partial_template(_partial_path(object))
+ locals[tmp.counter_name] = index
index += 1
-
- _render_template(template, locals)
+
+ _render_partial_template(tmp, locals, object, options, &block)
end.join(spacer)
end
def _pick_partial_template(partial_path) #:nodoc:
- prefix = controller_path unless partial_path.include?('/')
+ prefix = controller_path unless partial_path.include?(?/)
find_by_parts(partial_path, {:formats => formats}, prefix, true)
end
- memoize :_pick_partial_template
end
end
diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb
index 162e38c484..9c25fab6bb 100644
--- a/actionpack/lib/action_view/render/rendering.rb
+++ b/actionpack/lib/action_view/render/rendering.rb
@@ -10,24 +10,25 @@ module ActionView
#
# If no options hash is passed or :update specified, the default is to render a partial and use the second parameter
# as the locals hash.
- def render(options = {}, local_assigns = {}, &block) #:nodoc:
- local_assigns ||= {}
-
- @exempt_from_layout = true
-
+ def render(options = {}, locals = {}, &block) #:nodoc:
case options
+ when String, NilClass
+ _render_partial(:partial => options, :locals => locals || {})
when Hash
- options[:locals] ||= {}
layout = options[:layout]
-
- return _render_partial_with_layout(layout, options) if options.key?(:partial)
- return _render_partial_with_block(layout, block, options) if block_given?
-
+
+ if block_given?
+ return concat(_render_partial(options.merge(:partial => layout), &block))
+ elsif options.key?(:partial)
+ layout = _pick_partial_template(layout) if layout
+ return _render_content(_render_partial(options), layout, options[:locals])
+ end
+
layout = find_by_parts(layout, {:formats => formats}) if layout
-
+
if file = options[:file]
template = find_by_parts(file, {:formats => formats})
- _render_template_with_layout(template, layout, :locals => options[:locals])
+ _render_template(template, layout, :locals => options[:locals] || {})
elsif inline = options[:inline]
_render_inline(inline, layout, options)
elsif text = options[:text]
@@ -35,35 +36,33 @@ module ActionView
end
when :update
update_page(&block)
- when String, NilClass
- _render_partial(:partial => options, :locals => local_assigns)
end
end
-
- def _render_content_with_layout(content, layout, locals)
+
+ def _render_content(content, layout, locals)
return content unless layout
-
+
locals ||= {}
if controller && layout
@_layout = layout.identifier
logger.info("Rendering template within #{layout.identifier}") if logger
end
-
+
begin
old_content, @_content_for[:layout] = @_content_for[:layout], content
@cached_content_for_layout = @_content_for[:layout]
- _render_template(layout, locals)
+ _render_single_template(layout, locals)
ensure
@_content_for[:layout] = old_content
end
end
- # You can think of a layout as a method that is called with a block. This method
- # returns the block that the layout is called with. If the user calls yield :some_name,
- # the block, by default, returns content_for(:some_name). If the user calls yield,
- # the default block returns content_for(:layout).
+ # You can think of a layout as a method that is called with a block. _layout_for
+ # returns the contents that are yielded to the layout. If the user calls yield
+ # :some_name, the block, by default, returns content_for(:some_name). If the user
+ # calls yield, the default block returns content_for(:layout).
#
# The user can override this default by passing a block to the layout.
#
@@ -92,15 +91,28 @@ module ActionView
# In this case, the layout would receive the block passed into <tt>render :layout</tt>,
# and the Struct specified in the layout would be passed into the block. The result
# would be <html>Hello David</html>.
- def layout_proc(name)
- @_default_layout ||= proc { |*names| @_content_for[names.first || :layout] }
- !@_content_for.key?(name) && @_proc_for_layout || @_default_layout
+ def _layout_for(names, &block)
+ with_output_buffer do
+ # This is due to the potentially ambiguous use of yield when
+ # a block is passed in to a template *and* there is a content_for()
+ # of the same name. Suggested solution: require explicit use of content_for
+ # in these ambiguous cases.
+ #
+ # We would be able to continue supporting yield in all non-ambiguous
+ # cases. Question: should we deprecate yield in favor of content_for
+ # and reserve yield for cases where there is a yield into a real block?
+ if @_content_for.key?(names.first) || !block_given?
+ return @_content_for[names.first || :layout]
+ else
+ return yield(names)
+ end
+ end
end
- def _render_template(template, local_assigns = {})
+ def _render_single_template(template, locals = {}, &block)
with_template(template) do
- template.render(self, local_assigns) do |*names|
- capture(*names, &layout_proc(names.first))
+ template.render(self, locals) do |*names|
+ _layout_for(names, &block)
end
end
rescue Exception => e
@@ -115,32 +127,42 @@ module ActionView
def _render_inline(inline, layout, options)
handler = Template.handler_class_for_extension(options[:type] || "erb")
template = Template.new(options[:inline], "inline #{options[:inline].inspect}", handler, {})
- content = _render_template(template, options[:locals] || {})
- layout ? _render_content_with_layout(content, layout, options[:locals]) : content
+ content = _render_single_template(template, options[:locals] || {})
+ layout ? _render_content(content, layout, options[:locals]) : content
end
def _render_text(text, layout, options)
- layout ? _render_content_with_layout(text, layout, options[:locals]) : text
+ layout ? _render_content(text, layout, options[:locals]) : text
end
- def _render_template_from_controller(*args)
+ # This is the API to render a ViewContext's template from a controller.
+ #
+ # Internal Options:
+ # _template:: The Template object to render
+ # _layout:: The layout, if any, to wrap the Template in
+ # _partial:: true if the template is a partial
+ def render_template(options)
@assigns_added = nil
- _render_template_with_layout(*args)
+ template, layout, partial = options.values_at(:_template, :_layout, :_partial)
+ _render_template(template, layout, options, partial)
end
- def _render_template_with_layout(template, layout = nil, options = {}, partial = false)
- logger && logger.info("Rendering #{template.identifier}#{' (#{options[:status]})' if options[:status]}")
+ def _render_template(template, layout = nil, options = {}, partial = nil)
+ logger && logger.info do
+ msg = "Rendering #{template.identifier}"
+ msg << " (#{options[:status]})" if options[:status]
+ msg
+ end
locals = options[:locals] || {}
content = if partial
- object = partial unless partial == true
- _render_partial_object(template, options, object)
+ _render_partial_object(template, options)
else
- _render_template(template, locals)
+ _render_single_template(template, locals)
end
-
- layout ? _render_content_with_layout(content, layout, locals) : content
+
+ _render_content(content, layout, locals)
end
end
end \ No newline at end of file
diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb
index 3f3951509a..e51744d095 100644
--- a/actionpack/lib/action_view/test_case.rb
+++ b/actionpack/lib/action_view/test_case.rb
@@ -9,14 +9,14 @@ module ActionView
end
attr_internal :rendered
- alias_method :_render_template_without_template_tracking, :_render_template
- def _render_template(template, local_assigns = {})
+ alias_method :_render_template_without_template_tracking, :_render_single_template
+ def _render_single_template(template, local_assigns, &block)
if template.respond_to?(:identifier) && template.present?
@_rendered[:partials][template] += 1 if template.partial?
@_rendered[:template] ||= []
@_rendered[:template] << template
end
- _render_template_without_template_tracking(template, local_assigns)
+ _render_template_without_template_tracking(template, local_assigns, &block)
end
end
diff --git a/actionpack/test/abstract_controller/test_helper.rb b/actionpack/test/abstract_controller/test_helper.rb
index 915054f7fb..ba4302d914 100644
--- a/actionpack/test/abstract_controller/test_helper.rb
+++ b/actionpack/test/abstract_controller/test_helper.rb
@@ -6,7 +6,7 @@ require 'rubygems'
require 'test/unit'
require 'active_support'
require 'active_support/test_case'
-require 'action_controller/abstract'
+require 'abstract_controller'
require 'action_view'
require 'action_view/base'
require 'action_dispatch'
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index 6e71b85645..b062a71442 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -13,7 +13,6 @@ require 'test/unit'
require 'active_support'
require 'active_support/test_case'
-require 'action_controller/abstract'
require 'action_controller'
require 'fixture_template'
require 'action_controller/testing/process'
@@ -78,7 +77,7 @@ module ActionController
def assert_template(options = {}, message = nil)
validate_request!
- hax = @controller._action_view.instance_variable_get(:@_rendered)
+ hax = @controller.view_context.instance_variable_get(:@_rendered)
case options
when NilClass, String
diff --git a/actionpack/test/controller/logging_test.rb b/actionpack/test/controller/logging_test.rb
index a7ed1b8665..98ffbc3813 100644
--- a/actionpack/test/controller/logging_test.rb
+++ b/actionpack/test/controller/logging_test.rb
@@ -17,9 +17,10 @@ class LoggingTest < ActionController::TestCase
@level = Logger::DEBUG
end
- def method_missing(method, *args)
+ def method_missing(method, *args, &blk)
@logged ||= []
@logged << args.first
+ @logged << blk.call if block_given?
end
end
diff --git a/actionpack/test/controller/record_identifier_test.rb b/actionpack/test/controller/record_identifier_test.rb
index 44e49ed3f8..6b6d154faa 100644
--- a/actionpack/test/controller/record_identifier_test.rb
+++ b/actionpack/test/controller/record_identifier_test.rb
@@ -54,24 +54,6 @@ class RecordIdentifierTest < Test::Unit::TestCase
assert_equal "edit_#{@singular}_1", dom_id(@record, :edit)
end
- def test_partial_path
- expected = "#{@plural}/#{@singular}"
- assert_equal expected, partial_path(@record)
- assert_equal expected, partial_path(Comment)
- end
-
- def test_partial_path_with_namespaced_controller_path
- expected = "admin/#{@plural}/#{@singular}"
- assert_equal expected, partial_path(@record, "admin/posts")
- assert_equal expected, partial_path(@klass, "admin/posts")
- end
-
- def test_partial_path_with_not_namespaced_controller_path
- expected = "#{@plural}/#{@singular}"
- assert_equal expected, partial_path(@record, "posts")
- assert_equal expected, partial_path(@klass, "posts")
- end
-
def test_dom_class
assert_equal @singular, dom_class(@record)
end
@@ -101,42 +83,3 @@ class RecordIdentifierTest < Test::Unit::TestCase
RecordIdentifier.send(method, *args)
end
end
-
-class NestedRecordIdentifierTest < RecordIdentifierTest
- def setup
- @klass = Comment::Nested
- @record = @klass.new
- @singular = 'comment_nested'
- @plural = 'comment_nesteds'
- end
-
- def test_partial_path
- expected = "comment/nesteds/nested"
- assert_equal expected, partial_path(@record)
- assert_equal expected, partial_path(Comment::Nested)
- end
-
- def test_partial_path_with_namespaced_controller_path
- expected = "admin/comment/nesteds/nested"
- assert_equal expected, partial_path(@record, "admin/posts")
- assert_equal expected, partial_path(@klass, "admin/posts")
- end
-
- def test_partial_path_with_deeper_namespaced_controller_path
- expected = "deeper/admin/comment/nesteds/nested"
- assert_equal expected, partial_path(@record, "deeper/admin/posts")
- assert_equal expected, partial_path(@klass, "deeper/admin/posts")
- end
-
- def test_partial_path_with_even_deeper_namespaced_controller_path
- expected = "even/more/deeper/admin/comment/nesteds/nested"
- assert_equal expected, partial_path(@record, "even/more/deeper/admin/posts")
- assert_equal expected, partial_path(@klass, "even/more/deeper/admin/posts")
- end
-
- def test_partial_path_with_not_namespaced_controller_path
- expected = "comment/nesteds/nested"
- assert_equal expected, partial_path(@record, "posts")
- assert_equal expected, partial_path(@klass, "posts")
- end
-end
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index d0fa67c945..947ffa9ea6 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -17,8 +17,9 @@ class MockLogger
@logged = []
end
- def method_missing(method, *args)
+ def method_missing(method, *args, &blk)
@logged << args.first
+ @logged << blk.call if block_given?
end
end