Last active
May 11, 2016 06:42
-
-
Save daipresents/cd8c75cbe343487bfa7968ee231b6589 to your computer and use it in GitHub Desktop.
Redmineプラグインを作るなら読むべき本家チュートリアルの日本語訳
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ export RAILS_ENV="production" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ rake db:migrate_plugins | |
| (in /Users/daipresents/Development/redmine/redmine-1.1.3) | |
| Migrating engines... | |
| == CreateSawayakas: migrating ================================================ | |
| -- create_table(:sawayakas) | |
| -> 0.0530s | |
| == CreateSawayakas: migrated (0.0531s) ======================================= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ cd ${RAILS_ROOT} | |
| $ script/console | |
| >> Sawayaka.create(:question => "Are you OK?") | |
| => # | |
| >> Sawayaka.create(:question => "Are you Japanese?") | |
| => # | |
| >> exit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ vi vendor/plugins/redmine_sample/app/models/sawayaka.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Sawayaka < ActiveRecord::Base | |
| unloadable | |
| def vote(answer) | |
| increment(answer == 'yes' ? :yes : :no) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ruby script/generate redmine_plugin_controller <プラグイン名> <コントローラ名> [<アクション名>] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ cd ${RAILS_ROOT} | |
| $ ruby script/generate redmine_plugin_controller Sample cool index vote | |
| exists app/controllers/ | |
| exists app/helpers/ | |
| create app/views/cool | |
| create test/functional/ | |
| create app/controllers/cool_controller.rb | |
| create test/functional/cool_controller_test.rb | |
| create app/helpers/cool_helper.rb | |
| create app/views/cool/index.html.erb | |
| create app/views/cool/vote.html.erb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CoolController < ApplicationController unloadable def index @sawayakas = Sawayaka.find(:all) end def vote sawayaka = Sawayaka.find(params[:id]) sawayaka.vote(params[:answer]) if sawayaka.save flash[:notice] = 'Sawayaka saved.' redirect_to :action => 'index' | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| vi vendor/plugins/redmine_sample/app/views/cool/index.html.erb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <h2>Cool#index</h2> | |
| <% @sawayakas.each do |sawayaka| %> | |
| <%= sawayaka[:question] %>? | |
| <%= link_to 'Yes', {:action => 'vote', :id => poll[:id], :answer => 'yes'}, :method => :post %> (<%= poll[:yes] %>) / | |
| <%= link_to 'No', {:action => 'vote', :id => poll[:id], :answer => 'no'}, :method => :post %> (<%= poll[:no] %>) | |
| <% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| en: | |
| my_label: "My label" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ruby script/generate redmine_plugin <プラグイン名> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ja: | |
| my_label: "マイラベル" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| menu(menu_name, item_name, url, options={}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Redmine::Plugin.register :redmine_sample do | |
| [...] | |
| menu :top_menu, :sample, { :controller => 'cool', :action => 'index' }, :caption => 'SampleCap' | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Redmine::Plugin.register :redmine_sample do | |
| [...] | |
| menu :account_menu, :sample, { :controller => 'cool', :action => 'index' }, :caption => 'SampleCap' | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Redmine::Plugin.register :redmine_sample do | |
| name 'Redmine Sample plugin' | |
| [...] | |
| menu :application_menu, :sample, { :controller => 'cool', :action => 'index' }, :caption => 'Sample' | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Redmine::Plugin.register :redmine_sample do | |
| [...] | |
| permission :sample, {:cool => [:index, :vote]}, :public => true | |
| menu :project_menu, :sample, { :controller => 'cool', :action => 'index' }, :caption => 'SampleCap', :after => :activity, :param => :project_id | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def index | |
| @project = Project.find(params[:project_id]) | |
| @sawayaka = Sawayaka.find(:all) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| menu :project_menu, :sample, { :controller => 'cool', :action => 'index' }, :caption => 'SampleCap', :after => :activity, :param => :project_id | |
| permission :view_sample, :cool => :index | |
| permission :vote_sample, :cool => :vote |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CoolController < ApplicationController unloadable before_filter :find_project, :authorize, :only => :index | |
| def index | |
| @sawayakas = Sawayaka.find(:all) | |
| end | |
| def vote | |
| sawayaka = Sawayaka.find(params[:id]) | |
| sawayaka.vote(params[:answer]) | |
| if sawayaka.save | |
| flash[:notice] = 'Sawayaka saved.' | |
| redirect_to :action => 'index', :project_id => params[:project_id] | |
| end | |
| end | |
| private | |
| def find_project | |
| # @project variable must be set before calling the authorize filter | |
| @project = Project.find(params[:project_id]) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <% @sawayakas.each do |sawayaka| %> | |
| <%= sawayaka[:question] %>? | |
| <%= link_to 'Yes', {:action => 'vote', :id => sawayaka[:id], :answer => 'yes', :project_id => @project.id}, :method => :post %> (<%= sawayaka[:yes] %>) / | |
| <%= link_to 'No', {:action => 'vote', :id => sawayaka[:id], :answer => 'no', :project_id => @project.id}, :method => :post %> (<%= sawayaka[:no] %>) | |
| <% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ cd ${RAILS_ROOT} | |
| $ ruby script/generate redmine_plugin Sample | |
| create vendor/plugins/redmine_sample/app/controllers | |
| create vendor/plugins/redmine_sample/app/helpers | |
| create vendor/plugins/redmine_sample/app/models | |
| create vendor/plugins/redmine_sample/app/views | |
| create vendor/plugins/redmine_sample/db/migrate | |
| create vendor/plugins/redmine_sample/lib/tasks | |
| create vendor/plugins/redmine_sample/assets/images | |
| create vendor/plugins/redmine_sample/assets/javascripts | |
| create vendor/plugins/redmine_sample/assets/stylesheets | |
| create vendor/plugins/redmine_sample/lang | |
| create vendor/plugins/redmine_sample/config/locales | |
| create vendor/plugins/redmine_sample/test | |
| create vendor/plugins/redmine_sample/README.rdoc | |
| create vendor/plugins/redmine_sample/init.rb | |
| create vendor/plugins/redmine_sample/lang/en.yml | |
| create vendor/plugins/redmine_sample/config/locales/en.yml | |
| create vendor/plugins/redmine_sample/test/test_helper.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| permission_view_sample: View Sample | |
| permission_vote_sample: Vote Sample |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| permission :view_sample, :cool => :index | |
| permission :vote_sample, :cool => :vote |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| project_module :polls do | |
| permission :view_polls, :polls => :index | |
| permission :vote_polls, :polls => :vote | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a.vote { font-size: 120%; } | |
| a.vote.yes { color: green; } | |
| a.vote.no { color: red; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <% content_for :header_tags do %> | |
| <%= stylesheet_link_tag 'sample', :plugin => 'redmine_sample' %> | |
| <% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <% html_title "Sample Plugin!" -%> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ vi vendor/plugins/redmine_sample/init.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| vi vendor/plugins/redmine_sample/app/controllers/cool_controller.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'redmine' | |
| Redmine::Plugin.register :redmine_sample do | |
| name 'Redmine Sample plugin' | |
| author 'Dai Fujiahra' | |
| description 'This is a plugin for Redmine' | |
| version '0.0.1' | |
| url 'http://daipresents.com/' | |
| author_url 'http://daipresents.com' | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ruby script/generate redmine_plugin_model <プラグイン名> <モデル名> [<フィールド名>] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ cd ${RAILS_ROOT} | |
| $ ruby script/generate redmine_plugin_model Sample sawayaka question:string yes:integer no:integer | |
| exists app/models/ | |
| create test/unit/ | |
| create test/fixtures/ | |
| create app/models/sawayaka.rb | |
| create test/unit/sawayaka_test.rb | |
| create test/fixtures/sawayakas.yml | |
| exists db/migrate | |
| create db/migrate/20110508094844_create_sawayakas.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ cd ${RAILS_ROOT} | |
| $ cd vendor/plugins/redmine_sample/db/migrate | |
| $ mv 20110508094844_create_sawayakas.rb 001_create_sawayakas.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mysql> select * from schema_migrations where version like '%redmine_sample%'; | |
| Empty set (0.00 sec) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mysql> select * from schema_migrations where version like '%redmine_sample%'; | |
| +------------------+ | |
| | version | | |
| +------------------+ | |
| | 1-redmine_sample | | |
| +------------------+ | |
| 1 row in set (0.00 sec) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment