Sha256: cfde9cfc3aa1d75813bb9713457f80863060d291e54b319c06b5d1cb89585d40

Contents?: true

Size: 639 Bytes

Versions: 6

Compression:

Stored size: 639 Bytes

Contents

require 'erubis'

module HackBoxen
  class Template

    attr_accessor :source_template, :output_path, :attributes

    def initialize source_template, output_path, attributes
      @source_template = source_template
      @output_path     = output_path
      @attributes      = attributes
    end

    def compile!
      dest << Erubis::Eruby.new(source).result(attributes)
      dest << "\n"
      dest
    end

    def substitute!
      compile!
    end

    protected

    def source
      File.open(source_template).read
    end

    def dest
      return @dest if @dest
      @dest ||= File.open(output_path, 'w')
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hackboxen-0.1.5 lib/hackboxen/template.rb
hackboxen-0.1.4 lib/hackboxen/template.rb
hackboxen-0.1.3 lib/hackboxen/template.rb
hackboxen-0.1.2 lib/hackboxen/template.rb
hackboxen-0.1.1 lib/hackboxen/template.rb
hackboxen-0.1.0 lib/hackboxen/template.rb