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
|
# File 'lib/rubyhtmlapp/cli.rb', line 19
def create(raw_name)
name = raw_name.chomp("/")
namespaced_path = name.tr('-', '/')
target = File.join(Dir.pwd, 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('::')
git_user_name = `git config user.name`.chomp
git_user_email = `git config user.email`.chomp
`bundle gem #{raw_name}`
opts = {
:name => name,
:namespaced_path => namespaced_path,
:constant_name => constant_name,
:constant_array => constant_array,
:author => git_user_name.empty? ? "TODO: Write your name" : git_user_name,
:email => git_user_email.empty? ? "TODO: Write your email address" : git_user_email,
:test => options[:test]
}
gen = FileGenerator.new(name, opts)
FileGenerator.file(:application_html, "html/application.html.haml", "lib/#{name}/html/application.html.haml")
FileGenerator.file(:layout_html, "html/layout.html.haml", "lib/#{name}/html/layout.html.haml")
FileGenerator.empty_directory(:images, "lib/#{name}/images/")
FileGenerator.file(:application_js, "javascripts/application.js", "lib/#{name}/javascripts/application.js")
FileGenerator.file(:application_css, "stylesheets/application.css", "lib/#{name}/stylesheets/application.css")
FileGenerator.empty_directory(:dist, "dist/")
FileGenerator.file(:helpers, "helpers.rb", "lib/#{name}/helpers.rb")
FileGenerator.template(:cli, "cli.rb", "lib/#{name}/cli.rb")
FileGenerator.template(:run, "run", "bin/#{name}")
FileGenerator.template(:gemspec, "newgem.gemspec", "#{name}.gemspec")
FileGenerator.template(:app, "newgem.rb", "lib/#{name}.rb")
gen.invoke!
Dir.chdir(name) { `git add .`; `git commit -m "initialize rubyhtmlapp"`; }
end
|