forked from apache/accumulo-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
links.rb
executable file
·260 lines (231 loc) · 6.08 KB
/
links.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
def convert_package(package)
retval = ''
vals = package.split('.')
vals.each_with_index do |value, index|
retval << value
if index != vals.size - 1
if value =~ /^[a-z]/
retval << '/'
else
retval << '.'
end
end
end
return retval
end
def render_javadoc(context, text, url_only)
clz = text.strip
short = true
if not url_only
args = text.strip.split(' ', 2)
if args[0] == '-f'
short = false
clz = args[1]
elsif args[0] == '-c'
clz = args[1]
end
end
base = context.registers[:site].config['javadoc_base']
v = context.environments.first["page"]["javadoc_version"]
if v.nil?
v = context.registers[:site].config['javadoc_version']
end
clz_slash = convert_package(clz)
clz_name = clz.split('.').last
if not clz.start_with?('org.apache.accumulo.')
raise "Unknown package prefix for #{clz}"
end
# Default is accumulo-<module> but handle corner cases below
jmodule = 'accumulo-' + clz.split('.')[3]
if clz.start_with?('org.apache.accumulo.server')
jmodule = 'accumulo-server-base'
elsif clz.start_with?('org.apache.accumulo.hadoop.mapred')
jmodule = 'accumulo-hadoop-mapreduce'
elsif clz == 'org.apache.accumulo.hadoop'
jmodule = 'accumulo-hadoop-mapreduce'
elsif clz.start_with?('org.apache.accumulo.iteratortest')
jmodule = 'accumulo-iterator-test-harness'
end
if clz_slash.include? "#"
clz_only = convert_package(clz.split('#').first)
method = clz.split('#').last
url = "#{base}/#{jmodule}/#{v}/#{clz_only}.html##{method}"
elsif clz_name =~ /^[a-z]/
url = "#{base}/#{jmodule}/#{v}/#{clz_slash}/package-summary.html"
else
url = "#{base}/#{jmodule}/#{v}/#{clz_slash}.html"
end
if url_only
return url
end
if short
link_text = clz.split('.').last
else
link_text = clz
end
r = "[#{link_text}](#{url})"
return r
end
class JavadocLinkTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text
end
def render(context)
return render_javadoc(context, @text, false)
end
end
class JavadocUrlTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text
end
def render(context)
return render_javadoc(context, @text, true)
end
end
def render_prop(context, text, link)
args = text.split(' ')
type = 'server'
prop = args[0]
if args[0] == '-c'
type = 'client'
prop = args[1]
elsif args[0] == '-s'
type = 'server'
prop = args[1]
end
base = context.environments.first["page"]["docs_baseurl"]
if base.nil?
base = context.registers[:site].config['docs_baseurl']
end
prop_enc = prop.gsub('.\\*', '.*').gsub('.', '_').gsub('_*', '_prefix')
url = "#{base}/configuration/server-properties##{prop_enc}"
if type == 'client'
url = "#{base}/configuration/client-properties##{prop_enc}"
end
if link
return "[#{prop}](#{url})"
end
return url
end
def render_prop_onex(context, text, version)
args = text.split(' ')
prop = args[0]
base = context.registers[:site].config['baseurl']
prop_enc = prop.gsub('.\\*', '.*').gsub('.', '_').gsub('_*', '_prefix')
url = "#{base}/1.#{version}/accumulo_user_manual#_#{prop_enc}"
return "[#{prop}](#{url})"
end
class PropertyUrlTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text
end
def render(context)
return render_prop(context, @text, false)
end
end
class PropertyLinkTag1x < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text
end
def render(context)
return render_prop_onex(context, @text, '10')
end
end
class PropertyLinkTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text
end
def render(context)
return render_prop(context, @text, true)
end
end
def render_doc(context, text, link)
base = context.environments.first["page"]["docs_baseurl"]
if base.nil?
base = context.registers[:site].config['docs_baseurl']
end
url = "#{base}/#{@text}"
if not link
return url
end
page = @text.split('/').last
return "[#{page}](#{url})"
end
class DocLinkTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text
end
def render(context)
return render_doc(context, @text, true)
end
end
class DocUrlTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text
end
def render(context)
return render_doc(context, @text, false)
end
end
class GitHubIssueTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text
end
def render(context)
# TODO sanity check text
# TODO support optional pound char like #123
url = "https://github.com/apache/accumulo/issues/#{@text}"
return "[##{@text.strip}](#{url})"
end
end
class JiraTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text
end
def render(context)
# TODO sanity check text
# TODO accept number without ACCUMULO- prefix
url = "https://issues.apache.org/jira/browse/#{@text}"
return "[#{@text.strip}](#{url})"
end
end
class GitHubCodeTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text
end
def render(context)
args = @text.split(' ')
path = args[0]
branch = context.environments.first["page"]["gh_branch"]
if branch.nil?
branch = context.registers[:site].config["gh_branch"]
end
if args[0] == '-b'
branch = args[1]
path = args[2]
end
file_name = path.split('/').last
url = "https://github.com/apache/accumulo/blob/#{branch}/#{path}"
return "[#{file_name}](#{url})"
end
end
Liquid::Template.register_tag('plink1x', PropertyLinkTag1x)
Liquid::Template.register_tag('jlink', JavadocLinkTag)
Liquid::Template.register_tag('jurl', JavadocUrlTag)
Liquid::Template.register_tag('plink', PropertyLinkTag)
Liquid::Template.register_tag('purl', PropertyUrlTag)
Liquid::Template.register_tag('dlink', DocLinkTag)
Liquid::Template.register_tag('durl', DocUrlTag)
Liquid::Template.register_tag('ghi', GitHubIssueTag)
Liquid::Template.register_tag('ghc', GitHubCodeTag)
Liquid::Template.register_tag('jira', JiraTag)