Sha256: 3c1d6c587906e5204fe0c31e59f4519e4c21e8ee90bec1d76398724f831f25ba

Contents?: true

Size: 604 Bytes

Versions: 1

Compression:

Stored size: 604 Bytes

Contents

module Rasti
  module Web
    class Template

      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

      def self.cache
        Thread.current[:templates_cache] ||= Tilt::Cache.new
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rasti-web-2.1.0 lib/rasti/web/template.rb