aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2013-01-01 02:14:23 -0800
committerDavid Heinemeier Hansson <david@loudthinking.com>2013-01-01 02:14:23 -0800
commit8d945f4f97748bfc5083fe1d0020368598a79e47 (patch)
treeddcd90f0bc2c43b76955a2145121f95e4a5fea77 /actionpack/lib/action_view
parent56aa02f1ab66cfda8f5c8bdbd088dfd38b633cb7 (diff)
parent25c8770a6cbbc4922446085addaa5a41d0e4e1b6 (diff)
downloadrails-8d945f4f97748bfc5083fe1d0020368598a79e47.tar.gz
rails-8d945f4f97748bfc5083fe1d0020368598a79e47.tar.bz2
rails-8d945f4f97748bfc5083fe1d0020368598a79e47.zip
Merge pull request #8668 from guilleiguaran/exceptions
New exceptions pages for development
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r--actionpack/lib/action_view/template/error.rb20
1 files changed, 14 insertions, 6 deletions
diff --git a/actionpack/lib/action_view/template/error.rb b/actionpack/lib/action_view/template/error.rb
index e00056781d..b479f991bc 100644
--- a/actionpack/lib/action_view/template/error.rb
+++ b/actionpack/lib/action_view/template/error.rb
@@ -78,7 +78,7 @@ module ActionView
end
end
- def source_extract(indentation = 0)
+ def source_extract(indentation = 0, output = :console)
return unless num = line_number
num = num.to_i
@@ -88,13 +88,9 @@ module ActionView
end_on_line = [ num + SOURCE_CODE_RADIUS - 1, source_code.length].min
indent = end_on_line.to_s.size + indentation
- line_counter = start_on_line
return unless source_code = source_code[start_on_line..end_on_line]
- source_code.sum do |line|
- line_counter += 1
- "%#{indent}s: %s\n" % [line_counter, line]
- end
+ formatted_code_for(source_code, start_on_line, indent, output)
end
def sub_template_of(template_path)
@@ -123,6 +119,18 @@ module ActionView
'in '
end + file_name
end
+
+ 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
end
end