Class: TestServer::ErbGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/test_server/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:



16
17
18
# File 'lib/test_server/erb_generator.rb', line 16

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)


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

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