9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/handlebars_assets/tilt_handlebars.rb', line 9
def evaluate(scope, locals, &block)
name = basename(scope.logical_path)
compiled_hbs = Handlebars.precompile(data)
if name.start_with?('_')
partial_name = name[1..-1].inspect
<<-PARTIAL
(function() {
Handlebars.registerPartial(#{partial_name}, Handlebars.template(#{compiled_hbs}));
}).call(this);
PARTIAL
else
template_name = scope.logical_path.inspect
<<-TEMPLATE
(function() {
this.HandlebarsTemplates || (this.HandlebarsTemplates = {});
this.HandlebarsTemplates[#{template_name}] = Handlebars.template(#{compiled_hbs});
return HandlebarsTemplates[#{template_name}];
}).call(this);
TEMPLATE
end
end
|