Method: ActionView::Template::Error#source_extract

Defined in:
actionview/lib/action_view/template/error.rb

#source_extract(indentation = 0) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'actionview/lib/action_view/template/error.rb', line 192

def source_extract(indentation = 0)
  return [] unless num = line_number
  num = num.to_i

  source_code = @template.encode!.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)
end