Sha256: 92ebc32d7f7658a2cb200bada8f505d2a08f5ef7a3de8d4833bec66ef5068146

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

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) || File.image?(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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xcbootstrap-0.1.0 lib/xcbootstrap/template.rb