diff options
author | Gannon McGibbon <gannon.mcgibbon@gmail.com> | 2019-07-15 11:34:27 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-15 11:34:27 -0400 |
commit | 88b91299f3fc5b912e10323ed0ad18c87c7584e5 (patch) | |
tree | 24958b6a3e529d3874d1272232737b525827a1d3 /actionview/lib | |
parent | 0dc6527a8be9e2cf74162574b56ef3e84c4b6969 (diff) | |
parent | 526a5eb10cbe6092389c07c9529eb44c50fb0af6 (diff) | |
download | rails-88b91299f3fc5b912e10323ed0ad18c87c7584e5.tar.gz rails-88b91299f3fc5b912e10323ed0ad18c87c7584e5.tar.bz2 rails-88b91299f3fc5b912e10323ed0ad18c87c7584e5.zip |
Merge pull request #36532 from itsWill/add_to_a_to_annotated_source_code
Empty array instead of nil for source_extract
Diffstat (limited to 'actionview/lib')
-rw-r--r-- | actionview/lib/action_view/template/error.rb | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/actionview/lib/action_view/template/error.rb b/actionview/lib/action_view/template/error.rb index feceef15f9..7fc74a5502 100644 --- a/actionview/lib/action_view/template/error.rb +++ b/actionview/lib/action_view/template/error.rb @@ -81,8 +81,8 @@ module ActionView end end - def source_extract(indentation = 0, output = :console) - return unless num = line_number + def source_extract(indentation = 0) + return [] unless num = line_number num = num.to_i source_code = @template.source.split("\n") @@ -91,9 +91,9 @@ module ActionView 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] + return [] unless source_code = source_code[start_on_line..end_on_line] - formatted_code_for(source_code, start_on_line, indent, output) + formatted_code_for(source_code, start_on_line, indent) end def sub_template_of(template_path) @@ -122,15 +122,11 @@ module ActionView 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| + def formatted_code_for(source_code, line_counter, indent) + indent_template = "%#{indent}s: %s" + source_code.map do |line| line_counter += 1 - if output == :html - result.update(line_counter.to_s => "%#{indent}s %s\n" % ["", line]) - else - result << "%#{indent}s: %s" % [line_counter, line] - end + indent_template % [line_counter, line] end end end |