diff options
author | Łukasz Strzałkowski <lukasz.strzalkowski@gmail.com> | 2013-07-05 14:34:39 +0200 |
---|---|---|
committer | Łukasz Strzałkowski <lukasz.strzalkowski@gmail.com> | 2013-08-25 11:39:09 +0200 |
commit | 8e3413d41098eca3806ef0bed978d71397e3b1da (patch) | |
tree | ec17d7ab63a600faf509a7e00456d4540e7df38d | |
parent | c90971644a90372cfa56dac8b9b2ce709a6e7267 (diff) | |
download | rails-8e3413d41098eca3806ef0bed978d71397e3b1da.tar.gz rails-8e3413d41098eca3806ef0bed978d71397e3b1da.tar.bz2 rails-8e3413d41098eca3806ef0bed978d71397e3b1da.zip |
Create AbstractController::Rendering interface
This interface should be use when implementing renderers.
-rw-r--r-- | actionpack/lib/abstract_controller.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/abstract_controller/rendering.rb | 50 | ||||
-rw-r--r-- | actionpack/lib/action_controller/base.rb | 6 | ||||
-rw-r--r-- | actionpack/test/abstract/abstract_controller_test.rb | 1 | ||||
-rw-r--r-- | actionpack/test/abstract/helper_test.rb | 3 | ||||
-rw-r--r-- | actionpack/test/abstract/layouts_test.rb | 1 | ||||
-rw-r--r-- | actionpack/test/abstract/render_test.rb | 1 | ||||
-rw-r--r-- | actionpack/test/abstract_unit.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/mime/respond_with_test.rb | 1 | ||||
-rw-r--r-- | actionpack/test/controller/render_test.rb | 2 | ||||
-rw-r--r-- | actionview/lib/action_view/rendering.rb | 21 |
11 files changed, 69 insertions, 20 deletions
diff --git a/actionpack/lib/abstract_controller.rb b/actionpack/lib/abstract_controller.rb index 909b438a41..52f16b7bec 100644 --- a/actionpack/lib/abstract_controller.rb +++ b/actionpack/lib/abstract_controller.rb @@ -13,6 +13,7 @@ module AbstractController autoload :DoubleRenderError, "abstract_controller/rendering.rb" autoload :Helpers autoload :Logger + autoload :Rendering autoload :Translation autoload :AssetPaths autoload :UrlFor diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 8997207550..6e5b172203 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -6,4 +6,54 @@ module AbstractController super(message || DEFAULT_MESSAGE) end end + + module Rendering + # Raw rendering of a template to a string. + # + # It is similar to render, except that it does not + # set the response_body and it should be guaranteed + # to always return a string. + # + # If a component extends the semantics of response_body + # (as Action Controller extends it to be anything that + # responds to the method each), this method needs to be + # overridden in order to still return a string. + # :api: plugin + def render_to_string(*args, &block) + end + + # Raw rendering of a template. + # :api: plugin + def render_to_body(options = {}) + end + + def render(*args, &block) + end + + # This method should return a hash with assigns. + # You can overwrite this configuration per controller. + # :api: public + def view_assigns + {} + end + + # Normalize args by converting render "foo" to render :action => "foo" and + # render "foo/bar" to render :file => "foo/bar". + # :api: plugin + def _normalize_args(action=nil, options={}) + options + end + + # Normalize options. + # :api: plugin + def _normalize_options(options) + options + end + + # Process extra options. + # :api: plugin + def _process_options(options) + options + end + end end diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index ebb7cc2a64..82a7366f6b 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -161,7 +161,11 @@ module ActionController # render action: "overthere" # won't be called if monkeys is nil # end # - class Base < Metal + metal = Class.new(Metal) do + include AbstractController::Rendering + end + + class Base < metal abstract! # We document the request and response methods here because albeit they are diff --git a/actionpack/test/abstract/abstract_controller_test.rb b/actionpack/test/abstract/abstract_controller_test.rb index a161188b8e..40d3b17131 100644 --- a/actionpack/test/abstract/abstract_controller_test.rb +++ b/actionpack/test/abstract/abstract_controller_test.rb @@ -29,6 +29,7 @@ module AbstractController # Test Render mixin # ==== class RenderingController < AbstractController::Base + include AbstractController::Rendering include ActionView::Rendering def _prefixes diff --git a/actionpack/test/abstract/helper_test.rb b/actionpack/test/abstract/helper_test.rb index 555669efa5..a596ebe6f7 100644 --- a/actionpack/test/abstract/helper_test.rb +++ b/actionpack/test/abstract/helper_test.rb @@ -6,8 +6,9 @@ module AbstractController module Testing class ControllerWithHelpers < AbstractController::Base - include ActionView::Rendering include AbstractController::Helpers + include AbstractController::Rendering + include ActionView::Rendering def with_module render :inline => "Module <%= included_method %>" diff --git a/actionpack/test/abstract/layouts_test.rb b/actionpack/test/abstract/layouts_test.rb index 168e40c610..c79cb50fd7 100644 --- a/actionpack/test/abstract/layouts_test.rb +++ b/actionpack/test/abstract/layouts_test.rb @@ -5,6 +5,7 @@ module AbstractControllerTests # Base controller for these tests class Base < AbstractController::Base + include AbstractController::Rendering include ActionView::Rendering include ActionView::Layouts diff --git a/actionpack/test/abstract/render_test.rb b/actionpack/test/abstract/render_test.rb index 56e5f48825..f9d8c916d9 100644 --- a/actionpack/test/abstract/render_test.rb +++ b/actionpack/test/abstract/render_test.rb @@ -4,6 +4,7 @@ module AbstractController module Testing class ControllerRenderer < AbstractController::Base + include AbstractController::Rendering include ActionView::Rendering def _prefixes diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index d4e984f998..49dd891e4c 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -271,7 +271,6 @@ end module ActionController class Base include ActionController::Testing - include ActionView::Layouts # This stub emulates the Railtie including the URL helpers from a Rails application include SharedTestRoutes.url_helpers include SharedTestRoutes.mounted_helpers @@ -291,6 +290,7 @@ module ActionController end end + class ::ApplicationController < ActionController::Base end diff --git a/actionpack/test/controller/mime/respond_with_test.rb b/actionpack/test/controller/mime/respond_with_test.rb index 29ddbff8d4..76af9e3414 100644 --- a/actionpack/test/controller/mime/respond_with_test.rb +++ b/actionpack/test/controller/mime/respond_with_test.rb @@ -337,6 +337,7 @@ class RespondWithControllerTest < ActionController::TestCase errors = { :name => :invalid } Customer.any_instance.stubs(:errors).returns(errors) put :using_resource + assert_equal "text/html", @response.content_type assert_equal 200, @response.status assert_equal "Edit world!\n", @response.body diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index fd835795c0..bacc93a936 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -755,6 +755,8 @@ class TestController < ActionController::Base end class MetalTestController < ActionController::Metal + include AbstractController::Rendering + include ActionView::Rendering include ActionController::Rendering def accessing_logger_in_template diff --git a/actionview/lib/action_view/rendering.rb b/actionview/lib/action_view/rendering.rb index 9bade857be..6453b0543a 100644 --- a/actionview/lib/action_view/rendering.rb +++ b/actionview/lib/action_view/rendering.rb @@ -83,21 +83,11 @@ module ActionView # Normalize arguments, options and then delegates render_to_body and # sticks the result in self.response_body. def render(*args, &block) + super options = _normalize_render(*args, &block) self.response_body = render_to_body(options) end - # Raw rendering of a template to a string. - # - # It is similar to render, except that it does not - # set the response_body and it should be guaranteed - # to always return a string. - # - # If a component extends the semantics of response_body - # (as Action Controller extends it to be anything that - # responds to the method each), this method needs to be - # overridden in order to still return a string. - # :api: plugin def render_to_string(*args, &block) options = _normalize_render(*args, &block) render_to_body(options) @@ -126,7 +116,7 @@ module ActionView # You can overwrite this configuration per controller. # :api: public def view_assigns - hash = {} + hash = super variables = instance_variables variables -= protected_instance_variables variables -= DEFAULT_PROTECTED_INSTANCE_VARIABLES @@ -148,6 +138,7 @@ module ActionView # render "foo/bar" to render :file => "foo/bar". # :api: plugin def _normalize_args(action=nil, options={}) + options = super(action, options) case action when NilClass when Hash @@ -166,6 +157,7 @@ module ActionView # Normalize options. # :api: plugin def _normalize_options(options) + options = super(options) if options[:partial] == true options[:partial] = action_name end @@ -177,10 +169,5 @@ module ActionView options[:template] ||= (options[:action] || action_name).to_s options end - - # Process extra options. - # :api: plugin - def _process_options(options) - end end end |