instance method
translate_location
Ruby on Rails 8.1.2
Since v7.1.6Signature
translate_location(spot, _backtrace_location, source)
Translate an error location returned by ErrorHighlight to the correct source location inside the template.
Parameters
-
spotreq -
_backtrace_locationreq -
sourcereq
Source
# File actionview/lib/action_view/template/handlers/erb.rb, line 43
def translate_location(spot, _backtrace_location, source)
compiled = spot[:script_lines]
highlight = compiled[spot[:first_lineno] - 1]&.byteslice((spot[:first_column] - 1)...spot[:last_column])
return nil if highlight.blank?
source_lines = source.lines
lineno_delta = find_lineno_offset(compiled, source_lines, highlight, spot[:first_lineno])
tokens = ::ERB::Util.tokenize(source_lines[spot[:first_lineno] - lineno_delta - 1])
column_delta = find_offset(spot[:snippet], tokens, spot[:first_column])
spot[:first_lineno] -= lineno_delta
spot[:last_lineno] -= lineno_delta
spot[:first_column] -= column_delta
spot[:last_column] -= column_delta
spot[:script_lines] = source_lines
spot
rescue NotImplementedError, LocationParsingError
nil
end
Defined in actionview/lib/action_view/template/handlers/erb.rb line 43
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionView::Template::Handlers::ERB