Sha256: 24c20199b4a63f222c8098fe46ad61eb2e39d4f06cfcff3654f179c8cf288d4c

Contents?: true

Size: 730 Bytes

Versions: 4

Compression:

Stored size: 730 Bytes

Contents

# encoding: utf-8
module Filegen
  # Used to generate the template
  class ErbGenerator
    private

    attr_reader :data

    public

    # Create erb generator
    #
    # @param [Data] data
    #   The data class to be used within the template
    def initialize(data)
      @data = data
    end

    # Compile the template
    #
    # @param [IO] source
    #   The source template to be used
    # @param [IO] destination
    #   The output io handle
    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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
filegen-0.4.3 lib/filegen/erb_generator.rb
filegen-0.4.1 lib/filegen/erb_generator.rb
filegen-0.4.0 lib/filegen/erb_generator.rb
filegen-0.3.1 lib/filegen/erb_generator.rb