Class: Antlers::BranchNode

Inherits:
AntlerNode show all
Defined in:
lib/interfaces/branch_node.rb

Direct Known Subclasses

ForNode, RootNode, SlotNode, YieldNode

Instance Attribute Summary collapse

Attributes inherited from AntlerNode

#name

Instance Method Summary collapse

Methods inherited from AntlerNode

#==, #eql?, #hash

Constructor Details

#initialize(name:, children: []) ⇒ BranchNode

Returns a new instance of BranchNode.



9
10
11
12
13
# File 'lib/interfaces/branch_node.rb', line 9

def initialize(name:, children: [])
  super(name:)

  @children = children
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



7
8
9
# File 'lib/interfaces/branch_node.rb', line 7

def children
  @children
end

Instance Method Details

#render(current_binding: nil, parent_binding: nil, slot_node: nil, namespace: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/interfaces/branch_node.rb', line 15

def render(current_binding: nil, parent_binding: nil, slot_node: nil, namespace: nil)
  output = ''

  @children.each do |child|
    # Antlers nodes respond to "render", whereas HTML is stored as a string and output as is.
    output += (child.respond_to?(:render) ? child.render(current_binding:, parent_binding:, slot_node:, namespace:) : child) || ''
  end

  output
end