summaryrefslogtreecommitdiffstats
path: root/lib/generators
diff options
context:
space:
mode:
Diffstat (limited to 'lib/generators')
-rw-r--r--lib/generators/redmine_plugin/USAGE21
-rw-r--r--lib/generators/redmine_plugin/redmine_plugin_generator.rb47
-rw-r--r--lib/generators/redmine_plugin/templates/init.rb.erb2
-rw-r--r--lib/generators/redmine_plugin/templates/routes.rb2
-rw-r--r--lib/generators/redmine_plugin_controller/USAGE2
-rw-r--r--lib/generators/redmine_plugin_controller/redmine_plugin_controller_generator.rb64
-rw-r--r--lib/generators/redmine_plugin_controller/templates/controller.rb.erb2
-rw-r--r--lib/generators/redmine_plugin_controller/templates/functional_test.rb.erb2
-rw-r--r--lib/generators/redmine_plugin_controller/templates/helper.rb.erb2
-rw-r--r--lib/generators/redmine_plugin_controller/templates/view.html.erb2
-rw-r--r--lib/generators/redmine_plugin_model/USAGE2
-rw-r--r--lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb50
-rw-r--r--lib/generators/redmine_plugin_model/templates/fixtures.yml11
-rw-r--r--lib/generators/redmine_plugin_model/templates/migration.rb.erb13
-rw-r--r--lib/generators/redmine_plugin_model/templates/model.rb.erb2
-rw-r--r--lib/generators/redmine_plugin_model/templates/unit_test.rb.erb3
16 files changed, 69 insertions, 158 deletions
diff --git a/lib/generators/redmine_plugin/USAGE b/lib/generators/redmine_plugin/USAGE
index 1ed0dd591..01486f0d8 100644
--- a/lib/generators/redmine_plugin/USAGE
+++ b/lib/generators/redmine_plugin/USAGE
@@ -3,19 +3,8 @@ Description:
Example:
./script/generate redmine_plugin meetings
- create vendor/plugins/redmine_meetings/app/controllers
- create vendor/plugins/redmine_meetings/app/helpers
- create vendor/plugins/redmine_meetings/app/models
- create vendor/plugins/redmine_meetings/app/views
- create vendor/plugins/redmine_meetings/db/migrate
- create vendor/plugins/redmine_meetings/lib/tasks
- create vendor/plugins/redmine_meetings/assets/images
- create vendor/plugins/redmine_meetings/assets/javascripts
- create vendor/plugins/redmine_meetings/assets/stylesheets
- create vendor/plugins/redmine_meetings/lang
- create vendor/plugins/redmine_meetings/config/locales
- create vendor/plugins/redmine_meetings/test
- create vendor/plugins/redmine_meetings/README.rdoc
- create vendor/plugins/redmine_meetings/init.rb
- create vendor/plugins/redmine_meetings/config/locales/en.yml
- create vendor/plugins/redmine_meetings/test/test_helper.rb
+ create plugins/meetings/README.rdoc
+ create plugins/meetings/init.rb
+ create plugins/meetings/config/routes.rb
+ create plugins/meetings/config/locales/en.yml
+ create plugins/meetings/test/test_helper.rb
diff --git a/lib/generators/redmine_plugin/redmine_plugin_generator.rb b/lib/generators/redmine_plugin/redmine_plugin_generator.rb
index 0946d3ba0..8e1e4f822 100644
--- a/lib/generators/redmine_plugin/redmine_plugin_generator.rb
+++ b/lib/generators/redmine_plugin/redmine_plugin_generator.rb
@@ -1,32 +1,33 @@
-class RedminePluginGenerator < Rails::Generator::NamedBase
+class RedminePluginGenerator < Rails::Generators::NamedBase
+ source_root File.expand_path("../templates", __FILE__)
+
attr_reader :plugin_path, :plugin_name, :plugin_pretty_name
- def initialize(runtime_args, runtime_options = {})
+ def initialize(*args)
super
- @plugin_name = "redmine_#{file_name.underscore}"
+ @plugin_name = file_name.underscore
@plugin_pretty_name = plugin_name.titleize
- @plugin_path = "vendor/plugins/#{plugin_name}"
+ @plugin_path = "plugins/#{plugin_name}"
end
- def manifest
- record do |m|
- m.directory "#{plugin_path}/app/controllers"
- m.directory "#{plugin_path}/app/helpers"
- m.directory "#{plugin_path}/app/models"
- m.directory "#{plugin_path}/app/views"
- m.directory "#{plugin_path}/db/migrate"
- m.directory "#{plugin_path}/lib/tasks"
- m.directory "#{plugin_path}/assets/images"
- m.directory "#{plugin_path}/assets/javascripts"
- m.directory "#{plugin_path}/assets/stylesheets"
- m.directory "#{plugin_path}/lang"
- m.directory "#{plugin_path}/config/locales"
- m.directory "#{plugin_path}/test"
+ def copy_templates
+ empty_directory "#{plugin_path}/app"
+ empty_directory "#{plugin_path}/app/controllers"
+ empty_directory "#{plugin_path}/app/helpers"
+ empty_directory "#{plugin_path}/app/models"
+ empty_directory "#{plugin_path}/app/views"
+ empty_directory "#{plugin_path}/db/migrate"
+ empty_directory "#{plugin_path}/lib/tasks"
+ empty_directory "#{plugin_path}/assets/images"
+ empty_directory "#{plugin_path}/assets/javascripts"
+ empty_directory "#{plugin_path}/assets/stylesheets"
+ empty_directory "#{plugin_path}/config/locales"
+ empty_directory "#{plugin_path}/test"
- m.template 'README.rdoc', "#{plugin_path}/README.rdoc"
- m.template 'init.rb.erb', "#{plugin_path}/init.rb"
- m.template 'en_rails_i18n.yml', "#{plugin_path}/config/locales/en.yml"
- m.template 'test_helper.rb.erb', "#{plugin_path}/test/test_helper.rb"
- end
+ template 'README.rdoc', "#{plugin_path}/README.rdoc"
+ template 'init.rb.erb', "#{plugin_path}/init.rb"
+ template 'routes.rb', "#{plugin_path}/config/routes.rb"
+ template 'en_rails_i18n.yml', "#{plugin_path}/config/locales/en.yml"
+ template 'test_helper.rb.erb', "#{plugin_path}/test/test_helper.rb"
end
end
diff --git a/lib/generators/redmine_plugin/templates/init.rb.erb b/lib/generators/redmine_plugin/templates/init.rb.erb
index e6feded22..763ba7d22 100644
--- a/lib/generators/redmine_plugin/templates/init.rb.erb
+++ b/lib/generators/redmine_plugin/templates/init.rb.erb
@@ -1,5 +1,3 @@
-require 'redmine'
-
Redmine::Plugin.register :<%= plugin_name %> do
name '<%= plugin_pretty_name %> plugin'
author 'Author name'
diff --git a/lib/generators/redmine_plugin/templates/routes.rb b/lib/generators/redmine_plugin/templates/routes.rb
new file mode 100644
index 000000000..1803173d0
--- /dev/null
+++ b/lib/generators/redmine_plugin/templates/routes.rb
@@ -0,0 +1,2 @@
+# Plugin's routes
+# See: http://guides.rubyonrails.org/routing.html
diff --git a/lib/generators/redmine_plugin_controller/USAGE b/lib/generators/redmine_plugin_controller/USAGE
index 8336e7117..dc2a4b26b 100644
--- a/lib/generators/redmine_plugin_controller/USAGE
+++ b/lib/generators/redmine_plugin_controller/USAGE
@@ -2,4 +2,4 @@ Description:
Generates a plugin controller.
Example:
- ./script/generate redmine_plugin_controller MyPlugin Pools index show vote
+ ./script/generate redmine_plugin_controller meetings pools index show vote
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 71d7d106c..8351ce681 100644
--- a/lib/generators/redmine_plugin_controller/redmine_plugin_controller_generator.rb
+++ b/lib/generators/redmine_plugin_controller/redmine_plugin_controller_generator.rb
@@ -1,55 +1,27 @@
-require 'rails_generator/base'
-require 'rails_generator/generators/components/controller/controller_generator'
+class RedminePluginControllerGenerator < Rails::Generators::NamedBase
+ source_root File.expand_path("../templates", __FILE__)
+ argument :controller, :type => :string
+ argument :actions, :type => :array, :default => [], :banner => "ACTION ACTION ..."
-class RedminePluginControllerGenerator < ControllerGenerator
attr_reader :plugin_path, :plugin_name, :plugin_pretty_name
- def initialize(runtime_args, runtime_options = {})
- runtime_args = runtime_args.dup
- usage if runtime_args.empty?
- @plugin_name = "redmine_" + runtime_args.shift.underscore
+ def initialize(*args)
+ super
+ @plugin_name = file_name.underscore
@plugin_pretty_name = plugin_name.titleize
- @plugin_path = "vendor/plugins/#{plugin_name}"
- super(runtime_args, runtime_options)
+ @plugin_path = "plugins/#{plugin_name}"
+ @controller_class = controller.camelize
end
- 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
+ def copy_templates
+ template 'controller.rb.erb', "#{plugin_path}/app/controllers/#{controller}_controller.rb"
+ template 'helper.rb.erb', "#{plugin_path}/app/helpers/#{controller}_helper.rb"
+ template 'functional_test.rb.erb', "#{plugin_path}/test/functional/#{controller}_controller_test.rb"
+ # View template for each action.
+ actions.each do |action|
+ path = "#{plugin_path}/app/views/#{controller}/#{action}.html.erb"
+ @action_name = action
+ template 'view.html.erb', path
end
end
end
diff --git a/lib/generators/redmine_plugin_controller/templates/controller.rb.erb b/lib/generators/redmine_plugin_controller/templates/controller.rb.erb
index 2f4c70bd9..dddbf7017 100644
--- a/lib/generators/redmine_plugin_controller/templates/controller.rb.erb
+++ b/lib/generators/redmine_plugin_controller/templates/controller.rb.erb
@@ -1,4 +1,4 @@
-class <%= class_name %>Controller < ApplicationController
+class <%= @controller_class %>Controller < ApplicationController
unloadable
<% actions.each do |action| -%>
diff --git a/lib/generators/redmine_plugin_controller/templates/functional_test.rb.erb b/lib/generators/redmine_plugin_controller/templates/functional_test.rb.erb
index 876bd79e2..df332fd21 100644
--- a/lib/generators/redmine_plugin_controller/templates/functional_test.rb.erb
+++ b/lib/generators/redmine_plugin_controller/templates/functional_test.rb.erb
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../test_helper'
-class <%= class_name %>ControllerTest < ActionController::TestCase
+class <%= @controller_class %>ControllerTest < ActionController::TestCase
# Replace this with your real tests.
def test_truth
assert true
diff --git a/lib/generators/redmine_plugin_controller/templates/helper.rb.erb b/lib/generators/redmine_plugin_controller/templates/helper.rb.erb
index 3fe2ecdc7..059e12f3b 100644
--- a/lib/generators/redmine_plugin_controller/templates/helper.rb.erb
+++ b/lib/generators/redmine_plugin_controller/templates/helper.rb.erb
@@ -1,2 +1,2 @@
-module <%= class_name %>Helper
+module <%= @controller_class %>Helper
end
diff --git a/lib/generators/redmine_plugin_controller/templates/view.html.erb b/lib/generators/redmine_plugin_controller/templates/view.html.erb
index c24afaa6e..1fdb03dc7 100644
--- a/lib/generators/redmine_plugin_controller/templates/view.html.erb
+++ b/lib/generators/redmine_plugin_controller/templates/view.html.erb
@@ -1 +1 @@
-<h2><%= class_name %>#<%= action %></h2>
+<h2><%= @controller_class %>Controller#<%= @action_name %></h2>
diff --git a/lib/generators/redmine_plugin_model/USAGE b/lib/generators/redmine_plugin_model/USAGE
index 0cb55a186..f070d5493 100644
--- a/lib/generators/redmine_plugin_model/USAGE
+++ b/lib/generators/redmine_plugin_model/USAGE
@@ -2,4 +2,4 @@ Description:
Generates a plugin model.
Examples:
- ./script/generate redmine_plugin_model MyPlugin pool title:string question:text
+ ./script/generate redmine_plugin_model meetings pool
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 07aff1fb7..01ce31b1d 100644
--- a/lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb
+++ b/lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb
@@ -1,45 +1,19 @@
-require 'rails_generator/base'
-require 'rails_generator/generators/components/model/model_generator'
+class RedminePluginModelGenerator < Rails::Generators::NamedBase
+ source_root File.expand_path("../templates", __FILE__)
+ argument :model, :type => :string
-class RedminePluginModelGenerator < ModelGenerator
- attr_accessor :plugin_path, :plugin_name, :plugin_pretty_name
+ attr_reader :plugin_path, :plugin_name, :plugin_pretty_name
- def initialize(runtime_args, runtime_options = {})
- runtime_args = runtime_args.dup
- usage if runtime_args.empty?
- @plugin_name = "redmine_" + runtime_args.shift.underscore
+ def initialize(*args)
+ super
+ @plugin_name = file_name.underscore
@plugin_pretty_name = plugin_name.titleize
- @plugin_path = "vendor/plugins/#{plugin_name}"
- super(runtime_args, runtime_options)
+ @plugin_path = "plugins/#{plugin_name}"
+ @model_class = model.camelize
end
- 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
+ def copy_templates
+ template 'model.rb.erb', "#{plugin_path}/app/models/#{model}.rb"
+ template 'unit_test.rb.erb', "#{plugin_path}/test/unit/#{model}_test.rb"
end
end
diff --git a/lib/generators/redmine_plugin_model/templates/fixtures.yml b/lib/generators/redmine_plugin_model/templates/fixtures.yml
deleted file mode 100644
index 6be3c81be..000000000
--- a/lib/generators/redmine_plugin_model/templates/fixtures.yml
+++ /dev/null
@@ -1,11 +0,0 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-one:
- id: 1
-<% for attribute in attributes -%>
- <%= attribute.name %>: <%= attribute.default %>
-<% end -%>
-two:
- id: 2
-<% for attribute in attributes -%>
- <%= attribute.name %>: <%= attribute.default %>
-<% end -%>
diff --git a/lib/generators/redmine_plugin_model/templates/migration.rb.erb b/lib/generators/redmine_plugin_model/templates/migration.rb.erb
deleted file mode 100644
index 2a305a6a9..000000000
--- a/lib/generators/redmine_plugin_model/templates/migration.rb.erb
+++ /dev/null
@@ -1,13 +0,0 @@
-class <%= migration_name %> < ActiveRecord::Migration
- def self.up
- create_table :<%= table_name %> do |t|
-<% for attribute in attributes -%>
- t.column :<%= attribute.name %>, :<%= attribute.type %>
-<% end -%>
- end
- end
-
- def self.down
- drop_table :<%= table_name %>
- end
-end
diff --git a/lib/generators/redmine_plugin_model/templates/model.rb.erb b/lib/generators/redmine_plugin_model/templates/model.rb.erb
index e730492b0..71284e96d 100644
--- a/lib/generators/redmine_plugin_model/templates/model.rb.erb
+++ b/lib/generators/redmine_plugin_model/templates/model.rb.erb
@@ -1,3 +1,3 @@
-class <%= class_name %> < ActiveRecord::Base
+class <%= @model_class %> < ActiveRecord::Base
unloadable
end
diff --git a/lib/generators/redmine_plugin_model/templates/unit_test.rb.erb b/lib/generators/redmine_plugin_model/templates/unit_test.rb.erb
index bc6ae913b..531510470 100644
--- a/lib/generators/redmine_plugin_model/templates/unit_test.rb.erb
+++ b/lib/generators/redmine_plugin_model/templates/unit_test.rb.erb
@@ -1,7 +1,6 @@
require File.dirname(__FILE__) + '/../test_helper'
-class <%= class_name %>Test < ActiveSupport::TestCase
- fixtures :<%= table_name %>
+class <%= @model_class %>Test < ActiveSupport::TestCase
# Replace this with your real tests.
def test_truth