From aea02eb43001d85def0e69dce76fde0757040089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Strza=C5=82kowski?= Date: Tue, 3 Sep 2013 14:57:33 +0200 Subject: Move skeleton methods from AV to AbsC The methods: * #render_to_body * #render_to_string * #_normalize_render Haven't had anything specyfic to ActionView. This was common code which should belong to AbstractController --- actionpack/lib/abstract_controller/rendering.rb | 26 ++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index a3c45bacb7..c74bbafdec 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -18,6 +18,12 @@ module AbstractController self.protected_instance_variables = [] end + # Normalize arguments, options and then delegates render_to_body and + # sticks the result in self.response_body. + # :api: public + def render(*args, &block) + end + # Raw rendering of a template to a string. # # It is similar to render, except that it does not @@ -30,17 +36,15 @@ module AbstractController # 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) end # Raw rendering of a template. - # :api: plugin - def render_to_body(options = {}) - end - - # Normalize arguments, options and then delegates render_to_body and - # sticks the result in self.response_body. # :api: public - def render(*args, &block) + def render_to_body(options = {}) + _process_options(options) + _render_template(options) end # Return Content-Type of rendered content @@ -83,5 +87,13 @@ module AbstractController def _process_options(options) options end + + # Normalize args and options. + # :api: private + def _normalize_render(*args, &block) + options = _normalize_args(*args, &block) + _normalize_options(options) + options + end end end -- cgit v1.2.3 From d35cf4b6a0645dffb508ae1a5ad10924f7026f0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Strza=C5=82kowski?= Date: Tue, 3 Sep 2013 14:58:46 +0200 Subject: Make Mime::TEXT default format in AbstractController --- actionpack/lib/abstract_controller/rendering.rb | 1 + actionpack/lib/action_controller/metal/rendering.rb | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index c74bbafdec..0a4b58de7f 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -50,6 +50,7 @@ module AbstractController # Return Content-Type of rendered content # :api: public def rendered_format + Mime::TEXT end DEFAULT_PROTECTED_INSTANCE_VARIABLES = %w( diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb index 21224b9c3b..a853adec23 100644 --- a/actionpack/lib/action_controller/metal/rendering.rb +++ b/actionpack/lib/action_controller/metal/rendering.rb @@ -20,10 +20,6 @@ module ActionController end end - def rendered_format - Mime::TEXT - end - class UnsupportedOperationError < StandardError def initialize super "Unsupported render operation. BasicRendering supports only :text and :nothing options. For more, you need to include ActionView." -- cgit v1.2.3 From eddf367b8948d23f65a68a27a8bd3071e8a3d48d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Strza=C5=82kowski?= Date: Tue, 3 Sep 2013 15:03:56 +0200 Subject: Move BasicRendering to AbstractController --- actionpack/lib/abstract_controller/rendering.rb | 28 ++++++++++++++++++++++ actionpack/lib/action_controller/base.rb | 2 +- .../lib/action_controller/metal/rendering.rb | 28 ---------------------- 3 files changed, 29 insertions(+), 29 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 0a4b58de7f..4596aad46c 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -97,4 +97,32 @@ module AbstractController options end end + + # Basic rendering implements the most minimal rendering layer. + # It only supports rendering :text and :nothing. Passing any other option will + # result in `UnsupportedOperationError` exception. For more functionality like + # different formats, layouts etc. you should use `ActionView` gem. + module BasicRendering + extend ActiveSupport::Concern + + # Render text or nothing (empty string) to response_body + # :api: public + def render(*args, &block) + super(*args, &block) + opts = args.first + if opts.has_key?(:text) && opts[:text].present? + self.response_body = opts[:text] + elsif opts.has_key?(:nothing) && opts[:nothing] + self.response_body = " " + else + raise UnsupportedOperationError + end + end + + class UnsupportedOperationError < StandardError + def initialize + super "Unsupported render operation. BasicRendering supports only :text and :nothing options. For more, you need to include ActionView." + end + end + end end diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 9941c06201..df416908f0 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -14,7 +14,7 @@ module ActionController # metal = Class.new(Metal) do include AbstractController::Rendering - include ActionController::BasicRendering + include AbstractController::BasicRendering end # Action Controllers are the core of a web request in \Rails. They are made up of one or more actions that are executed diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb index a853adec23..abcc9d4acf 100644 --- a/actionpack/lib/action_controller/metal/rendering.rb +++ b/actionpack/lib/action_controller/metal/rendering.rb @@ -1,32 +1,4 @@ module ActionController - # Basic rendering implements the most minimal rendering layer. - # It only supports rendering :text and :nothing. Passing any other option will - # result in `UnsupportedOperationError` exception. For more functionality like - # different formats, layouts etc. you should use `ActionView` gem. - module BasicRendering - extend ActiveSupport::Concern - - # Render text or nothing (empty string) to response_body - # :api: public - def render(*args, &block) - super(*args, &block) - opts = args.first - if opts.has_key?(:text) && opts[:text].present? - self.response_body = opts[:text] - elsif opts.has_key?(:nothing) && opts[:nothing] - self.response_body = " " - else - raise UnsupportedOperationError - end - end - - class UnsupportedOperationError < StandardError - def initialize - super "Unsupported render operation. BasicRendering supports only :text and :nothing options. For more, you need to include ActionView." - end - end - end - module Rendering extend ActiveSupport::Concern -- cgit v1.2.3