Class: Lutaml::Model::Schema::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/model/schema/renderer.rb

Defined Under Namespace

Classes: Context

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_path) ⇒ Renderer

Returns a new instance of Renderer.



12
13
14
# File 'lib/lutaml/model/schema/renderer.rb', line 12

def initialize(template_path)
  @template = File.read(template_path)
end

Class Method Details

.render(template_path, variables = {}) ⇒ Object



8
9
10
# File 'lib/lutaml/model/schema/renderer.rb', line 8

def self.render(template_path, variables = {})
  new(template_path).render(variables)
end

Instance Method Details

#render(variables = {}) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/lutaml/model/schema/renderer.rb', line 16

def render(variables = {})
  context = build_context(variables)

  ERB.new(@template, trim_mode: "-").result(context.instance_eval do
    binding
  end)
end