Class: Mafia::Generator

Inherits:
Thor::Group
  • Object
show all
Includes:
Helpers, Thor::Actions
Defined in:
lib/mafia.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#camelize

Class Method Details

.source_rootObject



17
18
19
# File 'lib/mafia.rb', line 17

def self.source_root
  File.expand_path(File.join(File.dirname(__FILE__), 'mafia/templates'))
end

Instance Method Details

#copy_rakefileObject



53
54
55
# File 'lib/mafia.rb', line 53

def copy_rakefile
  copy_file("Rakefile", "#{name}/Rakefile")
end

#copy_readmeObject



61
62
63
# File 'lib/mafia.rb', line 61

def copy_readme
  template("README.md.tt", "#{name}/README.md")
end

#create_app_fileObject



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_fileObject



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_fileObject



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_directoriesObject



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_fileObject



45
46
47
# File 'lib/mafia.rb', line 45

def create_gem_file
  template("gem.rb.tt", "#{name}/lib/#{name}.rb")
end

#create_gemfileObject



57
58
59
# File 'lib/mafia.rb', line 57

def create_gemfile
  template("Gemfile.tt", "#{name}/Gemfile")
end

#create_gemspec_fileObject



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_licenseObject



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_fileObject



35
36
37
# File 'lib/mafia.rb', line 35

def create_version_file
  template("version.rb.tt", "#{name}/lib/version.rb")
end

#include_helpersObject



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_repoObject



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_commandObject



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_messageObject



109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/mafia.rb', line 109

def show_complete_message
  complete = <<-COMPLETE   
  
Sinatra gem has been generated

For help using sinatra please visit www.sinatrarb.com

COMPLETE
   
  say complete, :green
    
end