redmine-generators 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.md +112 -0
- data/Rakefile +38 -0
- data/lib/redmine-generators.rb +4 -0
- data/lib/redmine-generators/version.rb +3 -0
- data/lib/redmine/generators.rb +12 -0
- data/lib/redmine/generators/plugin_generator.rb +88 -0
- data/lib/redmine/generators/plugin_name_attribute.rb +42 -0
- data/lib/redmine/generators/plugin_support.rb +32 -0
- data/lib/redmine/generators/project_menu_generator.rb +21 -0
- data/lib/redmine/generators/project_module_generator.rb +25 -0
- data/lib/redmine/generators/remoteable_links.rb +18 -0
- data/lib/redmine/generators/resource_route_generator.rb +19 -0
- data/lib/redmine/generators/scaffold_controller_generator.rb +39 -0
- data/lib/redmine/generators/scaffold_generator.rb +51 -0
- data/lib/redmine/generators/sortable_headers.rb +18 -0
- data/lib/redmine/generators/templates/active_record/model/migration.rb +27 -0
- data/lib/redmine/generators/templates/active_record/model/model.rb +25 -0
- data/lib/redmine/generators/templates/erb/scaffold/_form.html.erb +13 -0
- data/lib/redmine/generators/templates/erb/scaffold/edit.html.erb +6 -0
- data/lib/redmine/generators/templates/erb/scaffold/index.html.erb +33 -0
- data/lib/redmine/generators/templates/erb/scaffold/new.html.erb +6 -0
- data/lib/redmine/generators/templates/erb/scaffold/show.html.erb +17 -0
- data/lib/redmine/generators/templates/rails/scaffold/_form.js.erb +14 -0
- data/lib/redmine/generators/templates/rails/scaffold/_model.html.erb +12 -0
- data/lib/redmine/generators/templates/rails/scaffold/create.js.erb +13 -0
- data/lib/redmine/generators/templates/rails/scaffold/destroy.js.erb +1 -0
- data/lib/redmine/generators/templates/rails/scaffold/edit.js.erb +7 -0
- data/lib/redmine/generators/templates/rails/scaffold/new.js.erb +7 -0
- data/lib/redmine/generators/templates/rails/scaffold/show.js.erb +19 -0
- data/lib/redmine/generators/templates/rails/scaffold/update.js.erb +12 -0
- data/lib/redmine/generators/templates/redmine/plugin/Gemfile +3 -0
- data/lib/redmine/generators/templates/redmine/plugin/en.yml +3 -0
- data/lib/redmine/generators/templates/redmine/plugin/init.rb +13 -0
- data/lib/redmine/generators/templates/redmine/plugin/plugin.rb +4 -0
- data/lib/redmine/generators/templates/redmine/plugin/routes.rb +5 -0
- data/lib/redmine/generators/templates/redmine/plugin/version.rb +3 -0
- data/lib/redmine/generators/templates/redmine/scaffold_controller/controller.rb +96 -0
- data/lib/redmine/generators/translation_generator.rb +41 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +4 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/redmine-generators_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- metadata +186 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 Greg Thornton
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
# Redmine Generators
|
2
|
+
|
3
|
+
[](https://travis-ci.org/xdissent/redmine-generators)
|
4
|
+
[](http://badge.fury.io/rb/redmine-generators)
|
5
|
+
|
6
|
+
Helpful generators for [Redmine](http://redmine.org) plugin authors.
|
7
|
+
|
8
|
+
## Crash Course
|
9
|
+
|
10
|
+
Recreate the [Redmine plugin tutorial](http://www.redmine.org/projects/redmine/wiki/Plugin_Tutorial)
|
11
|
+
using the `redmine:plugin` and `redmine:scaffold` generators:
|
12
|
+
|
13
|
+
```console
|
14
|
+
$ git clone https://github.com/redmine/redmine.git; cd redmine
|
15
|
+
$ echo "development:\n adapter: sqlite3\n database: db/dev.db" > config/database.yml
|
16
|
+
$ echo 'gem "redmine-generators", group: :development' >> Gemfile.local
|
17
|
+
$ bundle --without rmagick # Or whatever
|
18
|
+
$ rails g redmine:plugin polls
|
19
|
+
$ rails g redmine:scaffold polls poll question yes:integer no:integer
|
20
|
+
$ rake generate_secret_token db:migrate redmine:plugins:migrate
|
21
|
+
$ REDMINE_LANG=en rake redmine:load_default_data
|
22
|
+
```
|
23
|
+
|
24
|
+
Add a `vote` method to the `Poll` model in `plugins/redmine_polls/app/models/poll.rb`:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
def vote(answer)
|
28
|
+
increment(answer == "yes" ? :yes : :no)
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
Create a `vote` action for the `PollsController` in `plugins/redmine_polls/app/controllers/polls_controller.rb`:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
def vote
|
36
|
+
@poll.vote params[:answer]
|
37
|
+
flash[:notice] = "Voted #{params[:answer]}" if @poll.save && !request.xhr?
|
38
|
+
respond_with(@poll) do |format|
|
39
|
+
format.js { render action: :show }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
Create a member route in `plugins/redmine_polls/config/routes.rb` for the new
|
45
|
+
`vote` action:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
scope "/projects/:project_id" do
|
49
|
+
resources :polls do
|
50
|
+
post "vote", on: :member
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
Add the `vote` method to the `respond_to :js` and `before_filter :find_poll`
|
56
|
+
statements:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
respond_to :js, only: [:show, :new, :create, :edit, :update, :destroy, :vote]
|
60
|
+
# ...
|
61
|
+
before_filter :find_poll, only: [:show, :edit, :update, :destroy, :vote]
|
62
|
+
```
|
63
|
+
|
64
|
+
Add voting links to `plugins/redmine_polls/app/views/polls/show.html.erb`:
|
65
|
+
|
66
|
+
```erb
|
67
|
+
<p>
|
68
|
+
<b>Vote:</b>
|
69
|
+
<%= link_to "Yes", vote_poll_path(@poll, answer: "yes"), method: :post %> |
|
70
|
+
<%= link_to "No", vote_poll_path(@poll, answer: "no"), method: :post %>
|
71
|
+
</p>
|
72
|
+
```
|
73
|
+
|
74
|
+
And basically the same for `plugins/redmine_polls/app/views/polls/show.js.erb`
|
75
|
+
but using `remote: true` for AJAX links:
|
76
|
+
|
77
|
+
```erb
|
78
|
+
<p>
|
79
|
+
<b>Vote:</b>
|
80
|
+
<%= link_to "Yes", vote_poll_path(@poll, answer: "yes"), method: :post, remote: true %> |
|
81
|
+
<%= link_to "No", vote_poll_path(@poll, answer: "no"), method: :post, remote: true %>
|
82
|
+
</p>
|
83
|
+
```
|
84
|
+
|
85
|
+
Finally, add a `:vote_polls` Redmine permission to the `:polls` project module
|
86
|
+
in `plugins/redmine_polls/init.rb`:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
project_module :polls do
|
90
|
+
# ...
|
91
|
+
permission :vote_polls, polls: [:vote]
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
Start the rails server if you haven't already with `rails s`. Grant voting
|
96
|
+
access to whichever roles you'd like at
|
97
|
+
[http://localhost:3000/roles/permissions](http://localhost:3000/roles/permissions),
|
98
|
+
create a project with the `:polls` module enabled, and start polling!
|
99
|
+
|
100
|
+
|
101
|
+
## Available Generators
|
102
|
+
|
103
|
+
* `redmine:plugin`
|
104
|
+
* `redmine:project_menu`
|
105
|
+
* `redmine:project_module`
|
106
|
+
* `redmine:resource_route`
|
107
|
+
* `redmine:scaffold`
|
108
|
+
* `redmine:scaffold_controller`
|
109
|
+
* `redmine:translation`
|
110
|
+
|
111
|
+
|
112
|
+
This project rocks and uses MIT-LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'RedmineGenerators'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
|
30
|
+
Rake::TestTask.new(:test) do |t|
|
31
|
+
t.libs << 'lib'
|
32
|
+
t.libs << 'test'
|
33
|
+
t.pattern = 'test/**/*_test.rb'
|
34
|
+
t.verbose = false
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
task :default => :test
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require "redmine/generators/plugin_name_attribute"
|
2
|
+
require "rails/generators/named_base"
|
3
|
+
|
4
|
+
module Redmine
|
5
|
+
module Generators
|
6
|
+
class PluginGenerator < Rails::Generators::NamedBase
|
7
|
+
|
8
|
+
def create_root
|
9
|
+
empty_directory '.'
|
10
|
+
end
|
11
|
+
|
12
|
+
def init_rb
|
13
|
+
template "init.rb"
|
14
|
+
end
|
15
|
+
|
16
|
+
def config
|
17
|
+
empty_directory "config"
|
18
|
+
end
|
19
|
+
|
20
|
+
def routes
|
21
|
+
template "routes.rb", "config/routes.rb"
|
22
|
+
end
|
23
|
+
|
24
|
+
def locales
|
25
|
+
empty_directory "config/locales"
|
26
|
+
end
|
27
|
+
|
28
|
+
def translations
|
29
|
+
template "en.yml", "config/locales/en.yml"
|
30
|
+
end
|
31
|
+
|
32
|
+
def plugin_lib
|
33
|
+
empty_directory "lib"
|
34
|
+
empty_directory "lib/#{name}"
|
35
|
+
template "plugin.rb", "lib/#{name}.rb"
|
36
|
+
template "version.rb", "lib/#{name}/version.rb"
|
37
|
+
end
|
38
|
+
|
39
|
+
def app_folders
|
40
|
+
empty_directory "app"
|
41
|
+
empty_directory_with_gitkeep "app/models"
|
42
|
+
empty_directory_with_gitkeep "app/controllers"
|
43
|
+
empty_directory_with_gitkeep "app/helpers"
|
44
|
+
empty_directory_with_gitkeep "app/views"
|
45
|
+
end
|
46
|
+
|
47
|
+
def gemfile
|
48
|
+
template "Gemfile"
|
49
|
+
end
|
50
|
+
|
51
|
+
def initialize(args = [], options = {}, config = {})
|
52
|
+
args[0] = ideal_plugin_name(args[0]) if config[:behavior] == :invoke
|
53
|
+
super args, options, config
|
54
|
+
if ideal_plugin_path.exist? && behavior == :invoke
|
55
|
+
raise "Plugin #{name} already exists."
|
56
|
+
end
|
57
|
+
self.destination_root = ideal_plugin_path
|
58
|
+
end
|
59
|
+
|
60
|
+
protected
|
61
|
+
def ideal_plugin_name(pname = name)
|
62
|
+
"redmine_" + pname.gsub(/^(redmine|chiliproject)_/, "")
|
63
|
+
end
|
64
|
+
|
65
|
+
def ideal_plugin_path
|
66
|
+
Rails.root.join "plugins", ideal_plugin_name
|
67
|
+
end
|
68
|
+
|
69
|
+
def redmine_version
|
70
|
+
require "redmine/version"
|
71
|
+
"#{Redmine::VERSION::MAJOR}.#{Redmine::VERSION::MINOR}.#{Redmine::VERSION::TINY}"
|
72
|
+
end
|
73
|
+
|
74
|
+
def user_name
|
75
|
+
`git config --global --get user.name`.strip
|
76
|
+
end
|
77
|
+
|
78
|
+
def empty_directory_with_gitkeep(destination, config = {})
|
79
|
+
empty_directory(destination, config)
|
80
|
+
git_keep(destination)
|
81
|
+
end
|
82
|
+
|
83
|
+
def git_keep(destination)
|
84
|
+
create_file("#{destination}/.gitkeep")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "active_support/concern"
|
2
|
+
|
3
|
+
module Redmine
|
4
|
+
module Generators
|
5
|
+
module PluginNameAttribute
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
def initialize(args = [], options = {}, config = {})
|
9
|
+
self.plugin_name = args.shift unless plugin_name
|
10
|
+
plugin_destination = plugin_destination_root
|
11
|
+
raise "Invalid plugin name #{plugin_name}" if bail_on_missing? && !plugin_destination
|
12
|
+
super
|
13
|
+
self.destination_root = plugin_destination
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
def bail_on_missing?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def plugin_name=(name)
|
22
|
+
Redmine::Generators.plugin = name
|
23
|
+
end
|
24
|
+
|
25
|
+
def plugin_name
|
26
|
+
Redmine::Generators.plugin
|
27
|
+
end
|
28
|
+
|
29
|
+
def possible_plugin_names
|
30
|
+
%W(#{plugin_name} redmine_#{plugin_name} chiliproject_#{plugin_name})
|
31
|
+
end
|
32
|
+
|
33
|
+
def plugin_destination_root
|
34
|
+
possible_plugin_paths.find { |p| p.exist? }
|
35
|
+
end
|
36
|
+
|
37
|
+
def possible_plugin_paths
|
38
|
+
possible_plugin_names.map { |p| Rails.root.join "plugins", p }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "active_support/concern"
|
2
|
+
|
3
|
+
module Redmine
|
4
|
+
module Generators
|
5
|
+
module PluginSupport
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
templates_path << File.expand_path("../templates", __FILE__)
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def lookup_with_redmine(namespaces)
|
13
|
+
redmine_names = namespaces.select { |ns| ns.start_with? "redmine:" }
|
14
|
+
redmine_names.each do |ns|
|
15
|
+
require "redmine/generators/#{ns.split(":").last}_generator"
|
16
|
+
end
|
17
|
+
lookup_without_redmine (namespaces - redmine_names)
|
18
|
+
end
|
19
|
+
alias_method_chain :lookup, :redmine
|
20
|
+
|
21
|
+
def lookup_with_redmine!
|
22
|
+
Dir[File.expand_path("../*_generator.rb", __FILE__)].each do |path|
|
23
|
+
require File.join("redmine/generators", File.basename(path, ".rb"))
|
24
|
+
end
|
25
|
+
lookup_without_redmine!
|
26
|
+
end
|
27
|
+
alias_method_chain :lookup!, :redmine
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "redmine/generators/plugin_name_attribute"
|
2
|
+
Rails::Generators.lookup %w(rails:model)
|
3
|
+
|
4
|
+
module Redmine
|
5
|
+
module Generators
|
6
|
+
class ProjectMenuGenerator < Rails::Generators::ModelGenerator
|
7
|
+
include PluginNameAttribute
|
8
|
+
|
9
|
+
remove_hook_for :orm
|
10
|
+
|
11
|
+
def add_project_menu
|
12
|
+
menu = %( menu :project_menu, :#{plural_table_name}, {controller: "#{plural_table_name}", action: "index" }, caption: :label_#{singular_table_name}_plural, param: :project_id\n)
|
13
|
+
sentinel = /Redmine::Plugin\.register\s+:\w+\s+do\s?\n/
|
14
|
+
|
15
|
+
in_root do
|
16
|
+
inject_into_file "init.rb", menu, after: sentinel
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "redmine/generators/plugin_name_attribute"
|
2
|
+
Rails::Generators.lookup %w(rails:model)
|
3
|
+
|
4
|
+
module Redmine
|
5
|
+
module Generators
|
6
|
+
class ProjectModuleGenerator < Rails::Generators::ModelGenerator
|
7
|
+
include PluginNameAttribute
|
8
|
+
|
9
|
+
remove_hook_for :orm
|
10
|
+
|
11
|
+
def add_project_module
|
12
|
+
pm = " project_module :#{plural_table_name} do\n"
|
13
|
+
pm << " permission :view_#{plural_table_name}, #{plural_table_name}: [:index, :show]\n"
|
14
|
+
pm << " permission :manage_#{plural_table_name}, #{plural_table_name}: [:new, :create, :edit, :update, :destroy]\n"
|
15
|
+
pm << " end\n"
|
16
|
+
|
17
|
+
sentinel = /Redmine::Plugin\.register\s+:\w+\s+do\s?\n/
|
18
|
+
|
19
|
+
in_root do
|
20
|
+
inject_into_file "init.rb", pm, after: sentinel
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "active_support/concern"
|
2
|
+
|
3
|
+
module Redmine
|
4
|
+
module Generators
|
5
|
+
module RemoteableLinks
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
protected
|
9
|
+
def maybe_remote
|
10
|
+
", " + key_value(:remote, "true") if remote_option
|
11
|
+
end
|
12
|
+
|
13
|
+
def remote_option
|
14
|
+
parent_options[:remote]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "redmine/generators/plugin_name_attribute"
|
2
|
+
Rails::Generators.lookup %w(rails:resource_route)
|
3
|
+
|
4
|
+
module Redmine
|
5
|
+
module Generators
|
6
|
+
class ResourceRouteGenerator < Rails::Generators::ResourceRouteGenerator
|
7
|
+
include PluginNameAttribute
|
8
|
+
|
9
|
+
class_option :project, type: :boolean, default: true, desc: "Add project model relation"
|
10
|
+
|
11
|
+
private
|
12
|
+
def route(*args)
|
13
|
+
return super unless options[:project]
|
14
|
+
indented = route_string.split("\n").map { |l| " #{l}" }.compact.join "\n"
|
15
|
+
super %(scope "/projects/:project_id" do\n#{indented}\n end)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|