From 07804d4759726da04020834502d37a8f4ac97a8f Mon Sep 17 00:00:00 2001 From: Eli Rose Date: Sun, 17 Feb 2019 23:07:16 -0500 Subject: Add handling and tests. --- actionview/lib/action_view/template/error.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'actionview/lib/action_view/template/error.rb') diff --git a/actionview/lib/action_view/template/error.rb b/actionview/lib/action_view/template/error.rb index 4e3c02e05e..ff01e4cd83 100644 --- a/actionview/lib/action_view/template/error.rb +++ b/actionview/lib/action_view/template/error.rb @@ -138,4 +138,24 @@ module ActionView end TemplateError = Template::Error + + class SyntaxErrorInTemplate < TemplateError #:nodoc + def initialize(template, offending_code_string) + @offending_code_string = offending_code_string + super(template) + end + + def message + <<~MESSAGE + Encountered a syntax error while rendering template: check #{@offending_code_string} + MESSAGE + end + + def annoted_source_code + @offending_code_string.split("\n").map.with_index(1) { |line, index| + indentation = " " * 4 + "#{index}:#{indentation}#{line}" + } + end + end end -- cgit v1.2.3