Module: Spider::Create
- Defined in:
- lib/spiderfw/create.rb
Class Method Summary collapse
- .app(name, path, module_name = nil) ⇒ Object
- .create(source_path, dest_path, replacements = {}, erb_binding = nil) ⇒ Object
- .home(name, path) ⇒ Object
Class Method Details
.app(name, path, module_name = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/spiderfw/create.rb', line 11 def self.app(name, path, module_name=nil) name_parts = name.split('/') app_name = name_parts[-1] app_path = name module_full_name ||= Spider::Inflector.camelize(name) modules = module_full_name.split('::') module_name = modules[-1] erb_binding = binding dest_folder = path+'/'+name #FileUtils.mkdir_p(File.expand_path(dest_path+'/..')) source_folder = $SPIDER_PATH+'/blueprints/app' replacements = { '__APP__' => app_name, '__MODULE__' => modules[modules.length-1] } create(source_folder, dest_folder, replacements, erb_binding) end |
.create(source_path, dest_path, replacements = {}, erb_binding = nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/spiderfw/create.rb', line 55 def self.create(source_path, dest_path, replacements={}, erb_binding=nil) raise RuntimeError, "Folder #{source_path} does not exist" unless File.exist?(source_path) raise RuntimeError, "Folder #{dest_path} already exists" if File.exist?(dest_path) FileUtils.mkdir_p(dest_path) erb_binding ||= binding if File.exists?("#{source_path}/.dirs") File.readlines("#{source_path}/.dirs").each do |dir| dir.strip! replacements.each do |search, replace| dir.gsub!(search, replace) end FileUtils.mkdir_p(dest_path+'/'+dir) end end Find.find(source_path) do |sp| next if sp == source_path sp =~ /\/([^\/]+)$/ file_name = $1 rel_path = sp[source_path.length+1..-1] dp = rel_path replacements.each do |search, replace| dp.gsub!(search, replace) end if (File.directory?(sp)) FileUtils.mkdir(dest_path+'/'+dp) unless File.directory?(dest_path+'/'+dp) else dst = File.new(dest_path+'/'+dp, 'w') res = ERB.new(IO.read(sp)).result(erb_binding) dst.puts(res) dst.close end end Dir.glob("#{dest_path}/**/.dirs").each do |f| File.unlink(f) end end |
.home(name, path) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/spiderfw/create.rb', line 31 def self.home(name, path) dest_path = path+'/'+name source_path = $SPIDER_PATH+'/blueprints/home' create(source_path, dest_path) begin require 'grit' cwd = Dir.getwd Dir.chdir(dest_path) begin repo = Grit::Repo.init(dest_path) repo.add('apps', 'config', 'init.rb', 'public') repo.add('.gitignore') repo.commit_index(_("Created repository")) rescue => exc puts "Unable to init Git repo, please init manually" end Dir.chdir(cwd) rescue LoadError puts "Grit not installed, cannot init repo" end end |