Module: Helmet::Templates
- Included in:
- Handler
- Defined in:
- lib/helmet/templates.rb
Constant Summary collapse
- @@template_cache =
Tilt::Cache.new
Instance Method Summary collapse
- #erb(template, options = {}, locals = {}) ⇒ Object
- #render(engine, data, options = {}, locals = {}, &block) ⇒ Object
Instance Method Details
#erb(template, options = {}, locals = {}) ⇒ Object
8 9 10 |
# File 'lib/helmet/templates.rb', line 8 def erb(template, = {}, locals = {}) render(:erb, template, , 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, = {}, locals = {}, &block) layout = [:layout] layout = :layout if layout.nil? # force template update @@template_cache.clear unless Goliath.env == :production compiled_template = @@template_cache.fetch(data, ) do template = Tilt.new(find_template(engine, data), nil, ) end output = compiled_template.render(self, locals, &block) if layout begin .merge!(layout: false) return render(engine, layout, , locals) {output} rescue # Do nothing end end output end |