Module: Sinatra::Partials
- Defined in:
- lib/sinatra/partials.rb
Overview
Code available from Sinatra recipes github.com/sinatra/sinatra-recipes/blob/70c1b997673344fccbc35c15e7bde3a9e06468c5/helpers/partials.md
Instance Method Summary collapse
Instance Method Details
#partial(template, *args) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sinatra/partials.rb', line 5 def partial(template, *args) key="partial_#{template}_#{args.to_s}" template_array = template.to_s.split('/') template = template_array[0..-2].join('/') + "/_#{template_array[-1]}" = args.last.is_a?(Hash) ? args.pop : {} cache_option = .delete(:cache) .merge!(:layout => false, :escape_html=>false) lambda_func=lambda { if collection = .delete(:collection) then collection.inject([]) do |buffer, member| buffer << haml(:"#{template}", .merge(:layout => false, :locals => {template_array[-1].to_sym => member})) end.join("\n") else haml(:"#{template}", ) end } #$log.info("#{template}, #{options}") if false and cache_option if $cache.exists?(key) $cache.get(key) else out=lambda_func.call() $cache.put(key, out) out end else lambda_func.call() end end |