Module: Low::Templates::Renderer

Included in:
LowNode
Defined in:
lib/templates/renderer.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



25
26
27
# File 'lib/templates/renderer.rb', line 25

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#render(event:) ⇒ Object



8
9
10
# File 'lib/templates/renderer.rb', line 8

def render(event:)
  nil
end

#render_template(event:, parent_binding: nil, slot_node: nil, props: {}) ⇒ Object

When render() contains RBX/Antlers then LowLoad populates a template to render with instead.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/templates/renderer.rb', line 13

def render_template(event:, parent_binding: nil, slot_node: nil, props: {})
  template = self.class.template
  current_binding = binding
  
  # Pass in props from parent component as keyword arguments.
  template.params.each do |param|
    current_binding.local_variable_set(param, props[param]) if props[param]
  end

  template.engine.render(ast: template.ast, current_binding:, parent_binding:, slot_node:, namespace: template.namespace)
end