From 738fc579f0dc95aad9ab0dedc65fbce7af0bb980 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 25 Oct 2008 09:35:51 +0000 Subject: [PATCH] Renames template ruby files to erb. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@1951 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- .../redmine_plugin_controller_generator.rb | 36 +++++++++++++++++++ .../{controller.rb => controller.rb.erb} | 0 ...ctional_test.rb => functional_test.rb.erb} | 0 .../templates/{helper.rb => helper.rb.erb} | 0 .../redmine_plugin_model_generator.rb | 26 ++++++++++++++ .../{migration.rb => migration.rb.erb} | 0 .../templates/{model.rb => model.rb.erb} | 0 .../{unit_test.rb => unit_test.rb.erb} | 0 8 files changed, 62 insertions(+) rename lib/generators/redmine_plugin_controller/templates/{controller.rb => controller.rb.erb} (100%) rename lib/generators/redmine_plugin_controller/templates/{functional_test.rb => functional_test.rb.erb} (100%) rename lib/generators/redmine_plugin_controller/templates/{helper.rb => helper.rb.erb} (100%) rename lib/generators/redmine_plugin_model/templates/{migration.rb => migration.rb.erb} (100%) rename lib/generators/redmine_plugin_model/templates/{model.rb => model.rb.erb} (100%) rename lib/generators/redmine_plugin_model/templates/{unit_test.rb => unit_test.rb.erb} (100%) diff --git a/lib/generators/redmine_plugin_controller/redmine_plugin_controller_generator.rb b/lib/generators/redmine_plugin_controller/redmine_plugin_controller_generator.rb index 533d65ce8..efe28c5da 100644 --- a/lib/generators/redmine_plugin_controller/redmine_plugin_controller_generator.rb +++ b/lib/generators/redmine_plugin_controller/redmine_plugin_controller_generator.rb @@ -15,4 +15,40 @@ class RedminePluginControllerGenerator < ControllerGenerator def destination_root File.join(RAILS_ROOT, plugin_path) end + + def manifest + record do |m| + # Check for class naming collisions. + m.class_collisions class_path, "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper" + + # Controller, helper, views, and test directories. + m.directory File.join('app/controllers', class_path) + m.directory File.join('app/helpers', class_path) + m.directory File.join('app/views', class_path, file_name) + m.directory File.join('test/functional', class_path) + + # Controller class, functional test, and helper class. + m.template 'controller.rb.erb', + File.join('app/controllers', + class_path, + "#{file_name}_controller.rb") + + m.template 'functional_test.rb.erb', + File.join('test/functional', + class_path, + "#{file_name}_controller_test.rb") + + m.template 'helper.rb.erb', + File.join('app/helpers', + class_path, + "#{file_name}_helper.rb") + + # View template for each action. + actions.each do |action| + path = File.join('app/views', class_path, file_name, "#{action}.html.erb") + m.template 'view.html.erb', path, + :assigns => { :action => action, :path => path } + end + end + end end diff --git a/lib/generators/redmine_plugin_controller/templates/controller.rb b/lib/generators/redmine_plugin_controller/templates/controller.rb.erb similarity index 100% rename from lib/generators/redmine_plugin_controller/templates/controller.rb rename to lib/generators/redmine_plugin_controller/templates/controller.rb.erb diff --git a/lib/generators/redmine_plugin_controller/templates/functional_test.rb b/lib/generators/redmine_plugin_controller/templates/functional_test.rb.erb similarity index 100% rename from lib/generators/redmine_plugin_controller/templates/functional_test.rb rename to lib/generators/redmine_plugin_controller/templates/functional_test.rb.erb diff --git a/lib/generators/redmine_plugin_controller/templates/helper.rb b/lib/generators/redmine_plugin_controller/templates/helper.rb.erb similarity index 100% rename from lib/generators/redmine_plugin_controller/templates/helper.rb rename to lib/generators/redmine_plugin_controller/templates/helper.rb.erb diff --git a/lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb b/lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb index b712d9b07..059a028d6 100644 --- a/lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb +++ b/lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb @@ -15,4 +15,30 @@ class RedminePluginModelGenerator < ModelGenerator def destination_root File.join(RAILS_ROOT, plugin_path) end + + def manifest + record do |m| + # Check for class naming collisions. + m.class_collisions class_path, class_name, "#{class_name}Test" + + # Model, test, and fixture directories. + m.directory File.join('app/models', class_path) + m.directory File.join('test/unit', class_path) + m.directory File.join('test/fixtures', class_path) + + # Model class, unit test, and fixtures. + m.template 'model.rb.erb', File.join('app/models', class_path, "#{file_name}.rb") + m.template 'unit_test.rb.erb', File.join('test/unit', class_path, "#{file_name}_test.rb") + + unless options[:skip_fixture] + m.template 'fixtures.yml', File.join('test/fixtures', "#{table_name}.yml") + end + + unless options[:skip_migration] + m.migration_template 'migration.rb.erb', 'db/migrate', :assigns => { + :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}" + }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}" + end + end + end end diff --git a/lib/generators/redmine_plugin_model/templates/migration.rb b/lib/generators/redmine_plugin_model/templates/migration.rb.erb similarity index 100% rename from lib/generators/redmine_plugin_model/templates/migration.rb rename to lib/generators/redmine_plugin_model/templates/migration.rb.erb diff --git a/lib/generators/redmine_plugin_model/templates/model.rb b/lib/generators/redmine_plugin_model/templates/model.rb.erb similarity index 100% rename from lib/generators/redmine_plugin_model/templates/model.rb rename to lib/generators/redmine_plugin_model/templates/model.rb.erb diff --git a/lib/generators/redmine_plugin_model/templates/unit_test.rb b/lib/generators/redmine_plugin_model/templates/unit_test.rb.erb similarity index 100% rename from lib/generators/redmine_plugin_model/templates/unit_test.rb rename to lib/generators/redmine_plugin_model/templates/unit_test.rb.erb