Module: Broadway::Helpers::PartialHelper

Defined in:
lib/broadway/sinatra/helpers/partial_helper.rb

Instance Method Summary collapse

Instance Method Details

#partial(template, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/broadway/sinatra/helpers/partial_helper.rb', line 5

def partial(template, options = {})
  template = template.to_s.squeeze("/")
  options.symbolize_keys!
  options.merge!(:layout => false)
  template_array = template.to_s.split('/')
  template = "_#{template_array[-1]}"
  local_template = File.join(request.env["PATH_INFO"][1..-1], template)
  template = local_template if File.exists?(File.join("public", local_template) + ".haml")
  template = template_array[0..-2].join('/') + "/#{template}"
  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

#theme_partial(template, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/broadway/sinatra/helpers/partial_helper.rb', line 24

def theme_partial(template, options = {})
  theme = File.join(c(:theme_path), c(:theme))
  version = nil
  if options.has_key?(:locals) and options[:locals].has_key?(:theme_version)
    version = options[:locals][:theme_version]
  else
    version = "main"
  end
  partial(File.join(theme, version, template.to_s), options)
end