Sha256: 943e1b5689a48d27d1e8144984b1eaa1783ad618fd0d4a6ba6ff5362d59e427a
Contents?: true
Size: 1.02 KB
Versions: 1
Compression:
Stored size: 1.02 KB
Contents
require 'tilt' module Luca class Template < Tilt::Template def self.namespace 'JST' end def self.default_mime_type 'application/javascript' end def self.engine_initialized? defined? ::EJS defined? ::Haml end def initialize_engine require_template_library 'ejs' require_template_library 'haml' end def prepare options = @options.merge(:filename => eval_file, :line => line, :escape_attrs => false) @engine = ::Haml::Engine.new(data, options) end def evaluate(scope, locals, &block) compiled = @engine.render(scope, locals, &block) code = EJS.compile(compiled) tmpl = scope.logical_path namespace = self.class.namespace tmpl.gsub! /^.*\/templates\//, '' <<-JST (function() {#{namespace} || (#{namespace} = {}); #{namespace}[#{ tmpl.inspect }] = #{indent(code)}; }).call(this); JST end private def indent(string) string.gsub(/$(.)/m, "\\1 ").strip end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
luca-0.9.4 | lib/luca/template.rb |