Class: Antlers::SlotNode

Inherits:
BranchNode show all
Includes:
Props
Defined in:
lib/nodes/slot_node.rb

Instance Attribute Summary collapse

Attributes included from Props

#props

Attributes inherited from AntlerNode

#name

Instance Method Summary collapse

Methods inherited from AntlerNode

#==, #eql?, #hash

Constructor Details

#initialize(name:, props: [], children: []) ⇒ SlotNode

Returns a new instance of SlotNode.



12
13
14
# File 'lib/nodes/slot_node.rb', line 12

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

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



10
11
12
# File 'lib/nodes/slot_node.rb', line 10

def children
  @children
end

Instance Method Details

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



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/nodes/slot_node.rb', line 16

def render(current_binding: nil, parent_binding: nil, slot_node: nil, namespace: nil)
  props = evaluate_props(props: @props, current_binding:)
  event = create_render_event(props:)

  klass = class_from_namespace(namespace: namespace&.split('::') || [], name: @name)
  instance = klass.new(event:)

  # Classes referenced via "<{ ChildNode }>" must implement class/instance render/render_template methods (See LowNode).
  return instance.render_template(event:, parent_binding: current_binding, slot_node: self, props:) if klass.template

  props.empty? ? instance.render(event:) : instance.render(event:, **props)
end