diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-04-25 17:17:49 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-04-25 17:17:49 +0000 |
commit | 5e57a1a9d9478162ac4f27ae96b2ccaf55a1aba7 (patch) | |
tree | 93e57765139714bd82dede475725516c448c0d55 /lib/generators/redmine_plugin_controller | |
parent | 34e20c4373b7f5a20ab3a132feae3f70f21ec477 (diff) | |
download | redmine-5e57a1a9d9478162ac4f27ae96b2ccaf55a1aba7.tar.gz redmine-5e57a1a9d9478162ac4f27ae96b2ccaf55a1aba7.zip |
Merged rails-3.2 branch.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9528 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/generators/redmine_plugin_controller')
6 files changed, 23 insertions, 51 deletions
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> |