Module: Helmet::Templates

Included in:
Handler
Defined in:
lib/helmet/templates.rb

Constant Summary collapse

@@template_cache =
Tilt::Cache.new

Instance Method Summary collapse

Instance Method Details

#erb(template, options = {}, locals = {}) ⇒ Object



8
9
10
# File 'lib/helmet/templates.rb', line 8

def erb(template, options = {}, locals = {})
  render(:erb, template, options, locals) 
end

#render(engine, data, options = {}, locals = {}, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/helmet/templates.rb', line 12

def render(engine, data, options = {}, locals = {}, &block)
  layout = options[:layout]
  layout = :layout if layout.nil?
  # force template update
  @@template_cache.clear unless Goliath.env == :production
  compiled_template = @@template_cache.fetch(data, options) do
    template = Tilt.new(find_template(engine, data), nil, options)
  end
  output = compiled_template.render(self, locals, &block)
  if layout
    begin
      options.merge!(layout: false)
      return render(engine, layout, options, locals) {output}
    rescue 
      # Do nothing
    end
  end
  output
end