1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

small refactors to actionview renderers

This commit is contained in:
Eugene Gilburg 2014-07-18 20:54:03 -07:00
parent fe6f436dd9
commit 38117adfe3
3 changed files with 15 additions and 16 deletions

View file

@ -29,8 +29,9 @@ module ActionView
def extract_details(options)
@lookup_context.registered_details.each_with_object({}) do |key, details|
next unless value = options[key]
details[key] = Array(value)
value = options[key]
details[key] = Array(value) if value
end
end
@ -41,6 +42,7 @@ module ActionView
def prepend_formats(formats)
formats = Array(formats)
return if formats.empty? || @lookup_context.html_fallback_for_js
@lookup_context.formats = formats | @lookup_context.formats
end
end

View file

@ -353,25 +353,27 @@ module ActionView
# respond to +to_partial_path+ in order to setup the path.
def setup(context, options, block)
@view = context
partial = options[:partial]
@options = options
@locals = options[:locals] || {}
@block = block
@locals = options[:locals] || {}
@details = extract_details(options)
prepend_formats(options[:formats])
partial = options[:partial]
if String === partial
@object = options[:object]
@collection = collection_from_options
@path = partial
@collection = collection
else
@object = partial
@collection = collection_from_object || collection_from_options
if @collection = collection_from_object || collection
if @collection
paths = @collection_data = @collection.map { |o| partial_path(o) }
@path = paths.uniq.size == 1 ? paths.first : nil
@path = paths.uniq.one? ? paths.first : nil
else
@path = partial_path
end
@ -392,7 +394,7 @@ module ActionView
self
end
def collection
def collection_from_options
if @options.key?(:collection)
collection = @options[:collection]
collection.respond_to?(:to_ary) ? collection.to_ary : []
@ -404,9 +406,7 @@ module ActionView
end
def find_partial
if path = @path
find_template(path, @template_keys)
end
find_template(@path, @template_keys) if @path
end
def find_template(path, locals)

View file

@ -6,13 +6,10 @@ module ActionView
@view = context
@details = extract_details(options)
template = determine_template(options)
context = @lookup_context
prepend_formats(template.formats)
unless context.rendered_format
context.rendered_format = template.formats.first || formats.first
end
@lookup_context.rendered_format ||= (template.formats.first || formats.first)
render_template(template, options[:layout], options[:locals])
end