mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Allow both sym and array for details options in #render. using LC#registered_details to extract options.
This commit is contained in:
parent
f8e6664d86
commit
2e3eb2560b
3 changed files with 16 additions and 2 deletions
|
@ -13,6 +13,17 @@ module ActionView
|
|||
|
||||
protected
|
||||
|
||||
def extract_details(options)
|
||||
details = {}
|
||||
@lookup_context.registered_details.each do |key|
|
||||
next unless value = options[key]
|
||||
details[key] = Array.wrap(value)
|
||||
end
|
||||
details
|
||||
end
|
||||
|
||||
|
||||
|
||||
def extract_format(value, details)
|
||||
if value.is_a?(String) && value.sub!(formats_regexp, "")
|
||||
ActiveSupport::Deprecation.warn "Passing the format in the template name is deprecated. " \
|
||||
|
|
|
@ -5,7 +5,7 @@ module ActionView
|
|||
class TemplateRenderer < AbstractRenderer #:nodoc:
|
||||
def render(context, options)
|
||||
@view = context
|
||||
@details = options.slice(:formats, :locale, :handlers)
|
||||
@details = extract_details(options)
|
||||
extract_format(options[:file] || options[:template], @details)
|
||||
template = determine_template(options)
|
||||
freeze_formats(template.formats, true)
|
||||
|
|
|
@ -36,6 +36,7 @@ module RenderTestCases
|
|||
def test_render_file_with_format
|
||||
assert_equal "<h1>No Comment</h1>", @view.render(:file => "comments/empty", :formats => [:html])
|
||||
assert_equal "<error>No Comment</error>", @view.render(:file => "comments/empty", :formats => [:xml])
|
||||
assert_equal "<error>No Comment</error>", @view.render(:file => "comments/empty", :formats => :xml)
|
||||
end
|
||||
|
||||
def test_render_template_with_format
|
||||
|
@ -45,6 +46,7 @@ module RenderTestCases
|
|||
|
||||
def test_render_file_with_locale
|
||||
assert_equal "<h1>Kein Kommentar</h1>", @view.render(:file => "comments/empty", :locale => [:de])
|
||||
assert_equal "<h1>Kein Kommentar</h1>", @view.render(:file => "comments/empty", :locale => :de)
|
||||
end
|
||||
|
||||
def test_render_template_with_locale
|
||||
|
@ -53,6 +55,7 @@ module RenderTestCases
|
|||
|
||||
def test_render_file_with_handlers
|
||||
assert_equal "<h1>No Comment</h1>\n", @view.render(:file => "comments/empty", :handlers => [:builder])
|
||||
assert_equal "<h1>No Comment</h1>\n", @view.render(:file => "comments/empty", :handlers => :builder)
|
||||
end
|
||||
|
||||
def test_render_template_with_handlers
|
||||
|
|
Loading…
Reference in a new issue