From d1c404ee90ea7470d662517aa7a2d312a61c8c61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 3 Jul 2009 12:10:09 +0200 Subject: Added lookup to generators. --- .../generators/rails/plugin/plugin_generator.rb | 47 +++++++++------------- 1 file changed, 20 insertions(+), 27 deletions(-) (limited to 'railties/lib/generators/rails/plugin') diff --git a/railties/lib/generators/rails/plugin/plugin_generator.rb b/railties/lib/generators/rails/plugin/plugin_generator.rb index ec563be805..9eaf902021 100644 --- a/railties/lib/generators/rails/plugin/plugin_generator.rb +++ b/railties/lib/generators/rails/plugin/plugin_generator.rb @@ -1,51 +1,44 @@ module Rails module Generators class PluginGenerator < NamedBase - class_option :with_tasks, :type => :boolean, :aliases => "-r", :default => false, - :desc => "When supplied creates tasks base files." + class_option :tasks, :type => :boolean, :aliases => "-t", :default => false, + :desc => "When supplied creates tasks base files." - class_option :with_generator, :type => :boolean, :aliases => "-g", :default => false, - :desc => "When supplied creates generator base files." + class_option :generator, :type => :boolean, :aliases => "-g", :default => false, + :desc => "When supplied creates generator base files." check_class_collision - def create_root - self.root = File.expand_path("vendor/plugins/#{file_name}", root) - empty_directory '.' if behavior == :invoke - FileUtils.cd(root) - end - def create_root_files - %w(README MIT-LICENSE Rakefile init.rb install.rb uninstall.rb).each do |file| - template file - end + directory '.', plugin_dir, false # non-recursive end def create_lib_files - directory 'lib' + directory 'lib', plugin_dir('lib'), false # non-recursive end hook_for :test_framework def create_tasks_files - return unless options[:with_tasks] - directory 'tasks' + return unless options[:tasks] + directory 'tasks', plugin_dir('tasks') end def create_generator_files - return unless options[:with_generator] - directory 'generators' + return unless options[:generator] + directory 'generators', plugin_dir('generators') end - # Work around for generator to work on revoke. If we remove the root - # folder at the beginning, it will raise an error since FileUtils.cd - # will move to a non-existent folder. - # - def remove_on_revoke - return unless behavior == :revoke - FileUtils.cd("../../..") - empty_directory "vendor/plugins/#{file_name}" - end + protected + + def plugin_dir(join=nil) + if join + File.join(plugin_dir, join) + else + "vendor/plugins/#{file_name}" + end + end + end end end -- cgit v1.2.3