Exception: ActionView::Template::Error
- Inherits:
-
ActionViewError
- Object
- StandardError
- ActionViewError
- ActionView::Template::Error
- Defined in:
- actionpack/lib/action_view/template/error.rb
Overview
The Template::Error exception is raised when the compilation of the template fails. This exception then gathers a bunch of intimate details and uses it to report a very precise exception message.
Constant Summary
- SOURCE_CODE_RADIUS =
:nodoc:
3
Instance Attribute Summary (collapse)
-
- (Object) backtrace
readonly
Returns the value of attribute backtrace.
-
- (Object) original_exception
readonly
Returns the value of attribute original_exception.
Instance Method Summary (collapse)
- - (Object) annoted_source_code
- - (Object) file_name
-
- (Error) initialize(template, assigns, original_exception)
constructor
A new instance of Error.
- - (Object) line_number
- - (Object) message
- - (Object) source_extract(indentation = 0)
- - (Object) sub_template_message
- - (Object) sub_template_of(template_path)
Constructor Details
- (Error) initialize(template, assigns, original_exception)
A new instance of Error
53 54 55 56 |
# File 'actionpack/lib/action_view/template/error.rb', line 53 def initialize(template, assigns, original_exception) @template, @assigns, @original_exception = template, assigns.dup, original_exception @backtrace = original_exception.backtrace end |
Instance Attribute Details
- (Object) backtrace (readonly)
Returns the value of attribute backtrace
51 52 53 |
# File 'actionpack/lib/action_view/template/error.rb', line 51 def backtrace @backtrace end |
- (Object) original_exception (readonly)
Returns the value of attribute original_exception
51 52 53 |
# File 'actionpack/lib/action_view/template/error.rb', line 51 def original_exception @original_exception end |
Instance Method Details
- (Object) annoted_source_code
107 108 109 |
# File 'actionpack/lib/action_view/template/error.rb', line 107 def annoted_source_code source_extract(4) end |
- (Object) file_name
58 59 60 |
# File 'actionpack/lib/action_view/template/error.rb', line 58 def file_name @template.identifier end |
- (Object) line_number
99 100 101 102 103 104 105 |
# File 'actionpack/lib/action_view/template/error.rb', line 99 def line_number @line_number ||= if file_name regexp = /#{Regexp.escape File.basename(file_name)}:(\d+)/ $1 if =~ regexp || backtrace.find { |line| line =~ regexp } end end |
- (Object) message
62 63 64 |
# File 'actionpack/lib/action_view/template/error.rb', line 62 def ActiveSupport::Deprecation.silence { original_exception. } end |
- (Object) source_extract(indentation = 0)
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'actionpack/lib/action_view/template/error.rb', line 75 def source_extract(indentation = 0) return unless num = line_number num = num.to_i source_code = @template.source.split("\n") start_on_line = [ num - SOURCE_CODE_RADIUS - 1, 0 ].max end_on_line = [ num + SOURCE_CODE_RADIUS - 1, source_code.length].min indent = ' ' * indentation line_counter = start_on_line return unless source_code = source_code[start_on_line..end_on_line] source_code.sum do |line| line_counter += 1 "#{indent}#{line_counter}: #{line}\n" end end |
- (Object) sub_template_message
66 67 68 69 70 71 72 73 |
# File 'actionpack/lib/action_view/template/error.rb', line 66 def if @sub_templates "Trace of template inclusion: " + @sub_templates.collect { |template| template.inspect }.join(", ") else "" end end |
- (Object) sub_template_of(template_path)
94 95 96 97 |
# File 'actionpack/lib/action_view/template/error.rb', line 94 def sub_template_of(template_path) @sub_templates ||= [] @sub_templates << template_path end |