diff options
author | Prem Sichanugrist <s@sikac.hu> | 2014-02-07 13:45:57 -0500 |
---|---|---|
committer | Prem Sichanugrist <s@sikac.hu> | 2014-02-18 12:08:36 -0500 |
commit | 8cd9f6d205e5db5331dd5b01be35b537da17cdee (patch) | |
tree | 63de043c2a65cddf20105e608ea60af1a1e65e20 /actionview | |
parent | 9e9cc660773d331b04a829b4a727af70b3e23c16 (diff) | |
download | rails-8cd9f6d205e5db5331dd5b01be35b537da17cdee.tar.gz rails-8cd9f6d205e5db5331dd5b01be35b537da17cdee.tar.bz2 rails-8cd9f6d205e5db5331dd5b01be35b537da17cdee.zip |
Introduce `render :plain` for render plain text
This is as an option to render content with a content type of
`text/plain`. This is the preferred option if you are planning to render
a plain text content.
Please see #12374 for more detail.
Diffstat (limited to 'actionview')
-rw-r--r-- | actionview/lib/action_view/helpers/rendering_helper.rb | 2 | ||||
-rw-r--r-- | actionview/lib/action_view/layouts.rb | 2 | ||||
-rw-r--r-- | actionview/lib/action_view/renderer/template_renderer.rb | 4 |
3 files changed, 6 insertions, 2 deletions
diff --git a/actionview/lib/action_view/helpers/rendering_helper.rb b/actionview/lib/action_view/helpers/rendering_helper.rb index 77d63b7f86..4eae80cd93 100644 --- a/actionview/lib/action_view/helpers/rendering_helper.rb +++ b/actionview/lib/action_view/helpers/rendering_helper.rb @@ -12,6 +12,8 @@ module ActionView # * <tt>:file</tt> - Renders an explicit template file (this used to be the old default), add :locals to pass in those. # * <tt>:inline</tt> - Renders an inline template similar to how it's done in the controller. # * <tt>:text</tt> - Renders the text passed in out. + # * <tt>:plain</tt> - Renders the text passed in out. Setting the content + # type as <tt>text/plain</tt>. # * <tt>:body</tt> - Renders the text passed in, and does not set content # type in the response. # diff --git a/actionview/lib/action_view/layouts.rb b/actionview/lib/action_view/layouts.rb index b67b749af5..3f049e838a 100644 --- a/actionview/lib/action_view/layouts.rb +++ b/actionview/lib/action_view/layouts.rb @@ -420,7 +420,7 @@ module ActionView end def _include_layout?(options) - (options.keys & [:body, :text, :inline, :partial]).empty? || options.key?(:layout) + (options.keys & [:body, :text, :plain, :inline, :partial]).empty? || options.key?(:layout) end end end diff --git a/actionview/lib/action_view/renderer/template_renderer.rb b/actionview/lib/action_view/renderer/template_renderer.rb index 8f24f8dab0..ba946b230a 100644 --- a/actionview/lib/action_view/renderer/template_renderer.rb +++ b/actionview/lib/action_view/renderer/template_renderer.rb @@ -25,6 +25,8 @@ module ActionView Template::Text.new(options[:body]) elsif options.key?(:text) Template::Text.new(options[:text], formats.first) + elsif options.key?(:plain) + Template::Text.new(options[:plain]) elsif options.key?(:file) with_fallbacks { find_template(options[:file], nil, false, keys, @details) } elsif options.key?(:inline) @@ -37,7 +39,7 @@ module ActionView find_template(options[:template], options[:prefixes], false, keys, @details) end else - raise ArgumentError, "You invoked render but did not give any of :partial, :template, :inline, :file, :text or :body option." + raise ArgumentError, "You invoked render but did not give any of :partial, :template, :inline, :file, :plain, :text or :body option." end end |