class ActionView::Template::Error
:nodoc:
precise exception message.
fails. This exception then gathers a bunch of intimate details and uses it to report a
The Template::Error exception is raised when the compilation or rendering of the template
def annoted_source_code
def annoted_source_code source_extract(4) end
def file_name
def file_name @template.identifier end
def formatted_code_for(source_code, line_counter, indent, output)
def formatted_code_for(source_code, line_counter, indent, output) start_value = (output == :html) ? {} : "" source_code.inject(start_value) do |result, line| line_counter += 1 if output == :html result.update(line_counter.to_s => "%#{indent}s %s\n" % ["", line]) else result << "%#{indent}s: %s\n" % [line_counter, line] end end end
def initialize(template, original_exception)
def initialize(template, original_exception) super(original_exception.message) @template, @original_exception = template, original_exception @sub_templates = nil set_backtrace(original_exception.backtrace) end
def line_number
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
def source_extract(indentation = 0, output = :console)
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
def source_location
def source_location if line_number "on line ##{line_number} of " else 'in ' end + file_name end
def sub_template_message
def sub_template_message if @sub_templates "Trace of template inclusion: " + @sub_templates.collect { |template| template.inspect }.join(", ") else "" end end
def sub_template_of(template_path)
def sub_template_of(template_path) @sub_templates ||= [] @sub_templates << template_path end