Class: Mafia::Generator
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Mafia::Generator
- Includes:
- Helpers, Thor::Actions
- Defined in:
- lib/mafia.rb
Class Method Summary collapse
Instance Method Summary collapse
- #copy_rakefile ⇒ Object
- #copy_readme ⇒ Object
- #create_app_file ⇒ Object
- #create_bin_file ⇒ Object
- #create_config_ru_file ⇒ Object
- #create_empty_files_and_directories ⇒ Object
- #create_gem_file ⇒ Object
- #create_gemfile ⇒ Object
- #create_gemspec_file ⇒ Object
- #create_license ⇒ Object
- #create_version_file ⇒ Object
- #include_helpers ⇒ Object
- #initalize_git_repo ⇒ Object
- #run_bundle_command ⇒ Object
- #show_complete_message ⇒ Object
Methods included from Helpers
Class Method Details
.source_root ⇒ Object
17 18 19 |
# File 'lib/mafia.rb', line 17 def self.source_root File.(File.join(File.dirname(__FILE__), 'mafia/templates')) end |
Instance Method Details
#copy_rakefile ⇒ Object
53 54 55 |
# File 'lib/mafia.rb', line 53 def copy_rakefile copy_file("Rakefile", "#{name}/Rakefile") end |
#copy_readme ⇒ Object
61 62 63 |
# File 'lib/mafia.rb', line 61 def copy_readme template("README.md.tt", "#{name}/README.md") end |
#create_app_file ⇒ Object
49 50 51 |
# File 'lib/mafia.rb', line 49 def create_app_file template("app.rb.tt", "#{name}/lib/#{name}/app.rb") end |
#create_bin_file ⇒ Object
39 40 41 42 43 |
# File 'lib/mafia.rb', line 39 def create_bin_file if yes? "\n\nCreate a binary to run your application?", :green template("bin.tt", "#{name}/bin/#{name}") end end |
#create_config_ru_file ⇒ Object
31 32 33 |
# File 'lib/mafia.rb', line 31 def create_config_ru_file template("config.ru.tt", "#{name}/config.ru") end |
#create_empty_files_and_directories ⇒ Object
65 66 67 68 69 |
# File 'lib/mafia.rb', line 65 def create_empty_files_and_directories empty_directory("#{name}/lib/#{name}/public") empty_directory("#{name}/lib/#{name}/views") empty_directory("#{name}/lib/#{name}/lib") end |
#create_gem_file ⇒ Object
45 46 47 |
# File 'lib/mafia.rb', line 45 def create_gem_file template("gem.rb.tt", "#{name}/lib/#{name}.rb") end |
#create_gemfile ⇒ Object
57 58 59 |
# File 'lib/mafia.rb', line 57 def create_gemfile template("Gemfile.tt", "#{name}/Gemfile") end |
#create_gemspec_file ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/mafia.rb', line 21 def create_gemspec_file opts = { :name => name, :creator_name => `git config user.name`.chomp, :creator_email => `git config user.email`.chomp } template("gemspec.tt", "#{name}/#{name}.gemspec", opts) end |
#create_license ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/mafia.rb', line 79 def create_license if yes? "\n\nUse MIT License?", :green opts = { :name => name, :creator_name => `git config user.name`.chomp, :creator_email => `git config user.email`.chomp } template("LICENSE.tt", "#{name}/LICENSE", opts) end end |
#create_version_file ⇒ Object
35 36 37 |
# File 'lib/mafia.rb', line 35 def create_version_file template("version.rb.tt", "#{name}/lib/version.rb") end |
#include_helpers ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/mafia.rb', line 71 def include_helpers if yes? "\n\nInstall georgedrummond_sinatra_helpers gem into app?", :green insert_into_file "#{name}/#{name}.gemspec", " s.add_dependency \"georgedrummond_sinatra_helpers\"\n", :after => "s.add_dependency \"sass\"\n" insert_into_file "#{name}/lib/#{name}/app.rb", " include GeorgeDrummond::Sinatra::Helpers\n", :after => "class Application < Sinatra::Base\n" insert_into_file "#{name}/lib/#{name}/app.rb", "require \"georgedrummond_sinatra_helpers\"\n", :after => "require \"sass\"\n" end end |
#initalize_git_repo ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/mafia.rb', line 92 def initalize_git_repo target = File.join(Dir.pwd, name) say "\n\nInitializating git repo in #{target}", :green Dir.chdir(target) { run "git init", :verbose => false run "git add .", :verbose => false } end |
#run_bundle_command ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/mafia.rb', line 101 def run_bundle_command target = File.join(Dir.pwd, name) say "\n\nRunning Bundler", :green Dir.chdir(target) { run "bundle install", :verbose => false } end |
#show_complete_message ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/mafia.rb', line 109 def complete = <<-COMPLETE Sinatra gem has been generated For help using sinatra please visit www.sinatrarb.com COMPLETE say complete, :green end |