Sets up instance variables needed for rendering a partial. This method
finds the options and details and extracts them. The method also contains
logic that handles the type of object passed in as the partial.
If +options[:partial]+ is a string, then the +@path+ instance variable is
set to that string. Otherwise, the +options[:partial]+ object must respond
to to_partial_path in order to setup the path.
# File actionview/lib/action_view/renderer/partial_renderer.rb, line 358
def setup(context, options, block)
@view = context
@options = options
@block = block
@locals = options[:locals] || {}
@details = extract_details(options)
prepend_formats(options[:formats])
partial = options[:partial]
if String === partial
@has_object = options.key?(:object)
@object = options[:object]
@collection = collection_from_options
@path = partial
else
@has_object = true
@object = partial
@collection = collection_from_object || collection_from_options
if @collection
paths = @collection_data = @collection.map { |o| partial_path(o) }
@path = paths.uniq.one? ? paths.first : nil
else
@path = partial_path
end
end
if as = options[:as]
raise_invalid_option_as(as) unless as.to_s =~ /\A[a-z_]\w*\z/
as = as.to_sym
end
if @path
@variable, @variable_counter, @variable_iteration = retrieve_variable(@path, as)
@template_keys = retrieve_template_keys
else
paths.map! { |path| retrieve_variable(path, as).unshift(path) }
end
self
end