SinatraとHamlでRailsっぽくPartialする

helpers do
  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 << haml(template, options.merge(:layout => false, :locals => {template => member}))
      end.join("\n")
    else
      haml(template, options)
    end
  end
end
-# items.haml
= partial :item, :collection => @items
-# item.haml
%p= item.id
%p= item.name

参考
Sinatra: Frequently Asked Questions
Sinatra Book