Class: Typelizer::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/typelizer/renderer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template) ⇒ Renderer

Returns a new instance of Renderer.



11
12
13
# File 'lib/typelizer/renderer.rb', line 11

def initialize(template)
  @erb = ERB.new(File.read(File.join(File.dirname(__FILE__), "templates/#{template}")), trim_mode: "-")
end

Class Method Details

.call(template, **context) ⇒ Object



7
8
9
# File 'lib/typelizer/renderer.rb', line 7

def self.call(template, **context)
  new(template).call(**context)
end

Instance Method Details

#call(**context) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/typelizer/renderer.rb', line 15

def call(**context)
  b = binding
  context.each_pair do |key, value|
    b.local_variable_set(key, value)
  end
  erb.result(b)
end