Class: Twig::Node::Expression::MacroReference

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

Overview

Represents a macro call node.

Instance Attribute Summary

Attributes inherited from Base

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

Instance Method Summary collapse

Methods included from SupportDefinedTest

#define_test_enabled?, #enable_defined_test

Methods inherited from Base

#explicit_parentheses?, #set_explicit_parentheses

Methods inherited from Base

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

Constructor Details

#initialize(template, name, arguments, lineno) ⇒ MacroReference

Returns a new instance of MacroReference.

Parameters:



14
15
16
# File 'lib/twig/node/expression/macro_reference.rb', line 14

def initialize(template, name, arguments, lineno)
  super({ template:, arguments: }, { name: }, lineno)
end

Instance Method Details

#compile(compiler) ⇒ Object

Parameters:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/twig/node/expression/macro_reference.rb', line 19

def compile(compiler)
  if define_test_enabled?
    compiler.
      subcompile(nodes[:template]).
      raw('.macro?(').
      repr(attributes[:name]).
      raw(', context').
      raw(')')
    return
  end

  compiler.
    subcompile(nodes[:template]).
    raw('.render_macro(').
    repr(attributes[:name]).
    raw(', context, ').
    subcompile(nodes[:arguments]).
    raw(', ').
    repr(lineno).
    raw(', source_context)')
end