diff options
author | Guillermo Iguaran <guilleiguaran@gmail.com> | 2012-12-31 14:36:23 -0500 |
---|---|---|
committer | Guillermo Iguaran <guilleiguaran@gmail.com> | 2012-12-31 16:46:37 -0500 |
commit | 5a1b885dd620e6ab465c0f64b7cd0f025a46fb37 (patch) | |
tree | 00e54e1e794cf7440b3f74a04d39b8380b886c63 /actionpack/lib/action_view/template | |
parent | 9b79bb469b02c9c51440960cfc33bd928c9fbd1d (diff) | |
download | rails-5a1b885dd620e6ab465c0f64b7cd0f025a46fb37.tar.gz rails-5a1b885dd620e6ab465c0f64b7cd0f025a46fb37.tar.bz2 rails-5a1b885dd620e6ab465c0f64b7cd0f025a46fb37.zip |
Add style to AV::Template::Error exception page
Diffstat (limited to 'actionpack/lib/action_view/template')
-rw-r--r-- | actionpack/lib/action_view/template/error.rb | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/actionpack/lib/action_view/template/error.rb b/actionpack/lib/action_view/template/error.rb index e00056781d..662e1ac66b 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,12 +88,20 @@ 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| + formatted_code_for(source_code, start_on_line, indent, output) + 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 - "%#{indent}s: %s\n" % [line_counter, line] + 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 |