Class: Filegen::ErbGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/filegen/erb_generator.rb

Overview

Used to generate the template

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ErbGenerator

Create erb generator

Parameters:

  • data (Data)

    The data class to be used within the template



15
16
17
# File 'lib/filegen/erb_generator.rb', line 15

def initialize(data)
  @data = data
end

Instance Method Details

#compile(source, destination) ⇒ Object

Compile the template

Parameters:

  • source (IO)

    The source template to be used

  • destination (IO)

    The output io handle



25
26
27
28
29
30
31
32
# File 'lib/filegen/erb_generator.rb', line 25

def compile(source, destination)
  erb = ERB.new(source.read, nil, '-')
  begin
    destination.puts erb.result(data.instance_binding)
  rescue SyntaxError => e
    raise Exceptions::ErbTemplateHasSyntaxErrors, e.message
  end
end