Module: Sinatra::Partials
- Defined in:
- lib/mongodb_logger/server/helpers/partials.rb
Overview
stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb
and made a lot more robust by me
this implementation uses erb by default. if you want to use any other template mechanism
then replace erb on line 13 and line 17 with haml or whatever
Instance Method Summary collapse
Instance Method Details
#partial(template, *args) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/mongodb_logger/server/helpers/partials.rb', line 6 def partial(template, *args) template_array = template.to_s.split('/') template = template_array[0..-2].join('/') + "/_#{template_array[-1]}" = args.last.is_a?(Hash) ? args.pop : {} .merge!(:layout => false) locals = [:locals] || {} if collection = .delete(:collection) collection.inject([]) do |buffer, member| buffer << erb(:"#{template}", .merge(:layout => false, :locals => {template_array[-1].to_sym => member}.merge(locals))) end.join("\n") elsif partial_object = .delete(:object) erb(:"#{template}", .merge(:layout => false, :locals => {template_array[-1].to_sym => partial_object}).merge(locals)) else erb(:"#{template}", ) end end |