Add issue macro with subject

This commit is contained in:
Alexander Meindl 2016-06-15 19:09:16 +02:00
parent 205588e182
commit 83801fe39c
8 changed files with 112 additions and 1 deletions

View File

@ -16,6 +16,7 @@ Changelog
- html validation error has been fixed
- remove garfield support (because there is no image source server available)
- slideshare wiki macro has been added
- issue wiki macro has been added
0.5.7
+++++

View File

@ -65,6 +65,7 @@ Features
* set info message above new ticket (e.g. for guidelines)
* Wiki date macros
* Wiki Gist marco
* Wiki issue macro
* Wiki members macro
* Wiki projects macro
* Wiki Slideshare marco

View File

@ -8,6 +8,7 @@ If a parameter is in brackets, this parameter is optional.
.. include:: macros/calendar.rst
.. include:: macros/date.rst
.. include:: macros/gist.rst
.. include:: macros/issue.rst
.. include:: macros/last_updated_by.rst
.. include:: macros/last_updated_at.rst
.. include:: macros/members.rst

38
docs/macros/issue.rst Normal file
View File

@ -0,0 +1,38 @@
User
----
Issue wiki macro for Redmine.
.. function:: {{id [, format=FORMAT])}}
Display link to issue with subject
:param int id: issue id of the issue
:param string format: custom format of link name. Possible values: full, text, short or link. If not specified 'link' is used as default.
Examples
++++++++
Link to issue with subject and id
.. code-block:: smarty
{{issue(1)}}
Link to issue with subject (without id)
.. code-block:: smarty
{{issue(1, format=short)}}
Link to issue with tracker, subject and id
.. code-block:: smarty
{{issue(1, format=full)}}
Display subject of issue
.. code-block:: smarty
{{issue(1, format=text)}}

View File

@ -27,6 +27,7 @@ if ActiveRecord::Base.connection.table_exists?(:settings)
require_dependency 'redmine_tweaks/wiki_macros/calendar'
require_dependency 'redmine_tweaks/wiki_macros/date'
require_dependency 'redmine_tweaks/wiki_macros/gist'
require_dependency 'redmine_tweaks/wiki_macros/issue_macro'
require_dependency 'redmine_tweaks/wiki_macros/last_updated_at'
require_dependency 'redmine_tweaks/wiki_macros/last_updated_by'
require_dependency 'redmine_tweaks/wiki_macros/member_macro'

View File

@ -0,0 +1,58 @@
# Redmine Tweaks plugin for Redmine
# Copyright (C) 2013-2016 AlphaNodes GmbH
# Issue wiki macros
module RedmineTweaks
module WikiMacros
Redmine::WikiFormatting::Macros.register do
desc <<-EOHELP
Create a link to issue with the subject of this issue.
Syntax:
{{issue(ID [, format=USER_FORMAT)}}
ID is issue id
USER_FORMATS
- text
- short
- link (default)
- full
Examples:
{{issue(1)}}
...Link to issue with subject and id
{{issue(1, format=short)}}
...Link to issue with subject (without id)
{{issue(1, format=text)}}
...Display subject name
{{issue(1, format=full)}}
...Link to issue with track, issue id and subject
EOHELP
macro :issue do |_obj, args|
args, options = extract_macro_options(args, :format)
raise 'The correct usage is {{issue(<issue_id>, format=FORMAT)}}' if args.empty?
issue_id = args[0]
issue = Issue.find_by_id(issue_id)
return 'N/A' if issue.nil? || !issue.visible?
text = case options[:format]
when 'full'
"#{issue.tracker.name} ##{issue.id} #{issue.subject}"
when 'text', 'short'
issue.subject
else
"#{issue.subject} ##{issue.id}"
end
if options[:format].blank? || options[:format] != 'text'
link_to(text, issue_url(issue, only_path: true),
class: issue.css_classes)
else
text
end
end
end
end
end

View File

@ -29,7 +29,7 @@ module RedmineTweaks
user = User.find_by_id(user_id)
user ||= User.find_by_login(user_id)
return '' if user.nil?
return 'N/A' if user.nil?
name = if options[:format].blank?
user.name

View File

@ -158,6 +158,17 @@ class WikiControllerTest < ActionController::TestCase
assert_select 'div.wiki span.current-date', Time.zone.today.cweek.to_s
end
def test_show_issue
@request.session[:user_id] = 1
@page.content.text = '{{issue(1, format=short)}}'
@page.content.save!
get :show, project_id: 1, id: @page_name
assert_response :success
assert_template 'show'
assert_select 'a[href=?]', '/issues/1',
text: 'Cannot print recipes'
end
def test_show_user_with_id
@request.session[:user_id] = 1
@page.content.text = '{{user(1)}}'