require 'fileutils' require 'ptools' module XCBootstrap class Template attr_accessor :from attr_accessor :to def initialize file_info, template_dir, project_dir @template_name = File.basename template_dir @project_name = File.basename project_dir @from = File.join template_dir, file_info["from"] relative_path_to = file_info["to"] || file_info["from"].gsub(@template_name, @project_name) @to = File.join project_dir, relative_path_to end def process FileUtils.mkdir_p File.dirname(to) if File.binary? from FileUtils.cp from, to else sed_copy from, to end end private def sed_copy source, destination File.open destination, "w" do |destination_file| File.open source, "r" do |source_file| source_file.each do |input_line| destination_file.puts input_line.gsub(@template_name, @project_name) end end end end end end