lib/subtrac/project.rb in ktec-subtrac-0.1.46 vs lib/subtrac/project.rb in ktec-subtrac-0.1.47
- old
+ new
@@ -1,14 +1,35 @@
require 'subtrac/client'
module Subtrac
class Project
- attr_reader :display_name, :path, :client, :type, :template
- attr_accessor :svn_dir, :trac_dir
- def initialize(project_name,client_name,project_type)
+ 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)
- @type = project_type
- @template = File.join(File.dirname(__FILE__), "project", project_type)
+ @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 = File.new(file,'r').read.gsub(/\$\{project.display_name\}/,exp_replace)
+ 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
end
end
\ No newline at end of file