Class: Liquid2::ConditionalBlock

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

Overview

A Liquid block guarded by an expression. Only if the expression evaluates to a truthy value will the block be rendered.

Instance Attribute Summary collapse

Attributes inherited from Node

#blank, #token

Instance Method Summary collapse

Methods inherited from Node

#block_scope, #partial_scope, #render_with_disabled_tag_check, #template_scope

Constructor Details

#initialize(token, expression, block) ⇒ ConditionalBlock

Returns a new instance of ConditionalBlock.



99
100
101
102
103
104
# File 'lib/liquid2/node.rb', line 99

def initialize(token, expression, block)
  super(token)
  @expression = expression
  @block = block
  @blank = block.blank
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



97
98
99
# File 'lib/liquid2/node.rb', line 97

def block
  @block
end

#expressionObject (readonly)

Returns the value of attribute expression.



97
98
99
# File 'lib/liquid2/node.rb', line 97

def expression
  @expression
end

Instance Method Details

#children(_static_context, include_partials: true) ⇒ Object



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

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

#expressionsObject



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

def expressions = [@expression]

#render(context, buffer) ⇒ Object



106
107
108
# File 'lib/liquid2/node.rb', line 106

def render(context, buffer)
  @expression.evaluate(context) ? @block.render(context, buffer) : 0
end