Module: Lono::Template::Evaluate
- Included in:
- Dsl::Builder, Erb
- Defined in:
- lib/lono/template/evaluate.rb
Instance Method Summary collapse
- #evaluate_template_path(path) ⇒ Object
-
#template_evaluation_error(e) ⇒ Object
Prints out a user friendly task_definition error message.
Instance Method Details
#evaluate_template_path(path) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/lono/template/evaluate.rb', line 3 def evaluate_template_path(path) return unless File.exist?(path) begin instance_eval(File.read(path), path) rescue Exception => e template_evaluation_error(e) puts "\nFull error:" raise end end |
#template_evaluation_error(e) ⇒ Object
Prints out a user friendly task_definition error message
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/lono/template/evaluate.rb', line 16 def template_evaluation_error(e) error_info = e.backtrace.first path, line_no, _ = error_info.split(':') line_no = line_no.to_i puts "Error evaluating #{path}:".color(:red) puts e. puts "Here's the line in #{path} with the error:\n\n" contents = IO.read(path) content_lines = contents.split("\n") context = 5 # lines of context top, bottom = [line_no-context-1, 0].max, line_no+context-1 spacing = content_lines.size.to_s.size content_lines[top..bottom].each_with_index do |line_content, index| line_number = top+index+1 if line_number == line_no printf("%#{spacing}d %s\n".color(:red), line_number, line_content) else printf("%#{spacing}d %s\n", line_number, line_content) end end end |