diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2012-01-07 18:53:49 +0100 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2012-01-07 19:14:27 +0100 |
commit | 8ac53db5eedca8f2605ef7f91bbc956018ae1c50 (patch) | |
tree | e462acb200616e0a24c56d6f6427ca93013d90ce /railties/lib/rails | |
parent | 089bc761f89cf8dab71c448344fe4a8c5edb296f (diff) | |
download | rails-8ac53db5eedca8f2605ef7f91bbc956018ae1c50.tar.gz rails-8ac53db5eedca8f2605ef7f91bbc956018ae1c50.tar.bz2 rails-8ac53db5eedca8f2605ef7f91bbc956018ae1c50.zip |
Add Gemfile entry when creating a plugin in application's directory
After vendor/plugins were removed from rails, the new method to create
plugins is to create gem plugins. Most of the time if you create a
new plugin in rails application's directory, you want to extract
something from that application and use it immediately, ie. add
such line to Gemfile:
gem 'foo', :path => './vendor/foo'
This commit makes plugin new generator to add such line automatically.
Diffstat (limited to 'railties/lib/rails')
-rw-r--r-- | railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb index cd7d51e628..0e900a34bb 100644 --- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb @@ -133,6 +133,16 @@ task :default => :test end chmod "script", 0755, :verbose => false end + + def gemfile_entry + return unless inside_application? + + gemfile_in_app_path = File.join(rails_app_path, "Gemfile") + if File.exist? gemfile_in_app_path + entry = "gem '#{name}', :path => '#{relative_path}'" + append_file gemfile_in_app_path, entry + end + end end module Generators @@ -153,6 +163,10 @@ task :default => :test class_option :skip_gemspec, :type => :boolean, :default => false, :desc => "Skip gemspec file" + class_option :skip_gemfile_entry, :type => :boolean, :default => false, + :desc => "If creating plugin in application's directory " + + "skip adding entry to Gemfile" + def initialize(*args) raise Error, "Options should be given after the plugin name. For details run: rails plugin --help" if args[0].blank? @@ -208,6 +222,10 @@ task :default => :test create_dummy_app end + def update_gemfile + build(:gemfile_entry) unless options[:skip_gemfile_entry] + end + def finish_template build(:leftovers) end @@ -313,6 +331,19 @@ end def mute(&block) shell.mute(&block) end + + def rails_app_path + APP_PATH.sub("/config/application", "") if defined?(APP_PATH) + end + + def inside_application? + rails_app_path && app_path =~ /^#{rails_app_path}/ + end + + def relative_path + return unless inside_application? + app_path.sub(/^#{rails_app_path}\//, '') + end end end end |