Class: Liquid2::Block

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

Overview

An node representing a block of Liquid markup. Essentially an array of other nodes and strings.

Instance Attribute Summary

Attributes inherited from Node

#blank, #token

Instance Method Summary collapse

Methods inherited from Node

#block_scope, #expressions, #partial_scope, #render_with_disabled_tag_check, #template_scope

Constructor Details

#initialize(token, nodes) ⇒ Block

Returns a new instance of Block.



66
67
68
69
70
71
72
# File 'lib/liquid2/node.rb', line 66

def initialize(token, nodes)
  super(token)
  @nodes = nodes
  @blank = nodes.all? do |n|
    (n.is_a?(String) && n.match(/\A\s*\Z/)) || (n.is_a?(Node) && n.blank)
  end
end

Instance Method Details

#children(_static_context, include_partials: true) ⇒ Object



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

def children(_static_context, include_partials: true) = @nodes

#render(context, buffer) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/liquid2/node.rb', line 74

def render(context, buffer)
  buffer = +"" if context.env.suppress_blank_control_flow_blocks && @blank
  index = 0
  while (node = @nodes[index])
    index += 1
    case node
    when String
      buffer << node
    else
      node.render_with_disabled_tag_check(context, buffer)
    end

    context.raise_for_output_limit(buffer.bytesize)
    return unless context.interrupts.empty?
  end
end