class Rasti::Web::Template

Public Class Methods

render(template, context=nil, locals={}, &block) click to toggle source
# File lib/rasti/web/template.rb, line 5
def self.render(template, context=nil, locals={}, &block)
  files = Web.template_engines.map { |e| File.join Web.views_path, "#{template}.#{e}" }
  template_file = files.detect { |f| File.exists? f }

  raise "Missing template #{template} [#{files.join(', ')}]" unless template_file

  tilt = cache.fetch(template_file) { Tilt.new template_file }
  tilt.render(context, locals, &block)
end

Private Class Methods

cache() click to toggle source
# File lib/rasti/web/template.rb, line 17
def self.cache
  Thread.current[:templates_cache] ||= Tilt::Cache.new
end