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