def partial(template, opts={})
template = template.to_s
if template =~ %r{^/}
template_path = File.dirname(template) / "_#{File.basename(template)}"
else
kontroller = (m = template.match(/.*(?=\/)/)) ? m[0] : controller_name
end
template = "_#{File.basename(template)}"
with = [opts.delete(:with)].flatten
as = (opts.delete(:as) || template.match(%r[(?:.*/)?_([^\./]*)])[1]).to_sym
locals = opts.merge(:collection_index => -1, :collection_size => with.size, as => opts[as])
template_method, template_location = _template_for(
template,
opts.delete(:format) || content_type,
kontroller,
template_path,
locals.keys)
named_local = opts.key?(as)
sent_template = with.map do |temp|
locals[as] = temp unless named_local
if template_method && self.respond_to?(template_method)
locals[:collection_index] += 1
send(template_method, locals)
else
raise TemplateNotFound, "Could not find template at #{template_location}.*"
end
end.join
sent_template
end