123456789_123456789_123456789_123456789_123456789_

Exception: ActionView::Template::Error

Do not use. This class is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ::ActionView::ActionViewError, StandardError
Instance Chain:
self, ::ActionView::ActionViewError, StandardError
Inherits: ActionView::ActionViewError
Defined in: actionview/lib/action_view/template/error.rb

Overview

The 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

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(template) ⇒ Error

[ GitHub ]

  
# File 'actionview/lib/action_view/template/error.rb', line 162

def initialize(template)
  super($!.message)
  @cause = $!
  if @cause.is_a?(SyntaxError)
    @cause = ActiveSupport::SyntaxErrorProxy.new(@cause)
  end
  @template, @sub_templates = template, nil
end

Instance Attribute Details

#cause (readonly)

Override to prevent #cause resetting during re-raise.

[ GitHub ]

  
# File 'actionview/lib/action_view/template/error.rb', line 158

attr_reader :cause

#template (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/template/error.rb', line 160

attr_reader :template

Instance Method Details

#annotated_source_code

[ GitHub ]

  
# File 'actionview/lib/action_view/template/error.rb', line 220

def annotated_source_code
  source_extract(4)
end

#backtrace

[ GitHub ]

  
# File 'actionview/lib/action_view/template/error.rb', line 171

def backtrace
  @cause.backtrace
end

#backtrace_locations

[ GitHub ]

  
# File 'actionview/lib/action_view/template/error.rb', line 175

def backtrace_locations
  @cause.backtrace_locations
end

#file_name

[ GitHub ]

  
# File 'actionview/lib/action_view/template/error.rb', line 179

def file_name
  @template.identifier
end

#formatted_code_for(source_code, line_counter, indent) (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/template/error.rb', line 233

def formatted_code_for(source_code, line_counter, indent)
  indent_template = "%#{indent}s: %s"
  source_code.map do |line|
    line_counter += 1
    indent_template % [line_counter, line]
  end
end

#line_number

[ GitHub ]

  
# File 'actionview/lib/action_view/template/error.rb', line 212

def line_number
  @line_number ||=
    if file_name
      regexp = /#{Regexp.escape File.basename(file_name)}:(\d+)/
      $1 if message =~ regexp || backtrace.find { |line| line =~ regexp }
    end
end

#source_extract(indentation = 0)

[ GitHub ]

  
# File 'actionview/lib/action_view/template/error.rb', line 192

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

#source_location (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/template/error.rb', line 225

def source_location
  if line_number
    "on line ##{line_number} of "
  else
    "in "
  end + file_name
end

#sub_template_message

[ GitHub ]

  
# File 'actionview/lib/action_view/template/error.rb', line 183

def sub_template_message
  if @sub_templates
    "Trace of template inclusion: " +
    @sub_templates.collect(&:inspect).join(", ")
  else
    ""
  end
end

#sub_template_of(template_path)

[ GitHub ]

  
# File 'actionview/lib/action_view/template/error.rb', line 207

def sub_template_of(template_path)
  @sub_templates ||= []
  @sub_templates << template_path
end