aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/abstract_controller/rendering.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-09-03 06:32:55 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-09-03 06:32:55 -0700
commit8436620cb519c0c808fdd006c7c276146fb3b005 (patch)
tree964ea60d5ccd73db9df2fdb47665b9e319488b1c /actionpack/lib/abstract_controller/rendering.rb
parente3b695331d95022f9b41faf131f8e98cdf4f6985 (diff)
parenteddf367b8948d23f65a68a27a8bd3071e8a3d48d (diff)
downloadrails-8436620cb519c0c808fdd006c7c276146fb3b005.tar.gz
rails-8436620cb519c0c808fdd006c7c276146fb3b005.tar.bz2
rails-8436620cb519c0c808fdd006c7c276146fb3b005.zip
Merge pull request #12121 from strzalek/move-methods-to-abs-controller
Move glue methods & BasicRendering to AbstractController
Diffstat (limited to 'actionpack/lib/abstract_controller/rendering.rb')
-rw-r--r--actionpack/lib/abstract_controller/rendering.rb55
1 files changed, 48 insertions, 7 deletions
diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb
index a3c45bacb7..4596aad46c 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,22 +36,21 @@ 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
# :api: public
def rendered_format
+ Mime::TEXT
end
DEFAULT_PROTECTED_INSTANCE_VARIABLES = %w(
@@ -83,5 +88,41 @@ 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
+
+ # 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