Class: Liquid2::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/liquid2/node.rb

Overview

The base class for all nodes in a Liquid syntax tree.

Direct Known Subclasses

Block, Comment, ConditionalBlock, MultiEqualBlock, Output, Tag

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Node

Returns a new instance of Node.

Parameters:

  • token ([Symbol, String?, Integer])


10
11
12
13
# File 'lib/liquid2/node.rb', line 10

def initialize(token)
  @token = token
  @blank = true
end

Instance Attribute Details

#blankObject

Returns the value of attribute blank.



7
8
9
# File 'lib/liquid2/node.rb', line 7

def blank
  @blank
end

#tokenObject (readonly)

Returns the value of attribute token.



6
7
8
# File 'lib/liquid2/node.rb', line 6

def token
  @token
end

Instance Method Details

#block_scopeObject

Return variables this nodes adds to its block scope.



39
# File 'lib/liquid2/node.rb', line 39

def block_scope = []

#children(_static_context, include_partials: true) ⇒ Object

Return all children of this node.



30
# File 'lib/liquid2/node.rb', line 30

def children(_static_context, include_partials: true) = []

#expressionsObject

Return this node's expressions.



33
# File 'lib/liquid2/node.rb', line 33

def expressions = []

#partial_scopeObject

Return information about a partial template loaded by this node.



42
# File 'lib/liquid2/node.rb', line 42

def partial_scope = nil

#render(_context, _buffer) ⇒ Object



15
16
17
# File 'lib/liquid2/node.rb', line 15

def render(_context, _buffer)
  raise "nodes must implement `render: (RenderContext, String) -> void`"
end

#render_with_disabled_tag_check(context, buffer) ⇒ Object

Raises:



19
20
21
22
23
24
25
26
27
# File 'lib/liquid2/node.rb', line 19

def render_with_disabled_tag_check(context, buffer)
  if context.disabled_tags.empty? ||
     !is_a?(Tag) ||
     !context.disabled_tags.include?(@token[1] || raise)
    return render(context, buffer)
  end

  raise DisabledTagError.new("#{@token[1]} is not allowed in this context", @token)
end

#template_scopeObject

Return variables this node adds to the template local scope.



36
# File 'lib/liquid2/node.rb', line 36

def template_scope = []