lib/filegen/erb_generator.rb in filegen-0.0.1 vs lib/filegen/erb_generator.rb in filegen-0.1.1

- old
+ new

@@ -1,15 +1,30 @@ # encoding: utf-8 module Filegen + # Used to generate the template class ErbGenerator - attr_reader :template_binding + private - def initialize(template_binding) - @template_binding = template_binding + 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 - def compile(source,destination) - destination.puts ERB.new(source).result(template_binding) + # 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) + destination.puts erb.result(data.instance_binding) end end - end