Class: Themeable::Command

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/themeable/command.rb

Instance Method Summary collapse

Instance Method Details

#help(*args) ⇒ Object



10
11
12
# File 'lib/themeable/command.rb', line 10

def help(*args)
  super(*args)
end

#new(name) ⇒ Object



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)
  # say("\"rails plugin new #{app_name} -T\"")
  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

  # generators
  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"

  # rakes
  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

  # assets and views
  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"

  # scaffold templates
  %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

  # vender files
  create_file "vendor/#{theme_name}/.gitkeep"

  # libs
  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