require 'erb' module Kryo module Generators # The base class for all generators to inherit from. # # @author Matthew A. Johnston (warmwaffles) class Base # Creates a file based off of the template provided. # # @param [String] src the source of the template file # @param [String] destination the destination of where the generated file will go # @param [Hash] options # @option options [String] :name The name of the template to be written as # @return [Boolean] def self.create src, destination, options={}, &block paths = File.split(src) template_name = paths.last template_path = paths.first path = File.join(File.dirname(__FILE__), template_path, "#{template_name}.erb") yield if block erb = ERB.new(File.read(path)) output = File.join(destination, options[:name] || template_name) file = File.open(output, 'w+') file.write(erb.result(binding)) file.close true end end end end