Class: Antlers::YieldNode

Inherits:
BranchNode show all
Defined in:
lib/nodes/yield_node.rb

Instance Attribute Summary

Attributes inherited from BranchNode

#children

Attributes inherited from AntlerNode

#name

Instance Method Summary collapse

Methods inherited from AntlerNode

#==, #eql?, #hash

Constructor Details

#initialize(name: :default) ⇒ YieldNode

Returns a new instance of YieldNode.



7
8
9
# File 'lib/nodes/yield_node.rb', line 7

def initialize(name: :default)
  super(name:)
end

Instance Method Details

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

Renders the children of the parent node in the binding of the parent.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/nodes/yield_node.rb', line 12

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

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

  output
end