instance method translate_location

Ruby on Rails 8.1.2

Since v7.1.6

Available in: v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

translate_location(spot, _backtrace_location, source)

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

Parameters

spot req
_backtrace_location req
source req
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

Type at least 2 characters to search.

↑↓ navigate · open · esc close