Class: Antlers::SlotNode
- Inherits:
-
BranchNode
- Object
- AntlerNode
- BranchNode
- Antlers::SlotNode
- Defined in:
- lib/nodes/slot_node.rb
Constant Summary collapse
- DEF_KEY =
:slot_def- END_KEY =
:slot_end
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
Attributes included from Props
Attributes inherited from AntlerNode
Class Method Summary collapse
Instance Method Summary collapse
- #end_name ⇒ Object
-
#initialize(name:, namespace:, props: [], children: []) ⇒ SlotNode
constructor
A new instance of SlotNode.
- #render(current_binding: nil, parent_binding: nil, slot_node: nil) ⇒ Object
Methods included from Variables
Methods included from Queries
user_defined_string?, wrapped_in?
Methods included from Namespace
#class_constant, #class_from_namespace
Methods inherited from AntlerNode
Constructor Details
#initialize(name:, namespace:, props: [], children: []) ⇒ SlotNode
Returns a new instance of SlotNode.
17 18 19 20 21 |
# File 'lib/nodes/slot_node.rb', line 17 def initialize(name:, namespace:, props: [], children: [], **) super(name:, props:, children:) @namespace = namespace end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
15 16 17 |
# File 'lib/nodes/slot_node.rb', line 15 def children @children end |
Class Method Details
.build(segment:, namespace:) ⇒ Object
46 47 48 |
# File 'lib/nodes/slot_node.rb', line 46 def build(segment:, namespace:) new(name: segment[DEF_KEY], props: segment[:props], namespace:) end |
.match?(segment:) ⇒ Boolean
42 43 44 |
# File 'lib/nodes/slot_node.rb', line 42 def match?(segment:) segment[DEF_KEY] end |
Instance Method Details
#end_name ⇒ Object
37 38 39 |
# File 'lib/nodes/slot_node.rb', line 37 def end_name @name end |
#render(current_binding: nil, parent_binding: nil, slot_node: nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/nodes/slot_node.rb', line 23 def render(current_binding: nil, parent_binding: nil, slot_node: nil) props = evaluate_props(props: @props, current_binding:) event = create_render_event(props:) # TODO: Get LowLoad to load constants defined in "<{ MyNode }>" syntax so that we can resolve namespace/params on class load. klass = class_constant(namespace: @namespace&.split('::') || [], 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 |