1
|
# Wiki Extensions plugin for Redmine
|
2
|
# Copyright (C) 2009 Haruyuki Iida
|
3
|
#
|
4
|
# This program is free software; you can redistribute it and/or
|
5
|
# modify it under the terms of the GNU General Public License
|
6
|
# as published by the Free Software Foundation; either version 2
|
7
|
# of the License, or (at your option) any later version.
|
8
|
#
|
9
|
# This program is distributed in the hope that it will be useful,
|
10
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
# GNU General Public License for more details.
|
13
|
#
|
14
|
# You should have received a copy of the GNU General Public License
|
15
|
# along with this program; if not, write to the Free Software
|
16
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
17
|
require 'redmine'
|
18
|
|
19
|
module WikiExtensionsWikiMacro
|
20
|
Redmine::WikiFormatting::Macros.register do
|
21
|
desc "Displays tags.\n\n"+
|
22
|
" @{{tags}}@\n"
|
23
|
macro :tags do |obj, args|
|
24
|
return nil unless WikiExtensionsUtil.is_enabled?(@project)
|
25
|
page = obj.page
|
26
|
return unless page
|
27
|
project = page.project
|
28
|
|
29
|
return '' if page.tags.empty?
|
30
|
|
31
|
o = '<ul class="tags">'
|
32
|
page.tags.each{|tag|
|
33
|
o << '<li>' + link_to("#{tag.name}", {:controller => 'wiki_extensions',
|
34
|
:action => 'tag', :id => project, :tag_id => tag.id}) + '</li>'
|
35
|
}
|
36
|
o << '</ul>'
|
37
|
return o
|
38
|
end
|
39
|
end
|
40
|
|
41
|
Redmine::WikiFormatting::Macros.register do
|
42
|
desc "Displays tagcloud.\n\n"+
|
43
|
" @{{tagcloud}}@\n"
|
44
|
macro :tagcloud do |obj, args|
|
45
|
return nil unless WikiExtensionsUtil.is_enabled?(@project)
|
46
|
classes = ['tag_level1', 'tag_level2', 'tag_level3', 'tag_level4', 'tag_level5']
|
47
|
page = obj.page
|
48
|
return unless page
|
49
|
project = page.project
|
50
|
o = '<h3>' + l(:label_wikiextensions_tags) + '</h3>'
|
51
|
tags = WikiExtensionsTag.find(:all, :conditions => ['project_id = ?', project.id])
|
52
|
return '' if tags.empty?
|
53
|
max_count = tags.sort{|a, b| a.page_count <=> b.page_count}.last.page_count.to_f
|
54
|
tags.sort.each{|tag|
|
55
|
index = ((tag.page_count / max_count) * (classes.size - 1)).round
|
56
|
o << link_to("#{tag.name}(#{tag.page_count})", {:controller => 'wiki_extensions',
|
57
|
:action => 'tag', :id => project, :tag_id => tag.id}, :class => classes[index])
|
58
|
o << ' '
|
59
|
}
|
60
|
return o
|
61
|
end
|
62
|
end
|
63
|
end
|