Sha256: 609fdacb46067049db10048ed084091ab31acee0983ac0b70e15bd13f0d899c9

Contents?: true

Size: 910 Bytes

Versions: 5

Compression:

Stored size: 910 Bytes

Contents

require 'tilt'

module Helmet
  module Templates
    
    @@template_cache = Tilt::Cache.new
        
    def erb(template, options = {}, locals = {})
     render(:erb, template, options, locals) 
    end

    def render(engine, data, options = {}, locals = {}, &block)
      layout = options.delete(:layout)
      # 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
        return render(engine, layout, options, locals) {output}
      end
      output
    end
    
    private 
    
    def find_template(engine, template)
      filename = "#{template.to_s}.#{engine.to_s}"
      File.join(@klass.config(:views_folder), filename)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
helmet-0.2.0 lib/helmet/templates.rb
helmet-0.1.3 lib/helmet/templates.rb
helmet-0.1.2 lib/helmet/templates.rb
helmet-0.1.1 lib/helmet/templates.rb
helmet-0.1.0 lib/helmet/templates.rb