From 6416a35f4b3290a93145d40045147fc01d36e756 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 17 Mar 2010 14:23:00 -0700 Subject: Remove unneeded AV::Base and AV::Template monkey-patches --- actionpack/lib/abstract_controller/rendering.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib/abstract_controller/rendering.rb') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 16664098e5..94c9ec7478 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -1,4 +1,5 @@ require "abstract_controller/base" +require "action_view/base" module AbstractController class DoubleRenderError < Error -- cgit v1.2.3 From 21dcbb17de86b92df1a67e233fdc457be4fdf2d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 17 Mar 2010 23:09:28 +0100 Subject: Ensure json is loaded before using responders. --- actionpack/lib/abstract_controller/rendering.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'actionpack/lib/abstract_controller/rendering.rb') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 94c9ec7478..16664098e5 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -1,5 +1,4 @@ require "abstract_controller/base" -require "action_view/base" module AbstractController class DoubleRenderError < Error -- cgit v1.2.3 From 71c9337f45f9c5461cbc6ddf6cab764ad0f82c3b Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Thu, 18 Mar 2010 15:52:43 -0700 Subject: All tests pass without memoizing view_context --- actionpack/lib/abstract_controller/rendering.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/abstract_controller/rendering.rb') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 16664098e5..eec7e520fa 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -32,7 +32,6 @@ module AbstractController module Rendering extend ActiveSupport::Concern - include AbstractController::Assigns include AbstractController::ViewPaths # Overwrite process to setup I18n proxy. @@ -53,7 +52,8 @@ module AbstractController # # Override this method in a module to change the default behavior. def view_context - @_view_context ||= ActionView::Base.for_controller(self) + klass = ActionView::Base.for_controller(self) + klass.new(lookup_context, view_assigns, self) end # Normalize arguments, options and then delegates render_to_body and @@ -82,7 +82,6 @@ module AbstractController # Find and renders a template based on the options given. # :api: private def _render_template(options) #:nodoc: - _evaluate_assigns(view_context) view_context.render(options) end @@ -105,6 +104,17 @@ module AbstractController private + # 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.to_s[1..-1]] = instance_variable_get(name) } + hash + end + # Normalize options by converting render "foo" to render :action => "foo" and # render "foo/bar" to render :file => "foo/bar". def _normalize_args(action=nil, options={}) -- cgit v1.2.3 From 1dacc19702f88a18a57615d1a5eeab3d0f5f9007 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Thu, 18 Mar 2010 17:32:53 -0700 Subject: Return a valid Rack response from bare ActionController::Metal --- actionpack/lib/abstract_controller/rendering.rb | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'actionpack/lib/abstract_controller/rendering.rb') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index eec7e520fa..402ad7c8d7 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -76,7 +76,7 @@ module AbstractController # :api: plugin def render_to_string(options={}) _normalize_options(options) - AbstractController::Rendering.body_to_s(render_to_body(options)) + render_to_body(options) end # Find and renders a template based on the options given. @@ -90,18 +90,6 @@ module AbstractController controller_path end - # Return a string representation of a Rack-compatible response body. - def self.body_to_s(body) - if body.respond_to?(:to_str) - body - else - strings = [] - body.each { |part| strings << part.to_s } - body.close if body.respond_to?(:close) - strings.join - end - end - private # This method should return a hash with assigns. -- cgit v1.2.3 From a5d80f84d269bba6b0f0802612f29df1ee09d720 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Thu, 18 Mar 2010 18:12:04 -0700 Subject: Each controller class has it's own view context subclass. This removes the need for ActionView::Base.for_controller --- actionpack/lib/abstract_controller/rendering.rb | 28 +++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'actionpack/lib/abstract_controller/rendering.rb') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 402ad7c8d7..58d339d563 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -42,18 +42,38 @@ module AbstractController I18n.config = old_config end + module ClassMethods + def view_context_class + @view_context_class ||= begin + controller = self + Class.new(ActionView::Base) do + if controller.respond_to?(:_helpers) + include controller._helpers + # TODO: Fix RJS to not require this + self.helpers = controller._helpers + end + end + end + end + end + + attr_writer :view_context_class + + def view_context_class + @view_context_class || self.class.view_context_class + end + # An instance of a view class. The default view class is ActionView::Base # # The view class must have the following methods: - # View.for_controller[controller] + # View.new[lookup_context, assigns, controller] # Create a new ActionView instance for a controller - # View#render_template[options] + # View#render[options] # Returns String with the rendered template # # Override this method in a module to change the default behavior. def view_context - klass = ActionView::Base.for_controller(self) - klass.new(lookup_context, view_assigns, self) + view_context_class.new(lookup_context, view_assigns, self) end # Normalize arguments, options and then delegates render_to_body and -- cgit v1.2.3 From 995f57033f5a36d9ddd3aa65f0f01cccbb6baf6e Mon Sep 17 00:00:00 2001 From: wycats Date: Thu, 18 Mar 2010 22:21:25 -0700 Subject: We seem to have removed the URL helpers from ActionView subclasses... --- actionpack/lib/abstract_controller/rendering.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'actionpack/lib/abstract_controller/rendering.rb') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 58d339d563..cde14916f2 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -49,6 +49,7 @@ module AbstractController Class.new(ActionView::Base) do if controller.respond_to?(:_helpers) include controller._helpers + include controller._router.url_helpers # TODO: Fix RJS to not require this self.helpers = controller._helpers end @@ -63,6 +64,11 @@ module AbstractController @view_context_class || self.class.view_context_class end + def initialize(*) + @view_context_class = nil + super + end + # An instance of a view class. The default view class is ActionView::Base # # The view class must have the following methods: -- cgit v1.2.3 From 0aa0c37b59077d3f8b0d43c4d5faf86d40949f5f Mon Sep 17 00:00:00 2001 From: wycats Date: Thu, 18 Mar 2010 22:55:44 -0700 Subject: Well that was a bust --- actionpack/lib/abstract_controller/rendering.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/abstract_controller/rendering.rb') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index cde14916f2..b251bd6405 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -49,7 +49,11 @@ module AbstractController Class.new(ActionView::Base) do if controller.respond_to?(:_helpers) include controller._helpers - include controller._router.url_helpers + + if controller.respond_to?(:_router) + include controller._router.url_helpers + end + # TODO: Fix RJS to not require this self.helpers = controller._helpers end -- cgit v1.2.3