Sha256: 43cec4ae4f1208b0c11820f1f5443f2cbb52165070b4bae95d7507670c072a71

Contents?: true

Size: 1.7 KB

Versions: 10

Compression:

Stored size: 1.7 KB

Contents

require 'subtrac/client'
module Subtrac
  class Project
    attr_reader :display_name, :path, :client, :template
    attr_accessor :svn_dir, :trac_dir#, :temp_dir
    def initialize(project_name,client_name,template)
      @display_name = project_name.gsub(/^[a-z]|\s+[a-z]/) { |a| a.upcase }
      @path = project_name.downcase
      @client = Client.new(client_name)
      @template = File.join(File.dirname(__FILE__), "project", template)
      #@template = template 
      unless File.exists?(@template)
        # attempt download of remote template
        template_location = "file://#{Config.svn_dir}/templates/#{template}/trunk"
        @template = File.join(Config.temp_dir,template)
        `svn export #{template_location} #{@template} --quiet --username #{Config.data[:admin_user]} --password #{Config.data[:admin_pass]}`
        # replace the tokens in the project
        glob_path, exp_search, exp_replace = "#{@template}/**","", @display_name
        puts "Lets see what the filter has returned: #{Dir.glob(glob_path)}"
        Dir.glob(glob_path).each do |file|
          unless File.directory?(file) # only mess with files
            buffer = tokenize(File.new(file,'r').read)
            puts buffer
            File.open(file,'w') {|fw| fw.write(buffer)}
          end
        end
        # TODO: We'll need to run through and do some renaming if necessary
      end
    end
    
    def clear_temp
      # delete the temporary directory
      #FileUtils.rm_r(@temp_dir, :force => true)
    end

    private

    # Replaces some tokens
    def tokenize( string )
      string.gsub( /\$\{project.display_name\}/, @display_name ).
             gsub( /\$\{client.display_name\}/, @client.display_name )
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ktec-subtrac-0.1.48 lib/subtrac/project.rb
ktec-subtrac-0.1.49 lib/subtrac/project.rb
ktec-subtrac-0.1.50 lib/subtrac/project.rb
ktec-subtrac-0.1.51 lib/subtrac/project.rb
ktec-subtrac-0.1.52 lib/subtrac/project.rb
ktec-subtrac-0.1.54 lib/subtrac/project.rb
ktec-subtrac-0.1.55 lib/subtrac/project.rb
ktec-subtrac-0.1.56 lib/subtrac/project.rb
ktec-subtrac-0.1.57 lib/subtrac/project.rb
ktec-subtrac-0.1.58 lib/subtrac/project.rb