Permalink
Browse files

Added a --script option for installing the rubigen scripts

  • Loading branch information...
quirkey committed Dec 13, 2008
1 parent 1979246 commit 3edd2670829afcb734f146b6aedf9ebf5951d87d
Showing with 22 additions and 15 deletions.
  1. +1 −0 README.rdoc
  2. +14 −15 app_generators/sinatra_app/sinatra_app_generator.rb
  3. +7 −0 test/test_sinatra_app_generator.rb
View
@@ -25,6 +25,7 @@ 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
--git /path/to/git Specify a different path for 'git'
--test=test_framework Specify your testing framework (unit (default)/rspec/spec/shoulda)
@@ -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
+ attr_accessor :app_name, :vendor, :tiny, :git, :git_init, :test_framework, :view_framework, :install_scripts
def initialize(runtime_args, runtime_options = {})
super
@@ -27,9 +27,7 @@ def manifest
m.template 'config.ru.erb', 'config.ru'
m.template 'app.rb.erb' , 'app.rb'
m.template 'Rakefile.erb' , 'Rakefile'
- # m.dependency "install_rubigen_scripts", [destination_root, 'sinatra-gen'],
- # :shebang => options[:shebang], :collision => :force
-
+
unless tiny
BASEDIRS.each { |path| m.directory path }
m.template 'lib/module.rb.erb', "lib/#{app_name}.rb"
@@ -49,6 +47,9 @@ def manifest
`#{command}`
end
+ if install_scripts
+ m.dependency "install_rubigen_scripts", [destination_root, 'sinatra-gen'], :shebang => options[:shebang], :collision => :force
+ end
end
end
@@ -64,15 +65,12 @@ def banner
def add_options!(opts)
opts.separator ''
opts.separator 'Options:'
- # For each option below, place the default
- # at the top of the file next to "default_options"
- # opts.on("-a", "--author=\"Your Name\"", String,
- # "Some comment about this option",
- # "Default: none") { |options[:author]| }
+
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("--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,12 +80,13 @@ def extract_options
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
# Templates can access these value via the attr_reader-generated methods, but not the
# raw instance variable value.
- self.vendor = options[:vendor]
- self.tiny = options[:tiny]
- self.git = options[:git] || `which git`.strip
- self.git_init = options[:init]
- self.test_framework = options[:test_framework] || 'unit'
- self.view_framework = options[:view_framework] || 'erb'
+ self.vendor = options[:vendor]
+ self.tiny = options[:tiny]
+ self.git = options[:git] || `which git`.strip
+ self.git_init = options[:init]
+ self.test_framework = options[:test_framework] || 'unit'
+ self.view_framework = options[:view_framework] || 'erb'
+ self.install_scripts = options[:scripts] || false
end
def klass_name
@@ -128,6 +128,13 @@ def test_generate_app_with_views_builder_option
assert_generated_file 'views/index.builder'
end
+ def test_generate_app_with_scripts_option
+ run_generator('sinatra_app', [APP_ROOT, '--scripts'], sources)
+ assert_basic_paths_and_files
+ assert_directory_exists 'script'
+ assert_generated_file 'script/destroy'
+ assert_generated_file 'script/generate'
+ end
private
def assert_basic_paths_and_files

0 comments on commit 3edd267

Please sign in to comment.