Sha256: e0770a0c1aa376476bf65aab3d36be0315f74c4e60c6e9460b0030f83a8773c4

Contents?: true

Size: 937 Bytes

Versions: 1

Compression:

Stored size: 937 Bytes

Contents

# encoding: UTF-8

module Tetra
  # operates on files in template/
  class TemplateManager
    include Logging

    attr_reader :template_path

    def initialize
      @template_path = File.join(File.dirname(__FILE__), "..", "template")
    end

    # copies a template file in a directory
    def copy(template_name, destination_dir)
      FileUtils.cp_r(File.join(template_path, template_name), destination_dir)
    end

    # generates content from an ERB template and an object binding
    # if destination_path is given, write it to that file, otherwise just
    # return it
    def generate(template_name, object_binding, destination_path = nil)
      erb = ERB.new File.read(File.join(template_path, template_name)), nil, "<>"
      new_content =  erb.result(object_binding)

      unless destination_path.nil?
        File.open(destination_path, "w") { |io| io.write new_content }
      end

      new_content
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tetra-0.40.0 lib/tetra/template_manager.rb