From 32a3149ca9b0f3d55ff75b637a26b67161c51f35 Mon Sep 17 00:00:00 2001 From: Toru Takahashi Date: Sat, 23 Jun 2018 19:33:00 +0900 Subject: [PATCH] [phase-16]add term macro, and macro define moved from init.rb to new file --- init.rb | 20 +++----------------- lib/glossary_macros.rb | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 lib/glossary_macros.rb diff --git a/init.rb b/init.rb index f641b5a..485c737 100644 --- a/init.rb +++ b/init.rb @@ -1,6 +1,6 @@ -#Rails.configuration.to_prepare do -# Redmine::Activity.register :glossary_terms -#end +Rails.configuration.to_prepare do + require_dependency "glossary_macros" +end Redmine::Plugin.register :redmine_glossary do name 'Redmine Glossary plugin' @@ -33,17 +33,3 @@ end Redmine::Activity.register :glossary_terms - -Redmine::WikiFormatting::Macros.register do - desc "create macro which links to glossary term." - macro :termno do |obj, args| - puts "@@@@@@@@@@@@ Macros.register macro block: obj=#{obj.inspect} @@@@@@@@@@@@" - term_id = args.first - term = GlossaryTerm.find(term_id) - link_to term.name, project_glossary_term_path(@project, term) - end - macro :term do |obj, args| - term = GlossaryTerm.find_by(name: args.first) - link_to - end -end diff --git a/lib/glossary_macros.rb b/lib/glossary_macros.rb new file mode 100644 index 0000000..9d28753 --- /dev/null +++ b/lib/glossary_macros.rb @@ -0,0 +1,20 @@ +module GlossaryMacros + + Redmine::WikiFormatting::Macros.register do + + desc "create macro which links to glossary term by id." + macro :termno do |obj, args| + term_id = args.first + term = GlossaryTerm.find(term_id) + link_to term.name, project_glossary_term_path(@project, term) + end + + desc "create macro which links to glossary term by name." + macro :term do |obj, args| + term = GlossaryTerm.find_by(name: args.first) + link_to term.name, project_glossary_term_path(@project, term) + end + + end + +end