Module: Capcode::Helpers

Defined in:
lib/capcode/render/mustache.rb

Instance Method Summary collapse

Instance Method Details

#render_mustache(f, opts = {}) ⇒ Object

:nodoc:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/capcode/render/mustache.rb', line 9

def render_mustache( f, opts = {} ) #:nodoc:
  mustache_path = Capcode::Configuration.get( :mustache ) || Capcode.static() 
  
  name = Mustache.classify(f.to_s)
  
  if Capcode::Views.const_defined?(name)
    klass = Capcode::Views.const_get(name)
  else
    klass = Mustache
    klass.template_file = mustache_path + "/" + f.to_s + ".mustache"
  end
  
  klass.template_extension = 'mustache'
  klass.template_path = mustache_path
  
  instance = klass.new
  
  instance_variables.each do |name|
    instance.instance_variable_set(name, instance_variable_get(name))
  end

  opts.each do |k, v|
    instance[k] = v
  end
  
  instance.to_html
end