@@ -1,55 +1,55 | |||||
1 | require 'rails_generator/base' |
|
1 | require 'rails_generator/base' | |
2 | require 'rails_generator/generators/components/controller/controller_generator' |
|
2 | require 'rails_generator/generators/components/controller/controller_generator' | |
3 |
|
3 | |||
4 | class RedminePluginControllerGenerator < ControllerGenerator |
|
4 | class RedminePluginControllerGenerator < ControllerGenerator | |
5 | attr_reader :plugin_path, :plugin_name, :plugin_pretty_name |
|
5 | attr_reader :plugin_path, :plugin_name, :plugin_pretty_name | |
6 |
|
6 | |||
7 | def initialize(runtime_args, runtime_options = {}) |
|
7 | def initialize(runtime_args, runtime_options = {}) | |
8 | runtime_args = runtime_args.dup |
|
8 | runtime_args = runtime_args.dup | |
9 | usage if runtime_args.empty? |
|
9 | usage if runtime_args.empty? | |
10 | @plugin_name = "redmine_" + runtime_args.shift.underscore |
|
10 | @plugin_name = "redmine_" + runtime_args.shift.underscore | |
11 | @plugin_pretty_name = plugin_name.titleize |
|
11 | @plugin_pretty_name = plugin_name.titleize | |
12 | @plugin_path = "vendor/plugins/#{plugin_name}" |
|
12 | @plugin_path = "vendor/plugins/#{plugin_name}" | |
13 | super(runtime_args, runtime_options) |
|
13 | super(runtime_args, runtime_options) | |
14 | end |
|
14 | end | |
15 |
|
15 | |||
16 | def destination_root |
|
16 | def destination_root | |
17 |
File.join(R |
|
17 | File.join(Rails.root, plugin_path) | |
18 | end |
|
18 | end | |
19 |
|
19 | |||
20 | def manifest |
|
20 | def manifest | |
21 | record do |m| |
|
21 | record do |m| | |
22 | # Check for class naming collisions. |
|
22 | # Check for class naming collisions. | |
23 | m.class_collisions class_path, "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper" |
|
23 | m.class_collisions class_path, "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper" | |
24 |
|
24 | |||
25 | # Controller, helper, views, and test directories. |
|
25 | # Controller, helper, views, and test directories. | |
26 | m.directory File.join('app/controllers', class_path) |
|
26 | m.directory File.join('app/controllers', class_path) | |
27 | m.directory File.join('app/helpers', class_path) |
|
27 | m.directory File.join('app/helpers', class_path) | |
28 | m.directory File.join('app/views', class_path, file_name) |
|
28 | m.directory File.join('app/views', class_path, file_name) | |
29 | m.directory File.join('test/functional', class_path) |
|
29 | m.directory File.join('test/functional', class_path) | |
30 |
|
30 | |||
31 | # Controller class, functional test, and helper class. |
|
31 | # Controller class, functional test, and helper class. | |
32 | m.template 'controller.rb.erb', |
|
32 | m.template 'controller.rb.erb', | |
33 | File.join('app/controllers', |
|
33 | File.join('app/controllers', | |
34 | class_path, |
|
34 | class_path, | |
35 | "#{file_name}_controller.rb") |
|
35 | "#{file_name}_controller.rb") | |
36 |
|
36 | |||
37 | m.template 'functional_test.rb.erb', |
|
37 | m.template 'functional_test.rb.erb', | |
38 | File.join('test/functional', |
|
38 | File.join('test/functional', | |
39 | class_path, |
|
39 | class_path, | |
40 | "#{file_name}_controller_test.rb") |
|
40 | "#{file_name}_controller_test.rb") | |
41 |
|
41 | |||
42 | m.template 'helper.rb.erb', |
|
42 | m.template 'helper.rb.erb', | |
43 | File.join('app/helpers', |
|
43 | File.join('app/helpers', | |
44 | class_path, |
|
44 | class_path, | |
45 | "#{file_name}_helper.rb") |
|
45 | "#{file_name}_helper.rb") | |
46 |
|
46 | |||
47 | # View template for each action. |
|
47 | # View template for each action. | |
48 | actions.each do |action| |
|
48 | actions.each do |action| | |
49 | path = File.join('app/views', class_path, file_name, "#{action}.html.erb") |
|
49 | path = File.join('app/views', class_path, file_name, "#{action}.html.erb") | |
50 | m.template 'view.html.erb', path, |
|
50 | m.template 'view.html.erb', path, | |
51 | :assigns => { :action => action, :path => path } |
|
51 | :assigns => { :action => action, :path => path } | |
52 | end |
|
52 | end | |
53 | end |
|
53 | end | |
54 | end |
|
54 | end | |
55 | end |
|
55 | end |
General Comments 0
You need to be logged in to leave comments.
Login now