@@ -1,42 +1,37 | |||
|
1 | 1 | class RedminePluginGenerator < Rails::Generators::NamedBase |
|
2 | 2 | source_root File.expand_path("../templates", __FILE__) |
|
3 | 3 | |
|
4 | 4 | attr_reader :plugin_path, :plugin_name, :plugin_pretty_name |
|
5 | 5 | |
|
6 | 6 | def initialize(*args) |
|
7 | 7 | super |
|
8 | 8 | @plugin_name = file_name.underscore |
|
9 | 9 | @plugin_pretty_name = plugin_name.titleize |
|
10 | if Redmine::Configuration['plugins_path'].nil? | |
|
11 | @plugin_path = File.join(Rails.root, 'plugins', plugin_name) | |
|
12 | else | |
|
13 | @plugin_path = File.join(Redmine::Configuration['plugins_path'], plugin_name) | |
|
14 | end | |
|
15 | puts @plugin_path | |
|
10 | @plugin_path = File.join(Redmine::Plugin.directory, plugin_name) | |
|
16 | 11 | end |
|
17 | 12 | |
|
18 | 13 | def copy_templates |
|
19 | 14 | empty_directory "#{plugin_path}/app" |
|
20 | 15 | empty_directory "#{plugin_path}/app/controllers" |
|
21 | 16 | empty_directory "#{plugin_path}/app/helpers" |
|
22 | 17 | empty_directory "#{plugin_path}/app/models" |
|
23 | 18 | empty_directory "#{plugin_path}/app/views" |
|
24 | 19 | empty_directory "#{plugin_path}/db/migrate" |
|
25 | 20 | empty_directory "#{plugin_path}/lib/tasks" |
|
26 | 21 | empty_directory "#{plugin_path}/assets/images" |
|
27 | 22 | empty_directory "#{plugin_path}/assets/javascripts" |
|
28 | 23 | empty_directory "#{plugin_path}/assets/stylesheets" |
|
29 | 24 | empty_directory "#{plugin_path}/config/locales" |
|
30 | 25 | empty_directory "#{plugin_path}/test" |
|
31 | 26 | empty_directory "#{plugin_path}/test/fixtures" |
|
32 | 27 | empty_directory "#{plugin_path}/test/unit" |
|
33 | 28 | empty_directory "#{plugin_path}/test/functional" |
|
34 | 29 | empty_directory "#{plugin_path}/test/integration" |
|
35 | 30 | |
|
36 | 31 | template 'README.rdoc', "#{plugin_path}/README.rdoc" |
|
37 | 32 | template 'init.rb.erb', "#{plugin_path}/init.rb" |
|
38 | 33 | template 'routes.rb', "#{plugin_path}/config/routes.rb" |
|
39 | 34 | template 'en_rails_i18n.yml', "#{plugin_path}/config/locales/en.yml" |
|
40 | 35 | template 'test_helper.rb.erb', "#{plugin_path}/test/test_helper.rb" |
|
41 | 36 | end |
|
42 | 37 | end |
@@ -1,31 +1,27 | |||
|
1 | 1 | class RedminePluginControllerGenerator < Rails::Generators::NamedBase |
|
2 | 2 | source_root File.expand_path("../templates", __FILE__) |
|
3 | 3 | argument :controller, :type => :string |
|
4 | 4 | argument :actions, :type => :array, :default => [], :banner => "ACTION ACTION ..." |
|
5 | 5 | |
|
6 | 6 | attr_reader :plugin_path, :plugin_name, :plugin_pretty_name |
|
7 | 7 | |
|
8 | 8 | def initialize(*args) |
|
9 | 9 | super |
|
10 | 10 | @plugin_name = file_name.underscore |
|
11 | 11 | @plugin_pretty_name = plugin_name.titleize |
|
12 | if Redmine::Configuration['plugins_path'].nil? | |
|
13 | @plugin_path = File.join(Rails.root, 'plugins', plugin_name) | |
|
14 | else | |
|
15 | @plugin_path = File.join(Redmine::Configuration['plugins_path'], plugin_name) | |
|
16 | end | |
|
12 | @plugin_path = File.join(Redmine::Plugin.directory, plugin_name) | |
|
17 | 13 | @controller_class = controller.camelize |
|
18 | 14 | end |
|
19 | 15 | |
|
20 | 16 | def copy_templates |
|
21 | 17 | template 'controller.rb.erb', "#{plugin_path}/app/controllers/#{controller}_controller.rb" |
|
22 | 18 | template 'helper.rb.erb', "#{plugin_path}/app/helpers/#{controller}_helper.rb" |
|
23 | 19 | template 'functional_test.rb.erb', "#{plugin_path}/test/functional/#{controller}_controller_test.rb" |
|
24 | 20 | # View template for each action. |
|
25 | 21 | actions.each do |action| |
|
26 | 22 | path = "#{plugin_path}/app/views/#{controller}/#{action}.html.erb" |
|
27 | 23 | @action_name = action |
|
28 | 24 | template 'view.html.erb', path |
|
29 | 25 | end |
|
30 | 26 | end |
|
31 | 27 | end |
@@ -1,45 +1,41 | |||
|
1 | 1 | class RedminePluginModelGenerator < Rails::Generators::NamedBase |
|
2 | 2 | |
|
3 | 3 | source_root File.expand_path("../templates", __FILE__) |
|
4 | 4 | argument :model, :type => :string |
|
5 | 5 | argument :attributes, :type => :array, :default => [], :banner => "field[:type][:index] field[:type][:index]" |
|
6 | 6 | class_option :migration, :type => :boolean |
|
7 | 7 | class_option :timestamps, :type => :boolean |
|
8 | 8 | class_option :parent, :type => :string, :desc => "The parent class for the generated model" |
|
9 | 9 | class_option :indexes, :type => :boolean, :default => true, :desc => "Add indexes for references and belongs_to columns" |
|
10 | 10 | |
|
11 | 11 | attr_reader :plugin_path, :plugin_name, :plugin_pretty_name |
|
12 | 12 | |
|
13 | 13 | def initialize(*args) |
|
14 | 14 | super |
|
15 | 15 | @plugin_name = file_name.underscore |
|
16 | 16 | @plugin_pretty_name = plugin_name.titleize |
|
17 | if Redmine::Configuration['plugins_path'].nil? | |
|
18 | @plugin_path = File.join(Rails.root, 'plugins', plugin_name) | |
|
19 | else | |
|
20 | @plugin_path = File.join(Redmine::Configuration['plugins_path'], plugin_name) | |
|
21 | end | |
|
17 | @plugin_path = File.join(Redmine::Plugin.directory, plugin_name) | |
|
22 | 18 | @model_class = model.camelize |
|
23 | 19 | @table_name = @model_class.tableize |
|
24 | 20 | @migration_filename = "create_#{@table_name}" |
|
25 | 21 | @migration_class_name = @migration_filename.camelize |
|
26 | 22 | end |
|
27 | 23 | |
|
28 | 24 | def copy_templates |
|
29 | 25 | template 'model.rb.erb', "#{plugin_path}/app/models/#{model.underscore}.rb" |
|
30 | 26 | template 'unit_test.rb.erb', "#{plugin_path}/test/unit/#{model.underscore}_test.rb" |
|
31 | 27 | |
|
32 | 28 | migration_filename = "%03i_#{@migration_filename}.rb" % (migration_number + 1) |
|
33 | 29 | template "migration.rb", "#{plugin_path}/db/migrate/#{migration_filename}" |
|
34 | 30 | end |
|
35 | 31 | |
|
36 | 32 | def attributes_with_index |
|
37 | 33 | attributes.select { |a| a.has_index? || (a.reference? && options[:indexes]) } |
|
38 | 34 | end |
|
39 | 35 | |
|
40 | 36 | def migration_number |
|
41 | 37 | current = Dir.glob("#{plugin_path}/db/migrate/*.rb").map do |file| |
|
42 | 38 | File.basename(file).split("_").first.to_i |
|
43 | 39 | end.max.to_i |
|
44 | 40 | end |
|
45 | 41 | end |
General Comments 0
You need to be logged in to leave comments.
Login now