Class: Antlers::YieldNode

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

Constant Summary

Constants inherited from AntlerNode

AntlerNode::DEF_KEY, AntlerNode::END_KEY

Instance Attribute Summary

Attributes inherited from BranchNode

#children

Attributes inherited from AntlerNode

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AntlerNode

#==, #end_name, #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

Class Method Details

.build(segment:) ⇒ Object



27
28
29
# File 'lib/nodes/yield_node.rb', line 27

def build(segment:, **)
  new(name: segment[:slot])
end

.match?(segment:) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/nodes/yield_node.rb', line 23

def match?(segment:)
  segment[:slot]
end

Instance Method Details

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

Render the children in the binding of the parent.



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

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

  slot_node.children.each do |child|
    output += child.render(current_binding: parent_binding, parent_binding:, slot_node:) || ''
  end

  output
end