Exception: ActionView::Template::Error
- Inherits:
-
ActionViewError
- Object
- StandardError
- ActionViewError
- ActionView::Template::Error
- Defined in:
- actionview/lib/action_view/template/error.rb
Overview
The Template::Error exception is raised when the compilation or rendering of the template fails. This exception then gathers a bunch of intimate details and uses it to report a precise exception message.
Constant Summary collapse
- SOURCE_CODE_RADIUS =
:nodoc:
3
Instance Attribute Summary collapse
-
#original_exception ⇒ Object
readonly
Returns the value of attribute original_exception.
Instance Method Summary collapse
- #annoted_source_code ⇒ Object
- #file_name ⇒ Object
-
#initialize(template, original_exception) ⇒ Error
constructor
A new instance of Error.
- #line_number ⇒ Object
- #source_extract(indentation = 0, output = :console) ⇒ Object
- #sub_template_message ⇒ Object
- #sub_template_of(template_path) ⇒ Object
Constructor Details
#initialize(template, original_exception) ⇒ Error
Returns a new instance of Error.
64 65 66 67 68 69 |
# File 'actionview/lib/action_view/template/error.rb', line 64 def initialize(template, original_exception) super(original_exception.) @template, @original_exception = template, original_exception @sub_templates = nil set_backtrace(original_exception.backtrace) end |
Instance Attribute Details
#original_exception ⇒ Object (readonly)
Returns the value of attribute original_exception
62 63 64 |
# File 'actionview/lib/action_view/template/error.rb', line 62 def original_exception @original_exception end |
Instance Method Details
#annoted_source_code ⇒ Object
112 113 114 |
# File 'actionview/lib/action_view/template/error.rb', line 112 def annoted_source_code source_extract(4) end |
#file_name ⇒ Object
71 72 73 |
# File 'actionview/lib/action_view/template/error.rb', line 71 def file_name @template.identifier end |
#line_number ⇒ Object
104 105 106 107 108 109 110 |
# File 'actionview/lib/action_view/template/error.rb', line 104 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 |
#source_extract(indentation = 0, output = :console) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'actionview/lib/action_view/template/error.rb', line 84 def source_extract(indentation = 0, output = :console) 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 = end_on_line.to_s.size + indentation return unless source_code = source_code[start_on_line..end_on_line] formatted_code_for(source_code, start_on_line, indent, output) end |
#sub_template_message ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'actionview/lib/action_view/template/error.rb', line 75 def if @sub_templates "Trace of template inclusion: " + @sub_templates.collect { |template| template.inspect }.join(", ") else "" end end |
#sub_template_of(template_path) ⇒ Object
99 100 101 102 |
# File 'actionview/lib/action_view/template/error.rb', line 99 def sub_template_of(template_path) @sub_templates ||= [] @sub_templates << template_path end |