22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/handlebars_assets/tilt_handlebars.rb', line 22
def evaluate(scope, locals, &block)
template_path = TemplatePath.new(scope)
source = if template_path.is_haml?
Haml::Engine.new(data, HandlebarsAssets::Config.haml_options).render
elsif template_path.is_slim?
Slim::Template.new(HandlebarsAssets::Config.slim_options) { data }.render
else
data
end
if HandlebarsAssets::Config.ember?
"window.Ember.TEMPLATES[#{template_path.name}] = Ember.Handlebars.compile(#{MultiJson.dump source});"
else
compiled_hbs = Handlebars.precompile(source, HandlebarsAssets::Config.options)
template_namespace = HandlebarsAssets::Config.template_namespace
if template_path.is_partial?
unindent " (function() {\n Handlebars.registerPartial(\#{template_path.name}, Handlebars.template(\#{compiled_hbs}));\n }).call(this);\n PARTIAL\n else\n unindent <<-TEMPLATE\n (function() {\n this.\#{template_namespace} || (this.\#{template_namespace} = {});\n this.\#{template_namespace}[\#{template_path.name}] = Handlebars.template(\#{compiled_hbs});\n return this.\#{template_namespace}[\#{template_path.name}];\n }).call(this);\n TEMPLATE\n end\n end\nend\n"
|