instance method translate_location

Ruby on Rails 7.2.3

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)
          # 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

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