Permalink
Browse files

Add --dev and --edge options to rails plugin new

  • Loading branch information...
1 parent 5c8b48a commit e51e9e2db0359355feef71e735a1f9cb764ec929 @drogus drogus committed Oct 20, 2010
View
34 railties/lib/rails/generators/app_base.rb
@@ -74,6 +74,40 @@ def set_default_accessors!
options[:template]
end
end
+
+ def rails_gemfile_entry
+ if options.dev?
+ <<-GEMFILE
+gem 'rails', :path => '#{Rails::Generators::RAILS_DEV_PATH}'
+gem 'arel', :git => 'git://github.com/rails/arel.git'
+gem "rack", :git => "git://github.com/rack/rack.git"
+ GEMFILE
+ elsif options.edge?
+ <<-GEMFILE
+gem 'rails', :git => 'git://github.com/rails/rails.git'
+gem 'arel', :git => 'git://github.com/rails/arel.git'
+gem "rack", :git => "git://github.com/rack/rack.git"
+ GEMFILE
+ else
+ <<-GEMFILE
+gem 'rails', '#{Rails::VERSION::STRING}'
+
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
+# gem 'arel', :git => 'git://github.com/rails/arel.git'
+# gem "rack", :git => "git://github.com/rack/rack.git"
+ GEMFILE
+ end
+ end
+
+ def bundle_if_dev_or_edge
+ bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle')
+ run "#{bundle_command} install" if dev_or_edge?
+ end
+
+ def dev_or_edge?
+ options.dev? || options.edge?
+ end
end
end
end
View
7 railties/lib/rails/generators/rails/app/app_generator.rb
@@ -302,8 +302,7 @@ def apply_rails_template
end
def bundle_if_dev_or_edge
- bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle')
- run "#{bundle_command} install" if dev_or_edge?
+ super
end
protected
@@ -354,10 +353,6 @@ def app_secret
ActiveSupport::SecureRandom.hex(64)
end
- def dev_or_edge?
- options.dev? || options.edge?
- end
-
def gem_for_database
# %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
case options[:database]
View
17 railties/lib/rails/generators/rails/app/templates/Gemfile
@@ -1,21 +1,6 @@
source 'http://rubygems.org'
-<%- if options.dev? -%>
-gem 'rails', :path => '<%= Rails::Generators::RAILS_DEV_PATH %>'
-gem 'arel', :git => 'git://github.com/rails/arel.git'
-gem "rack", :git => "git://github.com/rack/rack.git"
-<%- elsif options.edge? -%>
-gem 'rails', :git => 'git://github.com/rails/rails.git'
-gem 'arel', :git => 'git://github.com/rails/arel.git'
-gem "rack", :git => "git://github.com/rack/rack.git"
-<%- else -%>
-gem 'rails', '<%= Rails::VERSION::STRING %>'
-
-# Bundle edge Rails instead:
-# gem 'rails', :git => 'git://github.com/rails/rails.git'
-# gem 'arel', :git => 'git://github.com/rails/arel.git'
-# gem "rack", :git => "git://github.com/rack/rack.git"
-<%- end -%>
+<%= rails_gemfile_entry -%>
<% unless options[:skip_active_record] -%>
gem '<%= gem_for_database %>'<% if require_for_database %>, :require => '<%= require_for_database %>'<% end %>
View
10 railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
@@ -91,6 +91,12 @@ class PluginNewGenerator < AppBase
class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
:desc => "Skip Git ignores and keeps"
+ class_option :dev, :type => :boolean, :default => false,
+ :desc => "Setup the plugin with Gemfile pointing to your Rails checkout"
+
+ class_option :edge, :type => :boolean, :default => false,
+ :desc => "Setup the plugin with Gemfile pointing to Rails repository"
+
class_option :help, :type => :boolean, :aliases => "-h", :group => :rails,
:desc => "Show this help message and quit"
@@ -158,6 +164,10 @@ def apply_rails_template
super
end
+ def bundle_if_dev_or_edge
+ super
+ end
+
protected
def self.banner
View
5 railties/lib/rails/generators/rails/plugin_new/templates/Gemfile
@@ -1,8 +1,7 @@
source "http://rubygems.org"
-gem "rails", :git => "http://github.com/rails/rails.git"
-gem "arel" , :git => "http://github.com/rails/arel.git"
-gem "rack" , :git => "http://github.com/rack/rack.git"
+<%= rails_gemfile_entry -%>
+
gem "capybara", ">= 0.3.9"
gem "sqlite3-ruby", :require => "sqlite3"
View
13 railties/test/generators/plugin_new_generator_test.rb
@@ -130,6 +130,19 @@ def test_template_is_executed_when_supplied
assert_match /It works!/, silence(:stdout){ generator.invoke_all }
end
+ def test_dev_option
+ generator([destination_root], :dev => true).expects(:run).with("#{@bundle_command} install")
+ silence(:stdout){ generator.invoke_all }
+ rails_path = File.expand_path('../../..', Rails.root)
+ assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:path\s+=>\s+["']#{Regexp.escape(rails_path)}["']$/
+ end
+
+ def test_edge_option
+ generator([destination_root], :edge => true).expects(:run).with("#{@bundle_command} install")
+ silence(:stdout){ generator.invoke_all }
+ assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:git\s+=>\s+["']#{Regexp.escape("git://github.com/rails/rails.git")}["']$/
+ end
+
protected
def action(*args, &block)

0 comments on commit e51e9e2

Please sign in to comment.