Class: LocalPac::ErbGenerator

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

Overview

Used to generate the template

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ErbGenerator

Create erb generator

The data class to be used within the template

Parameters:



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

def initialize(data)
  @data = data
end

Instance Method Details

#compile(source, destination) ⇒ Object

Compile the template

The source template to be used The output io handle

Parameters:

  • source (IO)
  • destination (IO)


25
26
27
28
29
30
31
32
# File 'lib/local_pac/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