Class: Antlers::PropNode

Inherits:
LeafNode show all
Includes:
Namespace, Props
Defined in:
lib/nodes/prop_node.rb

Instance Attribute Summary

Attributes included from Props

#props

Attributes inherited from AntlerNode

#name

Instance Method Summary collapse

Methods included from Variables

#evaluate, #fallback

Methods included from Queries

user_defined_string?, wrapped_in?

Methods included from Namespace

#class_constant, #class_from_namespace

Methods inherited from AntlerNode

#==, #eql?, #hash

Constructor Details

#initialize(name:, props: {}, namespace: nil) ⇒ PropNode

Returns a new instance of PropNode.



12
13
14
15
16
# File 'lib/nodes/prop_node.rb', line 12

def initialize(name:, props: {}, namespace: nil, **)
  super(name:, props:)

  @namespace = namespace
end

Instance Method Details

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

Classes referenced via "<{ MyNode }>" must implement class/instance and render/render_template methods (See LowNode).



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/nodes/prop_node.rb', line 19

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: @name)
  class_proxy = Lowkey[klass.to_s].first[klass.to_s]
  instance = create_instance(class_proxy:, klass:, event:)

  return instance.render_template(event:, parent_binding:, props:) if klass.template

  render_args(class_proxy:, instance:, event:, props:)
end