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
- 
  
    
      #cause  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Override to prevent #cause resetting during re-raise.
 - 
  
    
      #template  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute template.
 
Instance Method Summary collapse
- #annotated_source_code ⇒ Object
 - #backtrace ⇒ Object
 - #backtrace_locations ⇒ Object
 - #file_name ⇒ Object
 - 
  
    
      #initialize(template)  ⇒ Error 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Error.
 - #line_number ⇒ Object
 - #source_extract(indentation = 0) ⇒ Object
 - #sub_template_message ⇒ Object
 - #sub_template_of(template_path) ⇒ Object
 
Constructor Details
#initialize(template) ⇒ Error
Returns a new instance of Error.
      173 174 175 176 177 178 179 180  | 
    
      # File 'actionview/lib/action_view/template/error.rb', line 173 def initialize(template) super($!.) @cause = $! if @cause.is_a?(SyntaxError) @cause = ActiveSupport::SyntaxErrorProxy.new(@cause) end @template, @sub_templates = template, nil end  | 
  
Instance Attribute Details
#cause ⇒ Object (readonly)
Override to prevent #cause resetting during re-raise.
      169 170 171  | 
    
      # File 'actionview/lib/action_view/template/error.rb', line 169 def cause @cause end  | 
  
#template ⇒ Object (readonly)
Returns the value of attribute template.
      171 172 173  | 
    
      # File 'actionview/lib/action_view/template/error.rb', line 171 def template @template end  | 
  
Instance Method Details
#annotated_source_code ⇒ Object
      231 232 233  | 
    
      # File 'actionview/lib/action_view/template/error.rb', line 231 def annotated_source_code source_extract(4) end  | 
  
#backtrace ⇒ Object
      182 183 184  | 
    
      # File 'actionview/lib/action_view/template/error.rb', line 182 def backtrace @cause.backtrace end  | 
  
#backtrace_locations ⇒ Object
      186 187 188  | 
    
      # File 'actionview/lib/action_view/template/error.rb', line 186 def backtrace_locations @cause.backtrace_locations end  | 
  
#file_name ⇒ Object
      190 191 192  | 
    
      # File 'actionview/lib/action_view/template/error.rb', line 190 def file_name @template.identifier end  | 
  
#line_number ⇒ Object
      223 224 225 226 227 228 229  | 
    
      # File 'actionview/lib/action_view/template/error.rb', line 223 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) ⇒ Object
      203 204 205 206 207 208 209 210 211 212 213 214 215 216  | 
    
      # File 'actionview/lib/action_view/template/error.rb', line 203 def source_extract(indentation = 0) return [] unless num = line_number num = num.to_i source_code = @template.encode!.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) end  | 
  
#sub_template_message ⇒ Object
      194 195 196 197 198 199 200 201  | 
    
      # File 'actionview/lib/action_view/template/error.rb', line 194 def if @sub_templates "Trace of template inclusion: " + @sub_templates.collect(&:inspect).join(", ") else "" end end  | 
  
#sub_template_of(template_path) ⇒ Object
      218 219 220 221  | 
    
      # File 'actionview/lib/action_view/template/error.rb', line 218 def sub_template_of(template_path) @sub_templates ||= [] @sub_templates << template_path end  |