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