module Padrino::Helpers::RenderHelpers
def partial(template, options={})
- Api: - public
Other tags:
- Note: - If using this from Sinatra, pass explicit +:engine+ option
Returns:
-
(String)
- The html generated from this partial.
Options Hash:
(**options)
-
:engine
(Symbol
) -- -
:locals
(Hash
) -- -
:collection
(Array
) -- -
:object
(Object
) --
Parameters:
-
options
(Hash
) -- -
template
(String
) --
def partial(template, options={}) options.reverse_merge!(:locals => {}, :layout => false) path = template.to_s.split(File::SEPARATOR) object_name = path[-1].to_sym path[-1] = "_#{path[-1]}" explicit_engine = options.delete(:engine) template_path = File.join(path).to_sym raise 'Partial collection specified but is nil' if options.has_key?(:collection) && options[:collection].nil? if collection = options.delete(:collection) options.delete(:object) counter = 0 collection.map { |member| counter += 1 options[:locals].merge!(object_name => member, "#{object_name}_counter".to_sym => counter) render(explicit_engine, template_path, options.dup) }.join("\n").html_safe else if member = options.delete(:object) options[:locals].merge!(object_name => member) end render(explicit_engine, template_path, options.dup).html_safe end end