Class: Liquid2::ConditionalBlock
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
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#expression ⇒ Object
readonly
Returns the value of attribute expression.
Attributes inherited from Node
Instance Method Summary collapse
- #children(_static_context, include_partials: true) ⇒ Object
- #expressions ⇒ Object
-
#initialize(token, expression, block) ⇒ ConditionalBlock
constructor
A new instance of ConditionalBlock.
- #render(context, buffer) ⇒ Object
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
#block ⇒ Object (readonly)
Returns the value of attribute block.
97 98 99 |
# File 'lib/liquid2/node.rb', line 97 def block @block end |
#expression ⇒ Object (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] |
#expressions ⇒ Object
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 |