public
Last active — forked from lenary/partials.rb

  • Download Gist
partials.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb
module Sinatra::Partials
def partial(template, *args)
options = args.last.is_a?(Hash) ? args.pop : {}
options.merge!(:layout => false)
if collection = options.delete(:collection) then
collection.inject([]) do |buffer, member|
buffer << erb(template, options.merge(:layout =>
false, :locals => {template.to_sym => member}))
end.join("\n")
else
template_array = template.to_s.split('/')
template = template_array[0..-2].join('/') + "/_#{template_array[-1]}"
erb(:"#{template}", options)
end
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.