From 5e57a1a9d9478162ac4f27ae96b2ccaf55a1aba7 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 25 Apr 2012 17:17:49 +0000 Subject: Merged rails-3.2 branch. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9528 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/generators/redmine_plugin_controller/USAGE | 2 +- .../redmine_plugin_controller_generator.rb | 64 ++++++---------------- .../templates/controller.rb.erb | 2 +- .../templates/functional_test.rb.erb | 2 +- .../templates/helper.rb.erb | 2 +- .../templates/view.html.erb | 2 +- 6 files changed, 23 insertions(+), 51 deletions(-) (limited to 'lib/generators/redmine_plugin_controller') 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 @@ -

<%= class_name %>#<%= action %>

+

<%= @controller_class %>Controller#<%= @action_name %>

-- cgit v1.2.3