From 4fbac95ee1e8738f25ccb177623dd47356cd49fb Mon Sep 17 00:00:00 2001 From: Toru Takahashi Date: Sat, 23 Jun 2018 21:18:31 +0900 Subject: [PATCH] [phase-16]improve error message --- lib/glossary_macros.rb | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/glossary_macros.rb b/lib/glossary_macros.rb index 9d28753..b1a6f88 100644 --- a/lib/glossary_macros.rb +++ b/lib/glossary_macros.rb @@ -4,15 +4,33 @@ module GlossaryMacros 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) + begin + raise 'no parameters' if args.count.zero? + raise 'too many parameters' if args.count > 1 + term_id = args.first + term = GlossaryTerm.find(term_id) + link_to term.name, project_glossary_term_path(@project, term) + rescue => err_msg + raise <<-TEXT.html_safe +Parameter error: #{err_msg}
+Usage: {{termno(glossary_term_id)}} +TEXT + end 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) + begin + raise 'no parameters' if args.count.zero? + raise 'too many parameters' if args.count > 1 + term = GlossaryTerm.find_by!(name: args.first) + link_to term.name, project_glossary_term_path(@project, term) + rescue => err_msg + raise <<-TEXT.html_safe +Parameter error: #{err_msg}
+Usage: {{term(name)}} +TEXT + end end end