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
"require '\#{app_name}'\nDir.glob('lib/tasks/*.rake').each { |r| load r}\n CODE\n end\n\n # assets and views\n create_file \"theme/assets/\#{theme_name}/application.css\"\n create_file \"theme/assets/\#{theme_name}/application.js\"\n create_file \"theme/views/layouts/.gitkeep\"\n template \"view_application.html.erb\", \"theme/views/layouts/application.html.erb\"\n\n # scaffold templates\n %w(default admin).each do |name|\n create_file \"theme/scaffold_templates/\#{theme_name}/\#{name}/index.html.erb\"\n create_file \"theme/scaffold_templates/\#{theme_name}/\#{name}/edit.html.erb\"\n create_file \"theme/scaffold_templates/\#{theme_name}/\#{name}/show.html.erb\"\n create_file \"theme/scaffold_templates/\#{theme_name}/\#{name}/new.html.erb\"\n create_file \"theme/scaffold_templates/\#{theme_name}/\#{name}/_form.html.erb\"\n end\n\n # vender files\n create_file \"vendor/\#{theme_name}/.gitkeep\"\n\n # libs\n remove_file \"lib/\#{app_name}.rb\"\n template 'theme_main.rb', \"lib/\#{app_name}.rb\"\n\n puts\n say(\"Done. Please check your new theme project in directory \#{app_name}\", :green)\n puts\nend\n"
|