Skip to content

Instantly share code, notes, and snippets.

@cschneid
Created September 25, 2008 18:20
Show Gist options
  • Save cschneid/12882 to your computer and use it in GitHub Desktop.
Save cschneid/12882 to your computer and use it in GitHub Desktop.
require "sinatra"
require "partials"
helpers do
include Sinatra::Partials
end
module Sinatra
module Partials
def partial(template, *args)
options = args.extract_options!
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
erb(template, options)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment