From 11561f2200f34133ee4cec232ea5548af62d13f5 Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Thu, 30 Aug 2018 12:13:16 +0800 Subject: [PATCH 1/4] adds the issue macro for flexible rendering of issue links --- lib/redmine/wiki_formatting/macros.rb | 27 ++++++++++++++++++++++ .../lib/redmine/wiki_formatting/macros_test.rb | 10 ++++++++ 2 files changed, 37 insertions(+) diff --git a/lib/redmine/wiki_formatting/macros.rb b/lib/redmine/wiki_formatting/macros.rb index 9ef4ffd06..f128f0c07 100644 --- a/lib/redmine/wiki_formatting/macros.rb +++ b/lib/redmine/wiki_formatting/macros.rb @@ -252,6 +252,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 7b0dfa6da..22de394ef 100644 --- a/test/unit/lib/redmine/wiki_formatting/macros_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/macros_test.rb @@ -406,4 +406,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 -- 2.11.0