Method: ActionView::Template::Handlers::ERB#translate_location

Defined in:
actionview/lib/action_view/template/handlers/erb.rb

#translate_location(spot, backtrace_location, source) ⇒ Object

Translate an error location returned by ErrorHighlight to the correct source location inside the template.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'actionview/lib/action_view/template/handlers/erb.rb', line 43

def translate_location(spot, backtrace_location, source)
  # Tokenize the source line
  source_lines = source.lines
  return nil if source_lines.size < backtrace_location.lineno
  tokens = ::ERB::Util.tokenize(source_lines[backtrace_location.lineno - 1])
  new_first_column = find_offset(spot[:snippet], tokens, spot[:first_column])
  lineno_delta = spot[:first_lineno] - backtrace_location.lineno
  spot[:first_lineno] -= lineno_delta
  spot[:last_lineno] -= lineno_delta

  column_delta = spot[:first_column] - new_first_column
  spot[:first_column] -= column_delta
  spot[:last_column] -= column_delta
  spot[:script_lines] = source_lines

  spot
rescue NotImplementedError, LocationParsingError
  nil
end