12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/hogan_assets/tilt.rb', line 12
def evaluate(scope, locals, &block)
template_path = TemplatePath.new scope
template_namespace = HoganAssets::Config.template_namespace
text = if template_path.is_hamstache?
raise "Unable to compile #{template_path.full_path} because haml is not available. Did you add the haml gem?" unless HoganAssets::Config.haml_available?
Haml::Engine.new(data, HoganAssets::Config.haml_options.merge(@options)).render(scope, locals)
elsif template_path.is_slimstache?
raise "Unable to compile #{template_path.full_path} because slim is not available. Did you add the slim gem?" unless HoganAssets::Config.slim_available?
Slim::Template.new(HoganAssets::Config.slim_options.merge(@options)) { data }.render(scope, locals)
else
data
end
compiled_template = Hogan.compile(text)
template_name = scope.logical_path.inspect
text = '' unless HoganAssets::Config.lambda_support?
<<-TEMPLATE
this.#{template_namespace} || (this.#{template_namespace} = {});
this.#{template_namespace}[#{template_path.name}] = new Hogan.Template(#{compiled_template}, #{text.inspect}, Hogan, {});
TEMPLATE
end
|