vendor/rails/actionpack/lib/action_view/template_error.rb in radiant-0.7.2 vs vendor/rails/actionpack/lib/action_view/template_error.rb in radiant-0.8.0
- old
+ new
@@ -5,49 +5,55 @@
SOURCE_CODE_RADIUS = 3
attr_reader :original_exception
def initialize(template, assigns, original_exception)
- @base_path = template.base_path_for_exception
- @assigns, @source, @original_exception = assigns.dup, template.source, original_exception
- @file_path = template.filename
+ @template, @assigns, @original_exception = template, assigns.dup, original_exception
@backtrace = compute_backtrace
end
+ def file_name
+ @template.relative_path
+ end
+
def message
ActiveSupport::Deprecation.silence { original_exception.message }
end
def clean_backtrace
- original_exception.clean_backtrace
+ if defined?(Rails) && Rails.respond_to?(:backtrace_cleaner)
+ Rails.backtrace_cleaner.clean(original_exception.backtrace)
+ else
+ original_exception.backtrace
+ end
end
def sub_template_message
if @sub_templates
"Trace of template inclusion: " +
- @sub_templates.collect { |template| strip_base_path(template) }.join(", ")
+ @sub_templates.collect { |template| template.relative_path }.join(", ")
else
""
end
end
def source_extract(indentation = 0)
return unless num = line_number
num = num.to_i
- source_code = IO.readlines(@file_path)
+ 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]
-
+ return unless source_code = source_code[start_on_line..end_on_line]
+
source_code.sum do |line|
line_counter += 1
- "#{indent}#{line_counter}: #{line}"
+ "#{indent}#{line_counter}: #{line}\n"
end
end
def sub_template_of(template_path)
@sub_templates ||= []
@@ -61,19 +67,13 @@
$1 if message =~ regexp or clean_backtrace.find { |line| line =~ regexp }
end
end
- def file_name
- stripped = strip_base_path(@file_path)
- stripped.slice!(0,1) if stripped[0] == ?/
- stripped
- end
-
def to_s
- "\n\n#{self.class} (#{message}) #{source_location}:\n" +
- "#{source_extract}\n #{clean_backtrace.join("\n ")}\n\n"
+ "\n#{self.class} (#{message}) #{source_location}:\n" +
+ "#{source_extract}\n #{clean_backtrace.join("\n ")}\n\n"
end
# don't do anything nontrivial here. Any raised exception from here becomes fatal
# (and can't be rescued).
def backtrace
@@ -86,25 +86,14 @@
"#{source_location.capitalize}\n\n#{source_extract(4)}\n " +
clean_backtrace.join("\n ")
]
end
- def strip_base_path(path)
- stripped_path = File.expand_path(path).gsub(@base_path, "")
- stripped_path.gsub!(/^#{Regexp.escape File.expand_path(RAILS_ROOT)}/, '') if defined?(RAILS_ROOT)
- stripped_path
- end
-
def source_location
if line_number
"on line ##{line_number} of "
else
'in '
end + file_name
end
end
-end
-
-if defined?(Exception::TraceSubstitutions)
- Exception::TraceSubstitutions << [/:in\s+`_run_(html|xml).*'\s*$/, '']
- Exception::TraceSubstitutions << [%r{^\s*#{Regexp.escape RAILS_ROOT}/}, ''] if defined?(RAILS_ROOT)
-end
+end
\ No newline at end of file