11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/jets/erb.rb', line 11
def result(path, variables={})
set_template_variables(variables)
template = IO.read(path)
begin
ERB.new(template, nil, "-").result(binding)
rescue Exception => e
puts e
puts e.backtrace if ENV['JETS_DEBUG']
error_info = e.message.split("\n").grep(/\(erb\)/)[0]
error_info ||= e.backtrace.grep(/\(erb\)/)[0]
raise unless error_info line = error_info.split(':')[1].to_i
puts "Error evaluating ERB template on line #{line.to_s.color(:red)} of: #{path.sub(/^\.\//, '').color(:green)}"
template_lines = template.split("\n")
context = 5 top, bottom = [line-context-1, 0].max, line+context-1
spacing = template_lines.size.to_s.size
template_lines[top..bottom].each_with_index do |line_content, index|
line_number = top+index+1
if line_number == line
printf("%#{spacing}d %s\n".color(:red), line_number, line_content)
else
printf("%#{spacing}d %s\n", line_number, line_content)
end
end
exit 1 unless Jets.env.test?
end
end
|