15
16
17
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
65
66
67
68
69
70
71
72
|
# File 'lib/themeable/command.rb', line 15
def new(name)
@theme_name = name
@app_name = "theme_#{name}"
say('Initializing theme project...', :green)
system "rails plugin new #{app_name} -T -B"
@destination_stack ||= []
@destination_stack[0] = File.expand_path(app_name)
gsub_file "#{app_name}.gemspec", /TODO[: ]*/, ''
gsub_file "#{app_name}.gemspec", %r{^ *s\.files *=.*} do
' s.files = Dir["{lib,theme}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]'
end
insert_into_file "#{app_name}.gemspec", after: %r{^ *s\.add_dependency .*} do
"\n s.add_dependency 'themeable'"
end
template 'generators/copy_views_generator.rb', "lib/generators/theme_#{theme_name}/copy_views_generator.rb"
template 'generators/copy_assets_generator.rb', "lib/generators/theme_#{theme_name}/copy_assets_generator.rb"
template 'resolve_css_path.rake', "lib/tasks/resolve_css_path.rake"
append_to_file 'Rakefile' do
<<-CODE
require '#{app_name}'
Dir.glob('lib/tasks/*.rake').each { |r| load r}
CODE
end
create_file "theme/assets/#{theme_name}/application.css"
create_file "theme/assets/#{theme_name}/application.js"
create_file "theme/views/layouts/.gitkeep"
template "view_application.html.erb", "theme/views/layouts/application.html.erb"
%w(default admin).each do |name|
create_file "theme/scaffold_templates/#{theme_name}/#{name}/index.html.erb"
create_file "theme/scaffold_templates/#{theme_name}/#{name}/edit.html.erb"
create_file "theme/scaffold_templates/#{theme_name}/#{name}/show.html.erb"
create_file "theme/scaffold_templates/#{theme_name}/#{name}/new.html.erb"
create_file "theme/scaffold_templates/#{theme_name}/#{name}/_form.html.erb"
end
create_file "vendor/#{theme_name}/.gitkeep"
remove_file "lib/#{app_name}.rb"
template 'theme_main.rb', "lib/#{app_name}.rb"
puts
say("Done. Please check your new theme project in directory #{app_name}", :green)
puts
end
|