aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/template/error.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionview/lib/action_view/template/error.rb')
-rw-r--r--actionview/lib/action_view/template/error.rb24
1 files changed, 22 insertions, 2 deletions
diff --git a/actionview/lib/action_view/template/error.rb b/actionview/lib/action_view/template/error.rb
index 4e3c02e05e..aace0be04d 100644
--- a/actionview/lib/action_view/template/error.rb
+++ b/actionview/lib/action_view/template/error.rb
@@ -104,12 +104,12 @@ module ActionView
def line_number
@line_number ||=
if file_name
- regexp = /#{Regexp.escape File.basename(file_name)}:(\d+)/
+ regexp = /#{Regexp.escape ::File.basename(file_name)}:(\d+)/
$1 if message =~ regexp || backtrace.find { |line| line =~ regexp }
end
end
- def annoted_source_code
+ def annotated_source_code
source_extract(4)
end
@@ -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 annotated_source_code
+ @offending_code_string.split("\n").map.with_index(1) { |line, index|
+ indentation = " " * 4
+ "#{index}:#{indentation}#{line}"
+ }
+ end
+ end
end