aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikac.hu>2014-02-14 10:45:46 -0500
committerPrem Sichanugrist <s@sikac.hu>2014-02-18 12:08:36 -0500
commit79c4983f893da985806d3d59ac23836bccb906f8 (patch)
tree7fe31392aa300d5ef1c10aef07e728a42354ec15
parent243e6e4b2a53253d5ca734415564c419c5632f12 (diff)
downloadrails-79c4983f893da985806d3d59ac23836bccb906f8.tar.gz
rails-79c4983f893da985806d3d59ac23836bccb906f8.tar.bz2
rails-79c4983f893da985806d3d59ac23836bccb906f8.zip
Cleanup `ActionController::Rendering`
-rw-r--r--actionpack/lib/action_controller/metal/rendering.rb38
1 files changed, 27 insertions, 11 deletions
diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb
index cff0405351..ce37eaefd8 100644
--- a/actionpack/lib/action_controller/metal/rendering.rb
+++ b/actionpack/lib/action_controller/metal/rendering.rb
@@ -2,6 +2,8 @@ module ActionController
module Rendering
extend ActiveSupport::Concern
+ RENDER_FORMATS_IN_PRIORITY = [:body, :text, :plain, :html]
+
# Before processing, set the request formats in current controller formats.
def process_action(*) #:nodoc:
self.formats = request.formats.map(&:ref).compact
@@ -27,11 +29,19 @@ module ActionController
end
def render_to_body(options = {})
- super || options[:body].presence || options[:text].presence || options[:plain].presence || ERB::Util.h(options[:html]).presence || ' '
+ super || _render_in_priorities(options) || ' '
end
private
+ def _render_in_priorities(options)
+ RENDER_FORMATS_IN_PRIORITY.each do |format|
+ return options[format] if options.key?(format)
+ end
+
+ nil
+ end
+
def _process_format(format, options = {})
super
self.content_type ||= format.to_s
@@ -55,19 +65,13 @@ module ActionController
# Normalize both text and status options.
def _normalize_options(options) #:nodoc:
- if options.key?(:body) && options[:body].respond_to?(:to_text)
- options[:body] = options[:body].to_text
- end
+ _normalize_text(options)
- if options.key?(:text) && options[:text].respond_to?(:to_text)
- options[:text] = options[:text].to_text
+ if options[:html]
+ options[:html] = ERB::Util.html_escape(options[:html])
end
- if options.key?(:plain) && options[:plain].respond_to?(:to_text)
- options[:plain] = options[:plain].to_text
- end
-
- if options.delete(:nothing) || (options.key?(:body) && options[:body].nil?) || (options.key?(:text) && options[:text].nil?) || (options.key?(:plain) && options[:plain].nil?) || (options.key?(:html) && options[:html].nil?)
+ if options.delete(:nothing) || _any_render_format_is_nil?(options)
options[:body] = " "
end
@@ -78,6 +82,18 @@ module ActionController
super
end
+ def _normalize_text(options)
+ RENDER_FORMATS_IN_PRIORITY.each do |format|
+ if options.key?(format) && options[format].respond_to?(:to_text)
+ options[format] = options[format].to_text
+ end
+ end
+ end
+
+ def _any_render_format_is_nil?(options)
+ RENDER_FORMATS_IN_PRIORITY.any? { |format| options.key?(format) && options[format].nil? }
+ end
+
# Process controller specific options, as status, content-type and location.
def _process_options(options) #:nodoc:
status, content_type, location = options.values_at(:status, :content_type, :location)