torutk.hatenablog.jp
ã§ãRedmineã®Wikiãã¼ã¸ã«ã«ã¹ã¿ã ã¯ã¨ãªã¸ã®ãªã³ã¯ãè¨ãã¦ãã¯ãªãã¯ããã¨æå®ã®ã«ã¹ã¿ã ã¯ã¨ãªã®çµæã®ãã±ããä¸è¦§ãã¼ã¸ã«é£ã¶ããã«ããæ¹æ³ã模索ããWikiãã¯ããä½æãããã¨ã§è§£æ±ºã®ç®éãç«ã¦ã¾ããã
ãã®Wikiãã¯ããããã©ã°ã¤ã³ã¨ãã¦å±éã§ããããã«ãã¾ãä»å¾ãããããªãã¯ãã追å ãã¦ãããããã«æ§æãè¦ç´ãã¦ãGithubã«ãªãã¸ããªãã¤ããã¾ããã
https://github.com/torutk/redmine_cozy_wiki_macros
ä»æ¥ã®æ¥è¨ã¯ãæ§æã®è¦ç´ãã¨Githubã¸ä¸ããä½æ¥ã®ã¡ã¢ã§ãã
ãã©ã°ã¤ã³å
Redmineã®ãã©ã°ã¤ã³åã¯å¤§åããredmine_xxx ã®ããã«redmine_ãä»ãã¦ãã¾ããæåãããããredmine_ãä»ããã®ã¯ãã©ã°ã¤ã³åãé·ããªãããredmineãã£ã¬ã¯ããªä¸ã®pluginsä¸ã«ã¯ã©ããRedmineã®ãã©ã°ã¤ã³ããç½®ããªãã®ã§ãredmine_ãä»ããã«cozy_wiki_macrosã¨ãã¾ããã
次ã«ãGithubã«ãªãã¸ããªãä½æãã段ã«ãªã£ãéãGithubã¯ã¦ã¼ã¶ã¼åã®ä¸ã«ãã©ããã«ãªãã¸ããªã並ã¶ã®ã§ãcozy_wiki_macrosã§ã¯ä½ã®ãªãã¸ããªãä¸è¦åãããªãã§ããGithubä¸ã§åãããããããã«ã¯redmineãä»ããããªããredmine_cozy_wiki_macrosã¨ãã¾ããã
ãã©ã°ã¤ã³ãå ¥ããéã«ããã©ã°ã¤ã³åã¨Githubã®ãªãã¸ããªåã¯å¥ã«ãã¦ããã¦ãgit cloneãããã¨ãã£ã¬ã¯ããªåãå¤æ´ãã¦ãããæ¹æ³ãããã¾ããããããããã¯ã¤ã³ã¹ãã¼ã«ãã人ã¸ã®ä¸è¦ãªæéã¨ãªããååãå¤æ´ãå¿ãã¤ã³ã¹ãã¼ã«å¤±æã®è¦å ã«ããªãã®ã§ãgitãªãã¸ããªããã®ã¾ã¾cloneãã¦çæããããã£ã¬ã¯ããªããã©ã°ã¤ã³åã«ãã¾ããã
æè¿ã®ãã©ã°ã¤ã³ã¯ããªãã¸ããªããpluginsãã£ã¬ã¯ããªã¸cloneãã¦ãã®ã¾ã¾ä½¿ããã®ãå¤ããªã£ã¦ãã¾ãã以åã¯ãããã©ã°ã¤ã³ã®é å¸ç¨zipãã¡ã¤ã«ãå±éãããã®ã¾ã¾ã®ãã£ã¬ã¯ããªåã§ã¯ã¨ã©ã¼ã«ãªãã®ã§init.rbã®ä¸ã§regsiterã§å¼ã°ããååã調ã¹ããã®ååã«ãªãã¼ã ããã¨ãããã¨ãããã¾ããããæè¿ã¯githubãbitbucketããcloneããã ãã§ååãä¸è´ããããã«ãªã£ã¦ãã¾ãã
ãã¯ããå®ç¾©ãããã¡ã¤ã«ãinit.rbããå¼ã¶
æåã¯init.rbã«Wikiãã¯ãå®ç¾©ãã¹ãæ¸ããã¦ãã¾ããããè¤æ°ã®ãã¯ãå®ç¾©ãå容ãããã©ã°ã¤ã³ã¨ãã¦ã¯1ãã¯ã1ãã¡ã¤ã«ã§æ§æããããªãã¾ãã
å¥ãªãã¡ã¤ã«ãèªã¿è¾¼ãéã«ãRuby on Railsã§ç¨æããã¦ããrequire_dependency ã使ãã¨ãdevelopmentã¢ã¼ãã§å®è¡ãã¦ããã¨ãã¯æå®ãã¡ã¤ã«ãå¤æ´ããã¨åãã¼ããèµ°ãã®ã§ããã¯ãå®ç¾©rubyã½ã¼ã¹ãã¡ã¤ã«ãä¿®æ£ãããã¨Railsãµã¼ãã¼ï¼WEBrickï¼ãèµ·åãç´ããã¨ãä¸è¦ã«ãªã£ã¦ä¾¿å©ã§ãã
plugin_name = :redmine_cozy_wiki_macros Rails.configuration.to_prepare do %w{query_link}.each do |file_name| require_dependency "#{plugin_name}/#{file_name}" end end
ãã®ããã«è¨è¿°ããã¨
redmine-3.3.1 +-- plugins +-- redmine_cozy_wiki_macros +-- lib +-- redmine_cozy_wiki_macros +-- query_link.rb
ã®ããã«ããã©ã°ã¤ã³ã®libãã£ã¬ã¯ããªä¸ãåºç¹ã«ã#{plugin_name} ãredmine_cozy_wiki_macrosã«å±éããããã®ãã£ã¬ã¯ããªä¸ã«ãããã¯ãåã«å¯¾å¿ããã½ã¼ã¹ãã¡ã¤ã«ããã¼ããã¾ãã
%w{query_link} ã®ãã¯ãåã¯ãè¤æ°è¨è¿°ããå ´åã¯ç©ºç½ã§åºåã£ã¦è¨è¿°ãã¾ãã
ä¾ï¼%w{query_link query_list}.each do |file_name|
ãã®è¾ºã®ãã¯ããè¤æ°å®ç¾©ãããã©ã°ã¤ã³ã®ä½ãæ¹ã¯ãã»ã¼Wiki Listsãã©ã°ã¤ã³ãçä¼¼ã¦ãã¾ããï¼æè¬
http://www.redmine.org/plugins/redmine_wiki_lists
ãã¼ã«ã«ã§ä½ã£ããã£ã¬ã¯ããªãGithubã«ä¸ãã
æåã¯Redmineéçºç°å¢ä¸ã§pluginãã£ã¬ã¯ããªä¸ã«ãã®ãã¯ãç¨ã®ãã©ã°ã¤ã³ãã£ã¬ã¯ããªãä½æãããã¡ã¤ã«ã2ã¤ï¼init.rbã¨query_link.rbï¼ä½ã軽ãåä½ç¢ºèªãè¡ãã¾ããããã®æ®µéã§ãã¼ã«ã«ã®gitãªãã¸ããªãä½ãã¾ãã
ã¾ãããã£ã¬ã¯ããªã¨ãã¡ã¤ã«ãä½æãã¾ãããã£ã¬ã¯ããªåã¯æ£å¼åã®æã®ååï¼å é ã«redmine_ããªãï¼ã§ãã
~$ cd work/redmine-3.3.1/plugins plugins$ mkdir cozy_wiki_macros plugins$ cd cozy_wiki_macros cozy_wiki_macros$ vi init.rb : cozy_wiki_macros$ mkdir lib/cozy_wiki_macros cozy_wiki_macros$ vi lib/cozy_wiki_macros/query_link.rb :
ãã¼ã«ã«ã§gitãªãã¸ããªä½æ
cozy_wiki_macros$ git init . cozy_wiki_macros$ git add init.rb lib/cozy_wiki_macros/query_link.rb cozy_wiki_macros$ git commit
Githubã«ãªãã¸ã㪠redmine_cozy_wiki_macros ãä½æ
ãã¼ã«ã«ã®gitãªãã¸ããªã¨Githubã®ãªãã¸ããªãç´ã¥ã
cozy_wiki_macros$ git remote add origin https://github.com/torutk/redmine_cozy_wiki_macros.git
Githubã«ã³ãããå 容ãpush
cozy_wiki_macros$ git push
ãã©ã°ã¤ã³åãredmine_cozy_wiki_macrosã«å¤æ´ããéããã£ã¬ã¯ããªåãå¤ãã
cozy_wiki_macros$ cd lib lib$ git mv cozy_wiki_macros redmine_cozy_wiki_macros
ä»ã®ä¿®æ£ãå ããå¾ã«ãgit commit ã㦠pushãã¾ãã
moduleå®ç¾©
query_link.rbã®å é è¡
module RedmineCozyWikiMacros::QueryLink
ã¯ãRedmineã®ãã©ã°ã¤ã³åï¼redmine_cozy_wiki_macrosï¼ããã£ã¡ã«ã±ã¼ã¹åãããã®ã«ä¸è´ãã¦ããªãã¨ã¨ã©ã¼ã¨ãªãã¾ããã
ãã¯ãã®å¼æ°ãã§ãã¯
ãã©ã°ã¤ã³åããã®ã§ããã¯ãã®å¼æ°ãã§ãã¯ã¨ã¨ã©ã¼è¡¨ç¤ºããããªãã«è¨è¿°ãã¾ããã
macro :query_link do |obj, args| begin raise 'no parameters' if args.count.zero? raise 'too few parameters' if args.count < 2 raise 'too many parameters' if args.count > 2 :ï¼ä¸ç¥ï¼ rescue => err_msg raise <<-TEXT.html_safe Parameter error: #{err_msg}<br> Usage: {{query_link(text, query_id)}} TEXT end
begin ã rescue ã end ãrubyã®ã¨ã©ã¼å¦çï¼ä¾å¤å¦çï¼æ§æãªããã§ãã
ãã¯ãã®å¼æ°ããã§ãã¯ããæå®ã®2å以å¤ã§ããã°ä¾å¤ãçºçããã¾ãï¼raiseï¼ã
ä¾å¤ã¯rescueã§æ¾ãã¾ããraiseæã®ã¨ã©ã¼ã¡ãã»ã¼ã¸æååã¯rescueã®err_msgã«å
¥ãã¾ããããããã¨ã«ãã¨ã©ã¼å
容ã説æããæååãä½ããããã«raiseãã¾ãã
ããããã¨ã誤ã£ãæå®ãããã次ã®ããã«èª¬æã表示ããã¾ãã