Feature #27705 » 0002-Add-redmine_plugin_gem-generator.patch
lib/generators/redmine_plugin_gem/USAGE | ||
---|---|---|
1 |
Description: |
|
2 |
The plugin generator creates stubs for a new Redmine plugin. |
|
3 | ||
4 |
Example: |
|
5 |
bundle exec rails generate redmine_plugin_gem meetings |
|
6 |
create gems/meetings/app |
|
7 |
create gems/meetings/app/controllers |
|
8 |
create gems/meetings/app/helpers |
|
9 |
create gems/meetings/app/models |
|
10 |
create gems/meetings/app/views |
|
11 |
create gems/meetings/db/migrate |
|
12 |
create gems/meetings/lib/tasks |
|
13 |
create gems/meetings/assets/images |
|
14 |
create gems/meetings/assets/javascripts |
|
15 |
create gems/meetings/assets/stylesheets |
|
16 |
create gems/meetings/config/locales |
|
17 |
create gems/meetings/test |
|
18 |
create gems/meetings/test/fixtures |
|
19 |
create gems/meetings/test/unit |
|
20 |
create gems/meetings/test/functional |
|
21 |
create gems/meetings/test/integration |
|
22 |
create gems/meetings/Gemfile |
|
23 |
create gems/meetings/Rakefile |
|
24 |
create gems/meetings/README.rdoc |
|
25 |
create gems/meetings/init.rb |
|
26 |
create gems/meetings/meetings.gemspec |
|
27 |
create gems/meetings/config/routes.rb |
|
28 |
create gems/meetings/config/locales/en.yml |
|
29 |
create gems/meetings/test/test_helper.rb |
lib/generators/redmine_plugin_gem/redmine_plugin_gem_generator.rb | ||
---|---|---|
1 |
# frozen_string_literal: true |
|
2 | ||
3 |
# Redmine - project management software |
|
4 |
# Copyright (C) 2006-2023 Jean-Philippe Lang |
|
5 |
# |
|
6 |
# This program is free software; you can redistribute it and/or |
|
7 |
# modify it under the terms of the GNU General Public License |
|
8 |
# as published by the Free Software Foundation; either version 2 |
|
9 |
# of the License, or (at your option) any later version. |
|
10 |
# |
|
11 |
# This program is distributed in the hope that it will be useful, |
|
12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
# GNU General Public License for more details. |
|
15 |
# |
|
16 |
# You should have received a copy of the GNU General Public License |
|
17 |
# along with this program; if not, write to the Free Software |
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
19 | ||
20 |
class RedminePluginGemGenerator < Rails::Generators::NamedBase |
|
21 |
source_root File.expand_path('templates', __dir__) |
|
22 | ||
23 |
attr_reader :gem_path, :plugin_name, :plugin_pretty_name |
|
24 | ||
25 |
def initialize(*args) |
|
26 |
super |
|
27 |
@plugin_name = file_name.underscore |
|
28 |
@plugin_pretty_name = plugin_name.titleize |
|
29 |
@gem_path = Rails.root.join('gems', plugin_name) |
|
30 |
end |
|
31 | ||
32 |
def copy_templates |
|
33 |
empty_directory "#{gem_path}/app" |
|
34 |
empty_directory "#{gem_path}/app/controllers" |
|
35 |
empty_directory "#{gem_path}/app/helpers" |
|
36 |
empty_directory "#{gem_path}/app/models" |
|
37 |
empty_directory "#{gem_path}/app/views" |
|
38 |
empty_directory "#{gem_path}/db/migrate" |
|
39 |
empty_directory "#{gem_path}/lib/tasks" |
|
40 |
empty_directory "#{gem_path}/assets/images" |
|
41 |
empty_directory "#{gem_path}/assets/javascripts" |
|
42 |
empty_directory "#{gem_path}/assets/stylesheets" |
|
43 |
empty_directory "#{gem_path}/config/locales" |
|
44 |
empty_directory "#{gem_path}/test" |
|
45 |
empty_directory "#{gem_path}/test/fixtures" |
|
46 |
empty_directory "#{gem_path}/test/unit" |
|
47 |
empty_directory "#{gem_path}/test/functional" |
|
48 |
empty_directory "#{gem_path}/test/integration" |
|
49 |
empty_directory "#{gem_path}/test/system" |
|
50 | ||
51 |
template 'README.rdoc', "#{gem_path}/README.rdoc" |
|
52 |
template 'Gemfile.erb', "#{gem_path}/Gemfile" |
|
53 |
template 'Rakefile', "#{gem_path}/Rakefile" |
|
54 |
template 'init.rb.erb', "#{gem_path}/init.rb" |
|
55 |
template 'routes.rb', "#{gem_path}/config/routes.rb" |
|
56 |
template 'en_rails_i18n.yml', "#{gem_path}/config/locales/en.yml" |
|
57 |
template 'test_helper.rb.erb', "#{gem_path}/test/test_helper.rb" |
|
58 |
template 'gemspec.erb', "#{gem_path}/#{plugin_name}.gemspec" |
|
59 |
end |
|
60 |
end |
lib/generators/redmine_plugin_gem/templates/Gemfile.erb | ||
---|---|---|
1 |
# frozen_string_literal: true |
|
2 | ||
3 |
source "https://rubygems.org" |
|
4 | ||
5 |
# Specify your gem's dependencies in <%= plugin_name %>.gemspec |
|
6 |
gemspec |
|
7 |
lib/generators/redmine_plugin_gem/templates/README.rdoc | ||
---|---|---|
1 |
= <%= file_name %> |
|
2 | ||
3 |
Description goes here |
lib/generators/redmine_plugin_gem/templates/Rakefile | ||
---|---|---|
1 |
# frozen_string_literal: true |
|
2 | ||
3 |
require "bundler/gem_tasks" |
|
4 |
task default: [] |
lib/generators/redmine_plugin_gem/templates/en_rails_i18n.yml | ||
---|---|---|
1 |
# English strings go here for Rails i18n |
|
2 |
en: |
|
3 |
# my_label: "My label" |
lib/generators/redmine_plugin_gem/templates/gemspec.erb | ||
---|---|---|
1 |
# frozen_string_literal: true |
|
2 | ||
3 |
Gem::Specification.new do |spec| |
|
4 | ||
5 |
# Do not use constants or variables from the gem's own code in this block, as is normally |
|
6 |
# done with gems. (e.g. Foo::VERSION) |
|
7 |
# Specify the version of redmine or dependencies between plugins in the init.rb file. |
|
8 | ||
9 |
spec.name = "<%= plugin_name %>" |
|
10 |
spec.version = "0.0.1" |
|
11 |
spec.authors = ["johndoe"] |
|
12 |
spec.email = ["johndoe@example.org"] |
|
13 | ||
14 |
spec.summary = "<%= plugin_pretty_name %> plugin" |
|
15 |
spec.description = "This is a plugin for Redmine" |
|
16 |
spec.homepage = "https://example.org" |
|
17 |
spec.required_ruby_version = ">= 2.7.0" |
|
18 | ||
19 |
spec.metadata["author_url"] = spec.homepage |
|
20 |
spec.files = Dir["{app,lib,config,assets,db}/**/*", "init.rb", "Gemfile", "README.rdoc"] |
|
21 | ||
22 |
# DO NOT DELETE this attribute |
|
23 |
spec.metadata["redmine_plugin_id"] = "<%= plugin_name %>" |
|
24 |
end |
lib/generators/redmine_plugin_gem/templates/init.rb.erb | ||
---|---|---|
1 |
Redmine::Plugin.register :<%= plugin_name %> do |
|
2 |
# For gemmed plugins, the attributes of the plugin are described in the gemspec. |
|
3 |
# The correspondence between plugin attributes and gemspec is as follows |
|
4 | ||
5 |
# plugin name => gemspec summary |
|
6 |
# plugin author => gemspec authors |
|
7 |
# plugin description => gemspec description |
|
8 |
# plugin version => gemspec version |
|
9 |
# plugin url => gemspec homepage |
|
10 |
# plugin author_url => gemspec metadata['author_url'] |
|
11 | ||
12 |
# Other attributes should continue to be added to this block |
|
13 |
end |
lib/generators/redmine_plugin_gem/templates/routes.rb | ||
---|---|---|
1 |
# Plugin's routes |
|
2 |
# See: http://guides.rubyonrails.org/routing.html |
lib/generators/redmine_plugin_gem/templates/test_helper.rb.erb | ||
---|---|---|
1 |
# Load the Redmine helper |
|
2 |
require_relative '../../../test/test_helper' |