class Filegen::ErbGenerator

Used to generate the template

Attributes

data[R]

Public Class Methods

new(data) click to toggle source

Create erb generator

@param [Data] data

The data class to be used within the template
# File lib/filegen/erb_generator.rb, line 15
def initialize(data)
  @data = data
end

Public Instance Methods

compile(source, destination) click to toggle source

Compile the template

@param [IO] source

The source template to be used

@param [IO] destination

The output io handle
# 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