-
Notifications
You must be signed in to change notification settings - Fork 50
/
init.rb
103 lines (88 loc) · 3.06 KB
/
init.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require 'redmine'
Redmine::Plugin.register :redmine_tagging do
name 'Redmine Tagging Plugin'
author 'Restream'
description 'This plugin adds tagging features to Redmine.'
version '0.1.6'
settings default: {
dynamic_font_size: '1',
sidebar_tagcloud: '1',
wiki_pages_inline: '0',
issues_inline: '0'
},
partial: 'tagging/settings'
Redmine::WikiFormatting::Macros.register do
desc 'Wiki/Issues tagcloud'
macro :tagcloud do |obj, args|
args, options = extract_macro_options(args, :parent)
return if params[:controller] == 'mailer'
if obj
if obj.is_a? WikiContent
project = obj.page.wiki.project
else
project = obj.project
end
else
project = Project.visible.where(identifier: params[:project_id]).first
end
if project # this may be an attempt to render tag cloud when deleting wiki page
if [WikiContent, WikiContent::Version, NilClass].include?(obj.class)
render partial: 'tagging/tagcloud_search', project: project
elsif [Journal, Issue].include?(obj.class)
render partial: 'tagging/tagcloud', project: project
end
end
end
end
Redmine::WikiFormatting::Macros.register do
desc 'Wiki/Issues tag'
macro :tag do |obj, args|
if obj.is_a?(WikiContent) && Setting.plugin_redmine_tagging[:wiki_pages_inline] == '1'
inline = true
elsif obj.is_a?(Issue) && Setting.plugin_redmine_tagging[:issues_inline] == '1'
inline = true
else
inline = false
end
if inline
args, options = extract_macro_options(args, :parent)
tags = args.collect{|a| a.split(/[#"'\s,]+/)}.flatten.select{|tag| !tag.blank?}.collect{|tag| "##{tag}" }.uniq
tags.sort_by! { |t| t.downcase }
if obj.is_a? WikiContent
obj = obj.page
project = obj.wiki.project
else
project = obj.project
end
context = TaggingPlugin::ContextHelper.context_for(project)
tags_present = obj.tag_list_on(context).sort_by { |t| t.downcase }.join(',')
new_tags = tags.join(',')
if tags_present != new_tags
obj.tags_to_update = new_tags
obj.save
end
taglinks = tags.collect do |tag|
search_url = {
controller: 'search',
action: 'index',
id: project,
q: "\"#{tag}\""
}
search_url.merge!(obj.is_a?(WikiPage) ? { wiki_pages: true, issues: false } : { wiki_pages: false, issues: true })
link_to(tag, search_url)
end.join(' ')
raw("<div class='tags'>#{taglinks}</div>")
else
''
end
end
end
end
ActionDispatch::Callbacks.to_prepare do
require 'tagging_plugin/tagging_patches'
require 'tagging_plugin/api_template_handler_patch'
require 'redmine_tagging'
require File.expand_path('../app/helpers/tagging_helper', __FILE__)
ActionView::Base.send :include, TaggingHelper
end
require_dependency 'tagging_plugin/tagging_hooks'