Class: Twig::Node::Expression::GetAttribute

Inherits:
Base
  • Object
show all
Includes:
SupportDefinedTest
Defined in:
lib/twig/node/expression/get_attribute.rb

Instance Attribute Summary

Attributes inherited from Base

#attributes, #lineno, #nodes, #source_context, #tag

Instance Method Summary collapse

Methods included from SupportDefinedTest

#define_test_enabled?

Methods inherited from Base

#explicit_parentheses?, #set_explicit_parentheses

Methods inherited from Base

#empty?, #length, #template_name, #to_s

Constructor Details

#initialize(node, attribute, arguments, type, lineno) ⇒ GetAttribute

Returns a new instance of GetAttribute.



9
10
11
12
13
14
# File 'lib/twig/node/expression/get_attribute.rb', line 9

def initialize(node, attribute, arguments, type, lineno)
  nodes = { node:, attribute: }
  nodes[:arguments] = arguments if arguments

  super(nodes, { type:, ignore_strict_check: false }, lineno)
end

Instance Method Details

#compile(compiler) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/twig/node/expression/get_attribute.rb', line 21

def compile(compiler)
  compiler.
    raw('::Twig::Extension::Core.get_attribute(env, source_context, ')

  if attributes[:ignore_strict_check]
    nodes[:node].attributes[:ignore_strict_check] = true
  end

  compiler.
    subcompile(nodes[:node]).
    raw(', ').
    subcompile(nodes[:attribute]).
    raw(', ').
    repr(attributes[:type])

  if nodes.key?(:arguments)
    compiler.
      raw(', arguments: ').
      subcompile(nodes[:arguments])
  end

  if define_test_enabled?
    compiler.
      raw(', defined_test: true')
  end

  if attributes[:ignore_strict_check]
    compiler.
      raw(', ignore_strict_check: true')
  end

  compiler.
    raw(', lineno: ').
    repr(lineno).
    raw(')')
end

#enable_defined_testObject



16
17
18
19
# File 'lib/twig/node/expression/get_attribute.rb', line 16

def enable_defined_test
  super
  change_ignore_strict_check(self)
end