Sha256: 888d9dd7952d8413aa59b5d6346c780ae5780f4cd10ec1435561ec10505219c6

Contents?: true

Size: 947 Bytes

Versions: 18

Compression:

Stored size: 947 Bytes

Contents

# encoding: UTF-8

require "erb"

module Gjp
  # operates on files in template/
  class TemplateManager
    include Logger

    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)

      if destination_path != nil
        File.open(destination_path, "w") { |io| io.write new_content }
      end

      new_content
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
gjp-0.37.0 lib/gjp/template_manager.rb
gjp-0.36.0 lib/gjp/template_manager.rb
gjp-0.35.0 lib/gjp/template_manager.rb
gjp-0.34.0 lib/gjp/template_manager.rb
gjp-0.33.0 lib/gjp/template_manager.rb
gjp-0.32.0 lib/gjp/template_manager.rb
gjp-0.31.0 lib/gjp/template_manager.rb
gjp-0.30.0 lib/gjp/template_manager.rb
gjp-0.29.0 lib/gjp/template_manager.rb
gjp-0.28.0 lib/gjp/template_manager.rb
gjp-0.27.0 lib/gjp/template_manager.rb
gjp-0.26.0 lib/gjp/template_manager.rb
gjp-0.25.0 lib/gjp/template_manager.rb
gjp-0.24.0 lib/gjp/template_manager.rb
gjp-0.23.0 lib/gjp/template_manager.rb
gjp-0.22.0 lib/gjp/template_manager.rb
gjp-0.21.0 lib/gjp/template_manager.rb
gjp-0.20.0 lib/gjp/template_manager.rb