aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorYehuda Katz <wycats@gmail.com>2009-07-19 21:53:02 +0900
committerYehuda Katz <wycats@gmail.com>2009-07-19 21:53:02 +0900
commitbb530923bcd5c643f9bfca8e36cd3fa36365032d (patch)
treee5d821e7f13334a64a3936d0a484bbcd8667552f /actionpack
parent1a2946a6d9b1dbcf3a4c77654693d73f9b11bde1 (diff)
downloadrails-bb530923bcd5c643f9bfca8e36cd3fa36365032d.tar.gz
rails-bb530923bcd5c643f9bfca8e36cd3fa36365032d.tar.bz2
rails-bb530923bcd5c643f9bfca8e36cd3fa36365032d.zip
Simplify required "ActionView compliant" API
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_controller/abstract/helpers.rb6
-rw-r--r--actionpack/lib/action_controller/abstract/renderer.rb19
-rw-r--r--actionpack/lib/action_view/base.rb6
-rw-r--r--actionpack/lib/action_view/render/partials.rb6
-rw-r--r--actionpack/test/abstract_unit.rb2
5 files changed, 17 insertions, 22 deletions
diff --git a/actionpack/lib/action_controller/abstract/helpers.rb b/actionpack/lib/action_controller/abstract/helpers.rb
index 6b73f887c1..5efa37fde3 100644
--- a/actionpack/lib/action_controller/abstract/helpers.rb
+++ b/actionpack/lib/action_controller/abstract/helpers.rb
@@ -8,12 +8,6 @@ module AbstractController
extlib_inheritable_accessor(:_helpers) { Module.new }
end
- # Override AbstractController::Renderer's _action_view to include the
- # helper module for this class into its helpers module.
- def _action_view
- @_action_view ||= super.tap { |av| av.helpers.include(_helpers) }
- end
-
module ClassMethods
# When a class is inherited, wrap its helper module in a new module.
# This ensures that the parent class's module can be changed
diff --git a/actionpack/lib/action_controller/abstract/renderer.rb b/actionpack/lib/action_controller/abstract/renderer.rb
index 611d3a16ce..41b7d47458 100644
--- a/actionpack/lib/action_controller/abstract/renderer.rb
+++ b/actionpack/lib/action_controller/abstract/renderer.rb
@@ -17,25 +17,22 @@ module AbstractController
# An instance of a view class. The default view class is ActionView::Base
#
# The view class must have the following methods:
- # initialize[paths, assigns_for_first_render, controller]
- # paths<Array[ViewPath]>:: A list of resolvers to look for templates in
- # controller<AbstractController::Base> A controller
- # _render_partial_from_controller[options]
+ # View.for_controller[controller] Create a new ActionView instance for a
+ # controller
+ # View#_render_partial_from_controller[options]
+ # - responsible for setting options[:_template]
+ # - Returns String with the rendered partial
# options<Hash>:: see _render_partial in ActionView::Base
- # _render_template_from_controller[template, layout, options, partial]
+ # View#_render_template_from_controller[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
# options<Hash>:: See _render_template_with_layout in ActionView::Base
# partial<Boolean>:: Whether or not the template to render is a partial
- # _partial:: If a partial, rather than a template, was rendered, return
- # the partial.
- # helpers:: A module containing the helpers to be used in the view. This
- # module should respond_to include.
- # controller:: The controller that initialized the ActionView
#
# Override this method in a to change the default behavior.
def _action_view
- @_action_view ||= ActionView::Base.new(self.class.view_paths, {}, self)
+ @_action_view ||= ActionView::Base.for_controller(self)
end
# Mostly abstracts the fact that calling render twice is a DoubleRenderError.
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index 45184f58fb..5915337dd2 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -228,6 +228,12 @@ module ActionView #:nodoc:
end
end
+ def self.for_controller(controller)
+ new(controller.class.view_paths, {}, controller).tap do |view|
+ view.helpers.include(controller._helpers) if controller.respond_to?(:_helpers)
+ end
+ end
+
def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil, formats = nil)#:nodoc:
@formats = formats || [:html]
@assigns = assigns_for_first_render.each { |key, value| instance_variable_set("@#{key}", value) }
diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb
index a80ffe3c20..ccb14d513a 100644
--- a/actionpack/lib/action_view/render/partials.rb
+++ b/actionpack/lib/action_view/render/partials.rb
@@ -259,7 +259,7 @@ module ActionView
_set_locals(object, locals, template, options)
- self._partial = template
+ options[:_template] = template
_render_template(template, locals)
end
@@ -278,7 +278,7 @@ module ActionView
locals = (options[:locals] ||= {})
index, @_partial_path = 0, nil
collection.map do |object|
- template = passed_template || begin
+ options[:_template] = template = passed_template || begin
_partial_path =
ActionController::RecordIdentifier.partial_path(object, controller_path)
template = _pick_partial_template(_partial_path)
@@ -289,8 +289,6 @@ module ActionView
index += 1
- self._partial = template
-
_render_template(template, locals)
end.join(spacer)
end
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index 30e795a7a2..292d138fbd 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -97,7 +97,7 @@ module ActionController
partials = hax[:partials]
if expected_count = options[:count]
found = partials.detect { |p, _| p.identifier.match(expected_partial) }
- actual_count = found.nil? ? 0 : found.second
+ actual_count = found.nil? ? 0 : found[1]
msg = build_message(message,
"expecting ? to be rendered ? time(s) but rendered ? time(s)",
expected_partial, expected_count, actual_count)