Permalink
Browse files

Added --cap option for generating simple cap recipe

Added empty config.yml generation
  • Loading branch information...
1 parent a8f391b commit aacaa79c32d2688db5add9f49f426ff3e13f9a6a @quirkey quirkey committed Dec 16, 2008
View
8 README.rdoc
@@ -18,15 +18,15 @@ Run:
e.g.
- sinatra-gen mysinatrapp --vendor -i --test=shoulda --views=haml
+ sinatra-gen mysinatrapp --vendor --init --test=shoulda --views=haml
Options (can also be obtained by running sinatra-gen with no arguments):
-v, --version Show the sinatra-gen version number and quit.
-d, --vendor Extract the latest sinatra to vendor/sinatra
- -t, --tiny Only create the minimal files.
- -s, --scripts Install the rubigen scripts (script/generate, script/destroy)
- -i, --init Initialize a git repository
+ --tiny Only create the minimal files.
+ --scripts Install the rubigen scripts (script/generate, script/destroy)
+ --init Initialize a git repository
--git /path/to/git Specify a different path for 'git'
--test=test_framework Specify your testing framework (unit (default)/rspec/spec/shoulda)
--views=view_framework Specify your view framework (erb (default)/haml/builder)
View
17 app_generators/sinatra_app/sinatra_app_generator.rb
@@ -5,7 +5,7 @@ class SinatraAppGenerator < RubiGen::Base
default_options :author => nil
- attr_accessor :app_name, :vendor, :tiny, :git, :git_init, :test_framework, :view_framework, :install_scripts
+ attr_accessor :app_name, :vendor, :tiny, :git, :git_init, :test_framework, :view_framework, :install_scripts, :cap
def initialize(runtime_args, runtime_options = {})
super
@@ -30,6 +30,7 @@ def manifest
unless tiny
BASEDIRS.each { |path| m.directory path }
+ m.file 'config.yml', 'config.yml'
m.template 'lib/module.rb.erb', "lib/#{app_name}.rb"
m.template 'test/test_helper.rb.erb', 'test/test_helper.rb'
m.template "test/test_app_#{test_framework}.rb.erb", "test/test_#{app_name}.rb"
@@ -47,6 +48,12 @@ def manifest
`#{command}`
end
+ if cap
+ m.directory 'config'
+ m.file 'Capfile', 'Capfile'
+ m.template 'config/deploy.rb.erb', 'config/deploy.rb'
+ end
+
if install_scripts
m.dependency "install_rubigen_scripts", [destination_root, 'sinatra-gen'], :shebang => options[:shebang], :collision => :force
end
@@ -68,9 +75,10 @@ def add_options!(opts)
opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
opts.on("-d", "--vendor", "Extract the latest sinatra to vendor/sinatra") {|o| options[:vendor] = o }
- opts.on("-t", "--tiny", "Only create the minimal files.") {|o| options[:tiny] = o }
- opts.on("-i", "--init", "Initialize a git repository") {|o| options[:init] = o }
- opts.on("-s", "--scripts", "Install the rubigen scripts (script/generate, script/destroy)") {|o| options[:scripts] = o }
+ opts.on("--tiny", "Only create the minimal files.") {|o| options[:tiny] = o }
+ opts.on("--init", "Initialize a git repository") {|o| options[:init] = o }
+ opts.on("--cap", "Adds config directory with basic deploy.rb") {|o| options[:cap] = o }
+ opts.on("--scripts", "Install the rubigen scripts (script/generate, script/destroy)") {|o| options[:scripts] = o }
opts.on("--git /path/to/git", "Specify a different path for 'git'") {|o| options[:git] = o }
opts.on("--test=test_framework", String, "Specify your testing framework (unit (default)/rspec/spec/shoulda)") {|o| options[:test_framework] = o }
opts.on("--views=view_framework", "Specify your view framework (erb (default)/haml/builder)") {|o| options[:view_framework] = o }
@@ -82,6 +90,7 @@ def extract_options
# raw instance variable value.
self.vendor = options[:vendor]
self.tiny = options[:tiny]
+ self.cap = options[:cap]
self.git = options[:git] || `which git`.strip
self.git_init = options[:init]
self.test_framework = options[:test_framework] || 'unit'
View
3 app_generators/sinatra_app/templates/Capfile
@@ -0,0 +1,3 @@
+load 'deploy' if respond_to?(:namespace) # cap2 differentiator
+Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
+load 'config/deploy'
View
1 app_generators/sinatra_app/templates/config.yml
@@ -0,0 +1 @@
+---
View
13 app_generators/sinatra_app/templates/config/deploy.rb.erb
@@ -0,0 +1,13 @@
+set :application, "<%= app_name %>"
+set :deploy_via, :remote_cache
+set :user, 'SERVER_USER_NAME'
+set :runner, user
+
+set :scm, :git
+set :repository, "git@github.com:GITHUB_USER_NAME/#{application}.git"
+set :branch, 'master'
+set :git_enable_submodules, 1
+set :keep_releases, 3
+set :deploy_to, "/var/www/apps/#{application}"
+
+server "YOUR_DOMAIN", :web, :app, :db, :primary => true
View
18 test/test_sinatra_app_generator.rb
@@ -48,19 +48,22 @@ def test_generate_app_with_tiny_option
assert_generated_file 'Rakefile'
end
- def test_generate_app_with_t_option
- run_generator('sinatra_app', [APP_ROOT, '-t'], sources)
- assert_generated_file 'config.ru'
- assert_generated_file 'app.rb'
- assert_generated_file 'Rakefile'
- end
-
def test_generate_app_with_init_option
run_generator('sinatra_app', [APP_ROOT, '-i'], sources)
assert_basic_paths_and_files
assert_directory_exists '.git'
end
+ def test_generate_app_with_cap_option
+ run_generator('sinatra_app', [APP_ROOT, '--cap'], sources)
+ assert_basic_paths_and_files
+ assert_directory_exists 'config'
+ assert_generated_file 'Capfile'
+ assert_generated_file 'config/deploy.rb' do |deploy_contents|
+ assert_match(/set \:application, "#{app_name}"/, deploy_contents)
+ end
+ end
+
def test_generate_app_with_rspect_test_option
run_generator('sinatra_app', [APP_ROOT, '--test=rspec'], sources)
assert_basic_paths_and_files
@@ -152,6 +155,7 @@ def assert_basic_paths_and_files
assert_generated_file 'config.ru'
assert_generated_file 'app.rb'
assert_generated_file 'Rakefile'
+ assert_generated_file 'config.yml'
assert_generated_module "lib/#{app_name}"
end

0 comments on commit aacaa79

Please sign in to comment.