18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/liquid/console.rb', line 18
def project(name)
if File.exist?(name)
puts "!!! #{name} already exists"
exit(1)
end
puts ">>> Generating new project #{name}"
constant_name = name.split('_').map{|p| p[0..0].upcase + p[1..-1] }.join
constant_name = constant_name.split('-').map{|q| q[0..0].upcase + q[1..-1] }.join('::') if constant_name =~ /-/
constant_array = constant_name.split('::')
config = opts
config.merge!({
name: name,
constant_name: constant_name,
constant_array: constant_array,
})
{
"Gemfile" => "Gemfile",
"Rakefile" => "Rakefile",
"LICENSE.txt" => "LICENSE.txt",
"README.md" => "README.md",
".gitignore" => "gitignore",
"#{name}.gemspec" => "gemspec",
"bin/#{name}" => "binwrapper",
"config.yml" => "config.yml",
"#{name}/server.rb" => "server.rb",
}.each do |dest, source|
puts " * #{dest}"
source = File.join(ROOT, 'lib/liquid/templates', "#{source}.tt")
dest = File.join(name, dest)
FileUtils.mkdir_p(File.dirname(dest))
input = File.read(source)
eruby = Erubis::Eruby.new(input)
output = File.open(dest, "w")
output.write(eruby.result(binding()))
output.close
end
Dir.chdir(name) do
puts ">>> Installing dependencies"
system("bundle install")
system("chmod +x bin/*")
end
end
|