-
Notifications
You must be signed in to change notification settings - Fork 10
/
init.rb
61 lines (49 loc) · 1.3 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
require 'redmine'
require_dependency 'redmine_wiki_unc_hooks'
class UncHelper
def initialize
@head = /^\\\\/
end
def is_unc?(str)
(str =~ @head) != nil
end
def unc_to_file_proto(str)
Rails.logger.info "str == #{str}, is_unc? == #{is_unc?(str)}, head=#{@head.to_s}"
return "" if !is_unc?(str)
str.gsub(@head, "file://///").gsub(/\\/, "/")
end
def trim(str)
return str.strip unless str == nil
return nil
end
def parse_args(args)
unc = trim(args[0])
label = trim(args[1]) || unc
return unc, label
end
def get_tag(args)
return "(No parameters are specified. A UNC path is needed at least.)" if args.empty?
unc, label = parse_args(args)
return <<TEMPLATE
<a href=\"#{unc_to_file_proto(unc)}\">#{label}</a>
TEMPLATE
end
end
Redmine::Plugin.register :redmine_wiki_unc do
name 'Redmine Wiki Unc plugin'
author 'Takashi Oguma'
description 'This is a plugin for macro of Redmine Wiki'
version '0.0.4'
Redmine::WikiFormatting::Macros.register do
desc <<DESC
Makes a link to UNC path.
How to use:
1) without a label: {{unc(\\\\server\\path\\to\\file)}}
2) with a label: {{unc(\\\\server\\path\\to\\file, My Secret Document)}}
DESC
macro :unc do |obj, args|
h = UncHelper.new
h.get_tag(args).html_safe
end
end
end