From 8cd9f6d205e5db5331dd5b01be35b537da17cdee Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Fri, 7 Feb 2014 13:45:57 -0500 Subject: 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. --- actionview/lib/action_view/helpers/rendering_helper.rb | 2 ++ actionview/lib/action_view/layouts.rb | 2 +- actionview/lib/action_view/renderer/template_renderer.rb | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) (limited to 'actionview/lib') 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 # * :file - Renders an explicit template file (this used to be the old default), add :locals to pass in those. # * :inline - Renders an inline template similar to how it's done in the controller. # * :text - Renders the text passed in out. + # * :plain - Renders the text passed in out. Setting the content + # type as text/plain. # * :body - 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 -- cgit v1.2.3