aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/abstract_controller
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-03-12 20:39:53 +0100
committerJosé Valim <jose.valim@gmail.com>2010-03-12 20:39:53 +0100
commitf2c0a353aef41a6df2de8e1fe3eaa3d8bbd8a6dd (patch)
treea854e0b7b79968f7f7cdfb57d29fd6644805c5ae /actionpack/lib/abstract_controller
parent2a12686832fbcf0566454904a5d733998506bf56 (diff)
downloadrails-f2c0a353aef41a6df2de8e1fe3eaa3d8bbd8a6dd.tar.gz
rails-f2c0a353aef41a6df2de8e1fe3eaa3d8bbd8a6dd.tar.bz2
rails-f2c0a353aef41a6df2de8e1fe3eaa3d8bbd8a6dd.zip
Finish cleaning up rendering stack from views and move assigns evaluation to controller (so plugins and/or controllers can overwrite just one method).
Diffstat (limited to 'actionpack/lib/abstract_controller')
-rw-r--r--actionpack/lib/abstract_controller/assigns.rb21
-rw-r--r--actionpack/lib/abstract_controller/layouts.rb6
-rw-r--r--actionpack/lib/abstract_controller/rendering.rb16
3 files changed, 35 insertions, 8 deletions
diff --git a/actionpack/lib/abstract_controller/assigns.rb b/actionpack/lib/abstract_controller/assigns.rb
new file mode 100644
index 0000000000..21459c6d51
--- /dev/null
+++ b/actionpack/lib/abstract_controller/assigns.rb
@@ -0,0 +1,21 @@
+module AbstractController
+ module Assigns
+ # This method should return a hash with assigns.
+ # You can overwrite this configuration per controller.
+ # :api: public
+ def view_assigns
+ hash = {}
+ variables = instance_variable_names
+ variables -= protected_instance_variables if respond_to?(:protected_instance_variables)
+ variables.each { |name| hash[name] = instance_variable_get(name) }
+ hash
+ end
+
+ # This method assigns the hash specified in _assigns_hash to the given object.
+ # :api: private
+ # TODO Ideally, this should be done on AV::Base.new initialization.
+ def _evaluate_assigns(object)
+ view_assigns.each { |k,v| object.instance_variable_set(k, v) }
+ end
+ end
+end \ No newline at end of file
diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb
index 2f9616124a..95a6101109 100644
--- a/actionpack/lib/abstract_controller/layouts.rb
+++ b/actionpack/lib/abstract_controller/layouts.rb
@@ -284,6 +284,12 @@ module AbstractController
layout = options.key?(:layout) ? options.delete(:layout) : :default
value = _layout_for_option(layout)
options[:layout] = (value =~ /\blayouts/ ? value : "layouts/#{value}") if value
+
+ # TODO Layout for partials should be handled here, because inside the
+ # partial renderer it looks for the layout as a partial.
+ if options.key?(:partial) && options[:layout]
+ options[:layout] = view_context.find_layout(options[:layout])
+ end
end
end
diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb
index 42f4939108..16664098e5 100644
--- a/actionpack/lib/abstract_controller/rendering.rb
+++ b/actionpack/lib/abstract_controller/rendering.rb
@@ -31,6 +31,8 @@ module AbstractController
module Rendering
extend ActiveSupport::Concern
+
+ include AbstractController::Assigns
include AbstractController::ViewPaths
# Overwrite process to setup I18n proxy.
@@ -54,8 +56,8 @@ module AbstractController
@_view_context ||= ActionView::Base.for_controller(self)
end
- # Mostly abstracts the fact that calling render twice is a DoubleRenderError.
- # Delegates render_to_body and sticks the result in self.response_body.
+ # Normalize arguments, options and then delegates render_to_body and
+ # sticks the result in self.response_body.
def render(*args, &block)
options = _normalize_args(*args, &block)
_normalize_options(options)
@@ -78,8 +80,10 @@ module AbstractController
end
# Find and renders a template based on the options given.
- def _render_template(options)
- view_context.render_template(options) { |template| _with_template_hook(template) }
+ # :api: private
+ def _render_template(options) #:nodoc:
+ _evaluate_assigns(view_context)
+ view_context.render(options)
end
# The prefix used in render "foo" shortcuts.
@@ -134,9 +138,5 @@ module AbstractController
def _process_options(options)
end
-
- def _with_template_hook(template)
- self.formats = template.formats
- end
end
end