summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-08-10 14:57:05 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-08-10 14:57:05 +0000
commit2a04d6188b3fba0da3a7fce57302fd6225a594a3 (patch)
treed8bc488ef4fb39ae2db21f470f4245b675b4f377
parent74b942b34d67e42a9bd28faa762090791274af72 (diff)
downloadredmine-2a04d6188b3fba0da3a7fce57302fd6225a594a3.tar.gz
redmine-2a04d6188b3fba0da3a7fce57302fd6225a594a3.zip
Adds plugin controller and model generator.
git-svn-id: http://redmine.rubyforge.org/svn/branches/work@1726 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--hooks/lib/generators/redmine_plugin/redmine_plugin_generator.rb17
-rw-r--r--hooks/lib/generators/redmine_plugin_controller/USAGE5
-rw-r--r--hooks/lib/generators/redmine_plugin_controller/redmine_plugin_controller_generator.rb18
-rw-r--r--hooks/lib/generators/redmine_plugin_controller/templates/controller.rb7
-rw-r--r--hooks/lib/generators/redmine_plugin_controller/templates/functional_test.rb8
-rw-r--r--hooks/lib/generators/redmine_plugin_controller/templates/helper.rb2
-rw-r--r--hooks/lib/generators/redmine_plugin_controller/templates/view.html.erb1
-rw-r--r--hooks/lib/generators/redmine_plugin_model/USAGE5
-rw-r--r--hooks/lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb18
-rw-r--r--hooks/lib/generators/redmine_plugin_model/templates/fixtures.yml11
-rw-r--r--hooks/lib/generators/redmine_plugin_model/templates/migration.rb13
-rw-r--r--hooks/lib/generators/redmine_plugin_model/templates/model.rb2
-rw-r--r--hooks/lib/generators/redmine_plugin_model/templates/unit_test.rb10
13 files changed, 100 insertions, 17 deletions
diff --git a/hooks/lib/generators/redmine_plugin/redmine_plugin_generator.rb b/hooks/lib/generators/redmine_plugin/redmine_plugin_generator.rb
index 67f1f0933..2a7319f7b 100644
--- a/hooks/lib/generators/redmine_plugin/redmine_plugin_generator.rb
+++ b/hooks/lib/generators/redmine_plugin/redmine_plugin_generator.rb
@@ -1,20 +1,3 @@
-# redMine - project management software
-# Copyright (C) 2006-2008 Jean-Philippe Lang
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-
class RedminePluginGenerator < Rails::Generator::NamedBase
attr_reader :plugin_path, :plugin_name, :plugin_pretty_name
diff --git a/hooks/lib/generators/redmine_plugin_controller/USAGE b/hooks/lib/generators/redmine_plugin_controller/USAGE
new file mode 100644
index 000000000..8336e7117
--- /dev/null
+++ b/hooks/lib/generators/redmine_plugin_controller/USAGE
@@ -0,0 +1,5 @@
+Description:
+ Generates a plugin controller.
+
+Example:
+ ./script/generate redmine_plugin_controller MyPlugin Pools index show vote
diff --git a/hooks/lib/generators/redmine_plugin_controller/redmine_plugin_controller_generator.rb b/hooks/lib/generators/redmine_plugin_controller/redmine_plugin_controller_generator.rb
new file mode 100644
index 000000000..533d65ce8
--- /dev/null
+++ b/hooks/lib/generators/redmine_plugin_controller/redmine_plugin_controller_generator.rb
@@ -0,0 +1,18 @@
+require 'rails_generator/base'
+require 'rails_generator/generators/components/controller/controller_generator'
+
+class RedminePluginControllerGenerator < ControllerGenerator
+ attr_reader :plugin_path, :plugin_name, :plugin_pretty_name
+
+ def initialize(runtime_args, runtime_options = {})
+ runtime_args = runtime_args.dup
+ @plugin_name = "redmine_" + runtime_args.shift.underscore
+ @plugin_pretty_name = plugin_name.titleize
+ @plugin_path = "vendor/plugins/#{plugin_name}"
+ super(runtime_args, runtime_options)
+ end
+
+ def destination_root
+ File.join(RAILS_ROOT, plugin_path)
+ end
+end
diff --git a/hooks/lib/generators/redmine_plugin_controller/templates/controller.rb b/hooks/lib/generators/redmine_plugin_controller/templates/controller.rb
new file mode 100644
index 000000000..615986d9e
--- /dev/null
+++ b/hooks/lib/generators/redmine_plugin_controller/templates/controller.rb
@@ -0,0 +1,7 @@
+class <%= class_name %>Controller < ApplicationController
+<% actions.each do |action| -%>
+
+ def <%= action %>
+ end
+<% end -%>
+end
diff --git a/hooks/lib/generators/redmine_plugin_controller/templates/functional_test.rb b/hooks/lib/generators/redmine_plugin_controller/templates/functional_test.rb
new file mode 100644
index 000000000..38e0ae712
--- /dev/null
+++ b/hooks/lib/generators/redmine_plugin_controller/templates/functional_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class <%= class_name %>ControllerTest < ActionController::TestCase
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end
diff --git a/hooks/lib/generators/redmine_plugin_controller/templates/helper.rb b/hooks/lib/generators/redmine_plugin_controller/templates/helper.rb
new file mode 100644
index 000000000..3fe2ecdc7
--- /dev/null
+++ b/hooks/lib/generators/redmine_plugin_controller/templates/helper.rb
@@ -0,0 +1,2 @@
+module <%= class_name %>Helper
+end
diff --git a/hooks/lib/generators/redmine_plugin_controller/templates/view.html.erb b/hooks/lib/generators/redmine_plugin_controller/templates/view.html.erb
new file mode 100644
index 000000000..c24afaa6e
--- /dev/null
+++ b/hooks/lib/generators/redmine_plugin_controller/templates/view.html.erb
@@ -0,0 +1 @@
+<h2><%= class_name %>#<%= action %></h2>
diff --git a/hooks/lib/generators/redmine_plugin_model/USAGE b/hooks/lib/generators/redmine_plugin_model/USAGE
new file mode 100644
index 000000000..0cb55a186
--- /dev/null
+++ b/hooks/lib/generators/redmine_plugin_model/USAGE
@@ -0,0 +1,5 @@
+Description:
+ Generates a plugin model.
+
+Examples:
+ ./script/generate redmine_plugin_model MyPlugin pool title:string question:text
diff --git a/hooks/lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb b/hooks/lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb
new file mode 100644
index 000000000..b712d9b07
--- /dev/null
+++ b/hooks/lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb
@@ -0,0 +1,18 @@
+require 'rails_generator/base'
+require 'rails_generator/generators/components/model/model_generator'
+
+class RedminePluginModelGenerator < ModelGenerator
+ attr_accessor :plugin_path, :plugin_name, :plugin_pretty_name
+
+ def initialize(runtime_args, runtime_options = {})
+ runtime_args = runtime_args.dup
+ @plugin_name = "redmine_" + runtime_args.shift.underscore
+ @plugin_pretty_name = plugin_name.titleize
+ @plugin_path = "vendor/plugins/#{plugin_name}"
+ super(runtime_args, runtime_options)
+ end
+
+ def destination_root
+ File.join(RAILS_ROOT, plugin_path)
+ end
+end
diff --git a/hooks/lib/generators/redmine_plugin_model/templates/fixtures.yml b/hooks/lib/generators/redmine_plugin_model/templates/fixtures.yml
new file mode 100644
index 000000000..6be3c81be
--- /dev/null
+++ b/hooks/lib/generators/redmine_plugin_model/templates/fixtures.yml
@@ -0,0 +1,11 @@
+# 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/hooks/lib/generators/redmine_plugin_model/templates/migration.rb b/hooks/lib/generators/redmine_plugin_model/templates/migration.rb
new file mode 100644
index 000000000..2a305a6a9
--- /dev/null
+++ b/hooks/lib/generators/redmine_plugin_model/templates/migration.rb
@@ -0,0 +1,13 @@
+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/hooks/lib/generators/redmine_plugin_model/templates/model.rb b/hooks/lib/generators/redmine_plugin_model/templates/model.rb
new file mode 100644
index 000000000..8d4c89e91
--- /dev/null
+++ b/hooks/lib/generators/redmine_plugin_model/templates/model.rb
@@ -0,0 +1,2 @@
+class <%= class_name %> < ActiveRecord::Base
+end
diff --git a/hooks/lib/generators/redmine_plugin_model/templates/unit_test.rb b/hooks/lib/generators/redmine_plugin_model/templates/unit_test.rb
new file mode 100644
index 000000000..b464de47a
--- /dev/null
+++ b/hooks/lib/generators/redmine_plugin_model/templates/unit_test.rb
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
+
+class <%= class_name %>Test < Test::Unit::TestCase
+ fixtures :<%= table_name %>
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end