From: Jean-Philippe Lang Date: Thu, 20 Jun 2019 14:01:50 +0000 (+0000) Subject: Issue macro for flexible linking to issues (#29489). X-Git-Tag: 4.1.0~771 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c4a9d4cd4df130fa84e5c1948fc93d1f2b0bba5a;p=redmine.git Issue macro for flexible linking to issues (#29489). Patch by Jens Krämer. git-svn-id: http://svn.redmine.org/redmine/trunk@18297 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/lib/redmine/wiki_formatting/macros.rb b/lib/redmine/wiki_formatting/macros.rb index 8afa0f8e7..bf12cb1b0 100644 --- a/lib/redmine/wiki_formatting/macros.rb +++ b/lib/redmine/wiki_formatting/macros.rb @@ -254,6 +254,33 @@ module Redmine raise "Attachment #{filename} not found" end end + + desc "Displays an issue link including additional information. Examples:\n\n" + + "{{issue(123)}} -- Issue #123: Enhance macro capabilities\n" + + "{{issue(123, project=true)}} -- Andromeda - Issue #123: Enhance macro capabilities\n" + + "{{issue(123, tracker=false)}} -- #123: Enhance macro capabilities\n" + + "{{issue(123, subject=false, project=true)}} -- Andromeda - Issue #123\n" + macro :issue do |obj, args| + args, options = extract_macro_options(args, :project, :subject, :tracker) + id = args.first + issue = Issue.visible.find_by(id: id) + + if issue + # remove invalid options + options.delete_if { |k,v| v != 'true' && v != 'false' } + + # turn string values into boolean + options.each do |k, v| + options[k] = v == 'true' + end + + link_to_issue(issue, options) + else + # Fall back to regular issue link format to indicate, that there + # should have been something. + "##{id}" + end + end end end end diff --git a/test/unit/lib/redmine/wiki_formatting/macros_test.rb b/test/unit/lib/redmine/wiki_formatting/macros_test.rb index b91638274..95b886e85 100644 --- a/test/unit/lib/redmine/wiki_formatting/macros_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/macros_test.rb @@ -408,4 +408,14 @@ EXPECTED text = "*{{hello_world}}*" assert_match %r|\A

Hello world!.*

\z|, textilizable(text) end + + def test_issue_macro_should_not_render_link_if_not_visible + assert_equal "

#123

", textilizable('{{issue(123)}}') + end + + def test_issue_macro_should_render_link_to_issue + issue = Issue.find 1 + assert_equal %{

Bug #1: #{issue.subject}

}, textilizable("{{issue(1)}}") + assert_equal %{

eCookbook - Bug #1: #{issue.subject}

}, textilizable("{{issue(1, project=true)}}") + end end