Class: Twig::Node::Expression::Variable::AssignTemplate

Inherits:
Base
  • Object
show all
Defined in:
lib/twig/node/expression/variable/assign_template.rb

Instance Attribute Summary

Attributes inherited from Base

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

Instance Method Summary collapse

Methods inherited from Base

#explicit_parentheses?, #set_explicit_parentheses

Methods inherited from Base

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

Constructor Details

#initialize(var, global: true) ⇒ AssignTemplate

Returns a new instance of AssignTemplate.

Parameters:



10
11
12
# File 'lib/twig/node/expression/variable/assign_template.rb', line 10

def initialize(var, global: true)
  super({ var: }, { global: }, var.lineno)
end

Instance Method Details

#compile(compiler) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/twig/node/expression/variable/assign_template.rb', line 14

def compile(compiler)
  # @var [Template] var
  var = nodes[:var]

  compiler.
    add_debug_info(self).
    write('macros[').
    string(var.name(compiler)).
    raw('] = ')

  if attributes[:global]
    compiler.
      raw('@macros[').
      string(var.name(compiler)).
      raw('] = ')
  end
end