Module: Low::Templates::Renderer

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

Overview

Use the Method Factory pattern to .render -> .new -> #initialize -> #render a low node.

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_template(parent_binding: nil, slot_node: nil, props: {}, **kwargs) ⇒ Object

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



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

def render_template(parent_binding: nil, slot_node: nil, props: {}, **kwargs)
  template = self.class.template

  # NOTE: We currently set local variables on this local binding, not the receiver's binding.
  # TODO: Should we create an "instance_binding" method on LowNode and use that binding instead?
  current_binding = binding

  template.params.each do |param|
    variable = props[param] || kwargs[param] || raise(ArgumentError, "Missing argument: '#{param}'")
    current_binding.local_variable_set(param, variable)
  end

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