asciidoctor-plantuml 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/asciidoctor-plantuml/plantuml.rb +183 -178
- data/lib/asciidoctor-plantuml/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7718a31ed4888ccbacef471e5e5fda271b371336
|
4
|
+
data.tar.gz: 7cf588d1ff45b671122be55961f007dcce2fdbb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc542c286ccb6e1a9379560d3e3caa6dee8087de7f4f3d14cd0d43f27cef34df5e75a1051c9185f4376b9ba82b23f1a24656456ee90682024c81c322976f2f4a
|
7
|
+
data.tar.gz: 8fce5b5f981e13e0fd4dcad119b73a6685e64a58ad2ec2678e849bb2b58776cc98ea8288c8670346ea5c96dc0086b1ff23b8ca565f5a09128b290675efdf716b
|
@@ -32,226 +32,223 @@ module Asciidoctor
|
|
32
32
|
yield(configuration)
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
class Processor
|
36
36
|
|
37
37
|
FORMATS = ["png", "svg", "txt"]
|
38
38
|
DEFAULT_FORMAT = FORMATS[0]
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
class << self
|
41
|
+
def valid_format?(format)
|
42
|
+
FORMATS.include?(format)
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
def server_url
|
46
|
+
PlantUml::configuration.url
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
def txt_enabled?
|
50
|
+
PlantUml::configuration.txt_enable
|
51
|
+
end
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
def png_enabled?
|
54
|
+
PlantUml::configuration.png_enable
|
55
|
+
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
57
|
+
def svg_enabled?
|
58
|
+
PlantUml::configuration.svg_enable
|
59
|
+
end
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
61
|
+
def enabled?
|
62
|
+
txt_enabled? || png_enabled? || svg_enabled?
|
63
|
+
end
|
63
64
|
|
64
|
-
|
65
|
+
def plantuml_content(code, attrs = {})
|
65
66
|
|
66
|
-
|
67
|
+
format = attrs["format"] || DEFAULT_FORMAT
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
69
|
+
if !enabled?
|
70
|
+
return plantuml_disabled_content(code, attrs)
|
71
|
+
end
|
71
72
|
|
72
|
-
|
73
|
-
|
74
|
-
|
73
|
+
if !valid_uri?(server_url)
|
74
|
+
return plantuml_server_unavailable_content(server_url, attrs)
|
75
|
+
end
|
75
76
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
77
|
+
case format
|
78
|
+
when "png"
|
79
|
+
plantuml_img_content(code, format, attrs)
|
80
|
+
when "txt"
|
81
|
+
if txt_enabled?
|
82
|
+
plantuml_txt_content(code, format, attrs)
|
83
|
+
else
|
84
|
+
plantuml_invalid_content(format, attrs)
|
85
|
+
end
|
86
|
+
when "svg"
|
87
|
+
plantuml_img_content(code, format, attrs)
|
82
88
|
else
|
83
89
|
plantuml_invalid_content(format, attrs)
|
84
90
|
end
|
85
|
-
when "svg"
|
86
|
-
plantuml_img_content(code, format, attrs)
|
87
|
-
else
|
88
|
-
plantuml_invalid_content(format, attrs)
|
89
91
|
end
|
90
|
-
end
|
91
92
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
93
|
+
# Compression code used to generate PlantUML URLs. Taken directly from the
|
94
|
+
# Transcoder class in the PlantUML java code.
|
95
|
+
def gen_url(text, format)
|
96
|
+
result = ""
|
97
|
+
compressedData = Zlib::Deflate.deflate(text)
|
98
|
+
compressedData.chars.each_slice(3) do |bytes|
|
99
|
+
#print bytes[0], ' ' , bytes[1] , ' ' , bytes[2]
|
100
|
+
b1 = bytes[0].nil? ? 0 : (bytes[0].ord & 0xFF)
|
101
|
+
b2 = bytes[1].nil? ? 0 : (bytes[1].ord & 0xFF)
|
102
|
+
b3 = bytes[2].nil? ? 0 : (bytes[2].ord & 0xFF)
|
103
|
+
result += append3bytes(b1, b2, b3)
|
97
104
|
end
|
98
|
-
|
99
|
-
plantuml_img_content(code, format, attrs)
|
105
|
+
join_paths(server_url, "/#{format}/", result).to_s
|
100
106
|
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def plantuml_ascii_content(code, format, attrs = {})
|
104
|
-
content = "<div class=\"listingblock\">"
|
105
|
-
content += "<div class=\"content\">"
|
106
|
-
content += "<pre "
|
107
|
-
content +="id=\"#{attrs['id']}\" " if attrs['id']
|
108
|
-
content +="class=\"plantuml\">\n"
|
109
|
-
content += code
|
110
|
-
content +="</pre>"
|
111
|
-
content += "</div>"
|
112
|
-
content += "</div>"
|
113
|
-
end
|
114
|
-
|
115
|
-
def plantuml_img_content(code, format, attrs = {})
|
116
|
-
content = "<div class=\"imageblock\">"
|
117
|
-
content += "<div class=\"content\">"
|
118
|
-
content += "<img "
|
119
|
-
content +="id=\"#{attrs['id']}\" " if attrs['id']
|
120
|
-
content +="class=\"plantuml\" "
|
121
|
-
content +="width=\"#{attrs['width']}\" " if attrs['width']
|
122
|
-
content +="height=\"#{attrs['height']}\" " if attrs['height']
|
123
|
-
content +="alt=\"#{attrs['alt']}\" " if attrs['alt']
|
124
|
-
content +="src=\"#{gen_url(code, format)}\" />"
|
125
|
-
content += "</div>"
|
126
|
-
content += "</div>"
|
127
|
-
end
|
128
|
-
|
129
|
-
def plantuml_invalid_content(format, attrs = {})
|
130
|
-
content = "<div class=\"listingblock\">"
|
131
|
-
content += "<div class=\"content\">"
|
132
|
-
content += "<pre "
|
133
|
-
content +="id=\"#{attrs['id']}\" " if attrs['id']
|
134
|
-
content +="class=\"plantuml plantuml-error\"> "
|
135
|
-
content += "PlantUML Error: Invalid format \"#{format}\""
|
136
|
-
content +="</pre>"
|
137
|
-
content += "</div>"
|
138
|
-
content += "</div>"
|
139
|
-
end
|
140
107
|
|
141
|
-
|
142
|
-
content = "<div class=\"listingblock\">"
|
143
|
-
content += "<div class=\"content\">"
|
144
|
-
content += "<pre "
|
145
|
-
content +="id=\"#{attrs['id']}\" " if attrs['id']
|
146
|
-
content +="class=\"plantuml plantuml-error\"> "
|
147
|
-
content += "PlantUML Error: cannot connect to PlantUML server at \"#{url}\""
|
148
|
-
content +="</pre>"
|
149
|
-
content += "</div>"
|
150
|
-
content += "</div>"
|
151
|
-
end
|
152
|
-
|
153
|
-
def plantuml_disabled_content(code, attrs = {})
|
154
|
-
content = "<div class=\"listingblock\">"
|
155
|
-
content += "<div class=\"content\">"
|
156
|
-
content += "<pre "
|
157
|
-
content +="id=\"#{attrs['id']}\" " if attrs['id']
|
158
|
-
content +="class=\"plantuml plantuml-error\">\n"
|
159
|
-
content += code
|
160
|
-
content +="</pre>"
|
161
|
-
content += "</div>"
|
162
|
-
content += "</div>"
|
163
|
-
end
|
108
|
+
private
|
164
109
|
|
110
|
+
def plantuml_txt_content(code, format, attrs = {})
|
111
|
+
begin
|
112
|
+
url = gen_url(code, format)
|
113
|
+
open(url) do |f|
|
114
|
+
plantuml_ascii_content(f.read, format, attrs)
|
115
|
+
end
|
116
|
+
rescue
|
117
|
+
plantuml_img_content(code, format, attrs)
|
118
|
+
end
|
119
|
+
end
|
165
120
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
result += append3bytes(b1, b2, b3)
|
121
|
+
def plantuml_ascii_content(code, format, attrs = {})
|
122
|
+
content = "<div class=\"listingblock\">"
|
123
|
+
content += "<div class=\"content\">"
|
124
|
+
content += "<pre "
|
125
|
+
content +="id=\"#{attrs['id']}\" " if attrs['id']
|
126
|
+
content +="class=\"plantuml\">\n"
|
127
|
+
content += code
|
128
|
+
content +="</pre>"
|
129
|
+
content += "</div>"
|
130
|
+
content += "</div>"
|
177
131
|
end
|
178
|
-
join_paths(server_url, "/#{format}/", result).to_s
|
179
|
-
end
|
180
132
|
|
181
|
-
|
182
|
-
|
183
|
-
|
133
|
+
def plantuml_img_content(code, format, attrs = {})
|
134
|
+
content = "<div class=\"imageblock\">"
|
135
|
+
content += "<div class=\"content\">"
|
136
|
+
content += "<img "
|
137
|
+
content +="id=\"#{attrs['id']}\" " if attrs['id']
|
138
|
+
content +="class=\"plantuml\" "
|
139
|
+
content +="width=\"#{attrs['width']}\" " if attrs['width']
|
140
|
+
content +="height=\"#{attrs['height']}\" " if attrs['height']
|
141
|
+
content +="alt=\"#{attrs['alt']}\" " if attrs['alt']
|
142
|
+
content +="src=\"#{gen_url(code, format)}\" />"
|
143
|
+
content += "</div>"
|
144
|
+
content += "</div>"
|
184
145
|
end
|
185
|
-
|
186
|
-
|
187
|
-
|
146
|
+
|
147
|
+
def plantuml_invalid_content(format, attrs = {})
|
148
|
+
content = "<div class=\"listingblock\">"
|
149
|
+
content += "<div class=\"content\">"
|
150
|
+
content += "<pre "
|
151
|
+
content +="id=\"#{attrs['id']}\" " if attrs['id']
|
152
|
+
content +="class=\"plantuml plantuml-error\"> "
|
153
|
+
content += "PlantUML Error: Invalid format \"#{format}\""
|
154
|
+
content +="</pre>"
|
155
|
+
content += "</div>"
|
156
|
+
content += "</div>"
|
188
157
|
end
|
189
|
-
|
190
|
-
|
191
|
-
|
158
|
+
|
159
|
+
def plantuml_server_unavailable_content(url, attrs = {})
|
160
|
+
content = "<div class=\"listingblock\">"
|
161
|
+
content += "<div class=\"content\">"
|
162
|
+
content += "<pre "
|
163
|
+
content +="id=\"#{attrs['id']}\" " if attrs['id']
|
164
|
+
content +="class=\"plantuml plantuml-error\"> "
|
165
|
+
content += "PlantUML Error: cannot connect to PlantUML server at \"#{url}\""
|
166
|
+
content +="</pre>"
|
167
|
+
content += "</div>"
|
168
|
+
content += "</div>"
|
192
169
|
end
|
193
|
-
|
194
|
-
|
195
|
-
|
170
|
+
|
171
|
+
def plantuml_disabled_content(code, attrs = {})
|
172
|
+
content = "<div class=\"listingblock\">"
|
173
|
+
content += "<div class=\"content\">"
|
174
|
+
content += "<pre "
|
175
|
+
content +="id=\"#{attrs['id']}\" " if attrs['id']
|
176
|
+
content +="class=\"plantuml plantuml-error\">\n"
|
177
|
+
content += code
|
178
|
+
content +="</pre>"
|
179
|
+
content += "</div>"
|
180
|
+
content += "</div>"
|
196
181
|
end
|
197
|
-
|
198
|
-
|
182
|
+
|
183
|
+
def encode6bit(b)
|
184
|
+
if b < 10
|
185
|
+
return ('0'.ord + b).chr
|
186
|
+
end
|
187
|
+
b = b - 10
|
188
|
+
if b < 26
|
189
|
+
return ('A'.ord + b).chr
|
190
|
+
end
|
191
|
+
b = b - 26
|
192
|
+
if b < 26
|
193
|
+
return ('a'.ord + b).chr
|
194
|
+
end
|
195
|
+
b = b - 26
|
196
|
+
if b == 0
|
197
|
+
return '-'
|
198
|
+
end
|
199
|
+
if b == 1
|
200
|
+
return '_'
|
201
|
+
end
|
202
|
+
return '?'
|
199
203
|
end
|
200
|
-
return '?'
|
201
|
-
end
|
202
204
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
205
|
+
def append3bytes(b1, b2, b3)
|
206
|
+
c1 = b1 >> 2
|
207
|
+
c2 = ((b1 & 0x3) << 4) | (b2 >> 4)
|
208
|
+
c3 = ((b2 & 0xF) << 2) | (b3 >> 6)
|
209
|
+
c4 = b3 & 0x3F
|
210
|
+
return encode6bit(c1 & 0x3F).chr +
|
211
|
+
encode6bit(c2 & 0x3F).chr +
|
212
|
+
encode6bit(c3 & 0x3F).chr +
|
213
|
+
encode6bit(c4 & 0x3F).chr
|
214
|
+
end
|
213
215
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
216
|
+
# Make a call to the PlantUML server with the simplest diagram possible to
|
217
|
+
# check if the server is available or not.
|
218
|
+
def check_server(check_url)
|
219
|
+
response = Net::HTTP.get_response(URI(check_url))
|
220
|
+
return response.is_a?(Net::HTTPSuccess)
|
221
|
+
rescue
|
222
|
+
return false
|
223
|
+
end
|
222
224
|
|
223
|
-
|
224
|
-
|
225
|
-
|
225
|
+
def valid_uri?(uri)
|
226
|
+
!(uri =~ /\A#{URI::regexp(['http', 'https'])}\z/).nil?
|
227
|
+
end
|
226
228
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
229
|
+
def join_paths(*paths, separator: '/')
|
230
|
+
paths = paths.compact.reject(&:empty?)
|
231
|
+
last = paths.length - 1
|
232
|
+
paths.each_with_index.map { |path, index|
|
233
|
+
expand_path(path, index, last, separator)
|
234
|
+
}.join
|
235
|
+
end
|
231
236
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
expand_path(path, index, last, separator)
|
237
|
-
}.join
|
238
|
-
end
|
237
|
+
def expand_path(path, current, last, separator)
|
238
|
+
if path.start_with?(separator) && current != 0
|
239
|
+
path = path[1..-1]
|
240
|
+
end
|
239
241
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
end
|
242
|
+
unless path.end_with?(separator) || current == last
|
243
|
+
path = [path, separator]
|
244
|
+
end
|
244
245
|
|
245
|
-
|
246
|
-
path = [path, separator]
|
246
|
+
path
|
247
247
|
end
|
248
|
-
|
249
|
-
path
|
250
248
|
end
|
251
249
|
end
|
252
250
|
|
253
251
|
class BlockProcessor < Asciidoctor::Extensions::BlockProcessor
|
254
|
-
include Processor
|
255
252
|
|
256
253
|
def process(parent, target, attrs)
|
257
254
|
|
@@ -265,11 +262,19 @@ module Asciidoctor
|
|
265
262
|
lines += ["@enduml"]
|
266
263
|
end
|
267
264
|
|
268
|
-
content = plantuml_content(lines.join("\n"), attrs)
|
265
|
+
content = Processor.plantuml_content(lines.join("\n"), attrs)
|
269
266
|
|
270
267
|
return create_plantuml_block(parent, content)
|
271
268
|
|
272
269
|
end
|
270
|
+
|
271
|
+
private
|
272
|
+
|
273
|
+
def create_plantuml_block(parent, content)
|
274
|
+
Asciidoctor::Block.new parent, :pass, :content_model => :raw,
|
275
|
+
:source => content, :subs => :default
|
276
|
+
end
|
277
|
+
|
273
278
|
end
|
274
279
|
|
275
280
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-plantuml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Horacio Sanson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|