Class: Twig::Rails::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/twig/rails/renderer.rb

Instance Method Summary collapse

Instance Method Details

#call(template, source) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/twig/rails/renderer.rb', line 6

def call(template, source)
  <<~TEMPLATE
    ::Twig.
      environment.
      load("#{template.short_identifier}").
      render(
        local_assigns,
        call_context: self,
        output_buffer: @output_buffer
      )

    @output_buffer
  TEMPLATE
end

#translate_location(spot, _backtrace_location, source) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/twig/rails/renderer.rb', line 21

def translate_location(spot, _backtrace_location, source)
  exception = $ERROR_INFO

  return nil unless exception.is_a?(::ActionView::Template::Error)

  twig_exception = exception.cause

  return nil unless twig_exception.is_a?(::Twig::Error::Base)

  lineno = twig_exception.lineno
  lineno = 1 if lineno == -1

  spot[:script_lines] = twig_exception.source_context&.code&.lines || source.lines
  spot[:first_lineno] = spot[:last_lineno] = lineno
  spot[:first_column] = spot[:last_column] = 0

  spot
end