Project

General

Profile

Feature #29489 » 0001-adds-the-issue-macro-for-flexible-rendering-of-issue.patch

Jens Krämer, 2018-09-04 08:13

View differences:

lib/redmine/wiki_formatting/macros.rb
252 252
          raise "Attachment #{filename} not found"
253 253
        end
254 254
      end
255

  
256
      desc "Displays an issue link including additional information. Examples:\n\n" +
257
             "{{issue(123)}}                              -- Issue #123: Enhance macro capabilities\n" +
258
             "{{issue(123, project=true)}}                -- Andromeda - Issue #123: Enhance macro capabilities\n" +
259
             "{{issue(123, tracker=false)}}               -- #123: Enhance macro capabilities\n" +
260
             "{{issue(123, subject=false, project=true)}} -- Andromeda - Issue #123\n"
261
      macro :issue do |obj, args|
262
        args, options = extract_macro_options(args, :project, :subject, :tracker)
263
        id = args.first
264
        issue = Issue.visible.find_by(id: id)
265

  
266
        if issue
267
          # remove invalid options
268
          options.delete_if { |k,v| v != 'true' && v != 'false' }
269

  
270
          # turn string values into boolean
271
          options.each do |k, v|
272
            options[k] = v == 'true'
273
          end
274

  
275
          link_to_issue(issue, options)
276
        else
277
          # Fall back to regular issue link format to indicate, that there
278
          # should have been something.
279
          "##{id}"
280
        end
281
      end
255 282
    end
256 283
  end
257 284
end
test/unit/lib/redmine/wiki_formatting/macros_test.rb
406 406
    text = "*{{hello_world}}*"
407 407
    assert_match %r|\A<p><strong>Hello world!.*</strong></p>\z|, textilizable(text)
408 408
  end
409

  
410
  def test_issue_macro_should_not_render_link_if_not_visible
411
    assert_equal "<p>#123</p>", textilizable('{{issue(123)}}')
412
  end
413

  
414
  def test_issue_macro_should_render_link_to_issue
415
    issue = Issue.find 1
416
    assert_equal %{<p><a class="issue tracker-1 status-1 priority-4 priority-lowest" href="/issues/1">Bug #1</a>: #{issue.subject}</p>}, textilizable("{{issue(1)}}")
417
    assert_equal %{<p>eCookbook - <a class="issue tracker-1 status-1 priority-4 priority-lowest" href="/issues/1">Bug #1</a>: #{issue.subject}</p>}, textilizable("{{issue(1, project=true)}}")
418
  end
409 419
end
    (1-1/1)