Sha256: a0aa702e9c7404edb80e42a98cf50fa2f58365ca9d31d8b9f1009a265fd5d3f2

Contents?: true

Size: 1020 Bytes

Versions: 3

Compression:

Stored size: 1020 Bytes

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
        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

3 entries across 3 versions & 1 rubygems

Version Path
xcbootstrap-0.0.3 lib/xcbootstrap/template.rb
xcbootstrap-0.0.2 lib/xcbootstrap/template.rb
xcbootstrap-0.0.1 lib/xcbootstrap/template.rb