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
|
# 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
else
data
end
if HandlebarsAssets::Config.ember?
"window.Ember.TEMPLATES[#{template_path.name}] = Ember.Handlebars.compile(#{source.to_json});"
else
compiled_hbs = Handlebars.precompile(source, HandlebarsAssets::Config.options)
template_namespace = HandlebarsAssets::Config.template_namespace
if template_path.is_partial?
unindent <<-PARTIAL
(function() {
Handlebars.registerPartial(#{template_path.name}, Handlebars.template(#{compiled_hbs}));
}).call(this);
PARTIAL
else
unindent <<-TEMPLATE
(function() {
this.#{template_namespace} || (this.#{template_namespace} = {});
this.#{template_namespace}[#{template_path.name}] = Handlebars.template(#{compiled_hbs});
return this.#{template_namespace}[#{template_path.name}];
}).call(this);
TEMPLATE
end
end
end
|