Class: Twig::Node::Expression::Unary::Base

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

Direct Known Subclasses

Not, Spread, StringCast

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(node, lineno) ⇒ Base

Returns a new instance of Base.

Parameters:



10
11
12
# File 'lib/twig/node/expression/unary/base.rb', line 10

def initialize(node, lineno)
  super({ node: }, { with_parenthesis: false }, lineno)
end

Instance Method Details

#compile(compiler) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/twig/node/expression/unary/base.rb', line 14

def compile(compiler)
  if explicit_parentheses?
    compiler.raw('(')
  else
    compiler.raw(' ')
  end

  operator(compiler)
  compiler.subcompile(nodes[:node])

  if explicit_parentheses?
    compiler.raw(')')
  end
end

#operator(compiler) ⇒ Object

Parameters:



30
31
32
# File 'lib/twig/node/expression/unary/base.rb', line 30

def operator(compiler)
  raise 'operator is not implemented'
end