Skip to content

Instantly share code, notes, and snippets.

@tomdavies
Forked from lenary/partials.rb
Created January 13, 2012 10:51
Show Gist options
  • Select an option

  • Save tomdavies/1605514 to your computer and use it in GitHub Desktop.

Select an option

Save tomdavies/1605514 to your computer and use it in GitHub Desktop.
# 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 = template.split('/')[0..-2].join('/') + "/_#{template.split('/')[-1]}"
erb(:"#{template}", options)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment