Module: Sinatra::Partials

Defined in:
lib/mongojob/web/helpers.rb

Overview

Copied and adapted to HAML from gist.github.com/119874 - thanks!

Instance Method Summary collapse

Instance Method Details

#partial(template, *args) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/mongojob/web/helpers.rb', line 32

def partial(template, *args)
  template_array = template.to_s.split('/')
  template = template_array[0..-2].join('/') + "/_#{template_array[-1]}"
  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_array[-1].to_sym => member}))
    end.join("\n")
  else
    haml(:"#{template}", options)
  end
end