43
44
45
46
47
48
49
50
51
52
53
54
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
|
# File 'lib/motion/gem/command/template.rb', line 43
def scaffold_gem(gem_name)
gem_name = gem_name.chomp('/')
gem_path = gem_name.tr('-', '/')
destination = File.join(Dir.pwd, gem_name)
constant_name = gem_name.split('_').map(&:capitalize).join
constant_name = constant_name.split('-').map(&:capitalize).join('::') if constant_name =~ /-/
constants = constant_name.split('::')
git_user = `git config user.name`.chomp
git_email = `git config user.email`.chomp
config = {
:gem_name => gem_name,
:gem_path => gem_path,
:constant_name => constant_name,
:constants => constants,
:author => git_user,
:email => git_email
}
if Motion::Project::App.respond_to?(:template)
template_ext = Motion::Project::App.template
end
template_ext ||= 'ios'
template_root = File.join(File.expand_path('../../templates/', __FILE__), template_ext)
render File.join(template_root, 'Gemfile.erb'), File.join(destination, 'Gemfile'), config
render File.join(template_root, 'LICENSE.md.erb'), File.join(destination, 'LICENSE.md'), config
render File.join(template_root, 'README.md.erb'), File.join(destination, 'README.md'), config
render File.join(template_root, 'Rakefile.erb'), File.join(destination, 'Rakefile'), config
render File.join(template_root, 'gitignore.erb'), File.join(destination, '.gitignore'), config
render File.join(template_root, 'newgem.gemspec.erb'), File.join(destination, "#{gem_name}.gemspec"), config
render File.join(template_root, 'lib/newgem.rb.erb'), File.join(destination, "lib/#{gem_path}.rb"), config
render File.join(template_root, 'lib/newgem/version.rb.erb'), File.join(destination, "lib/#{gem_path}/version.rb"), config
puts "Initializing git repository in #{destination}"
Dir.chdir(destination) do
`git init`
`git add .`
end
end
|