asciidoctor-plantuml 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/asciidoctor_plantuml/plantuml.rb +28 -23
- data/lib/asciidoctor_plantuml/version.rb +1 -1
- data/test/test_plantuml.rb +174 -2
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de8d640d579d7d3c4171db4f02210fbe508868d8c70de10d4ce1a622bc8b14b1
|
4
|
+
data.tar.gz: a86d4afa322bf30c3f074c7c53e38dab0dcabf52df340ba685bae463143aa41f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e81d9655d877bc2d53492d954f08e7176e5c8da48eb0ac82d693368092684781fb173ae8b36baacab5f71f974d12596036c9dd6fccd3c3752a7ebcfcafe1384
|
7
|
+
data.tar.gz: 69eba0374e2621ca0abbb100154fd8f4627e09bbd5192d09feea79315f16a7486309deb60c76042b174068b61de29ae6294d1ac001582391b8d03907dfea4422
|
@@ -80,10 +80,9 @@ module Asciidoctor
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def plantuml_content_format(code, format, attrs = {})
|
83
|
-
if %w[png svg].include?(format)
|
84
|
-
|
85
|
-
|
86
|
-
plantuml_txt_content(code, format, attrs)
|
83
|
+
if %w[png svg txt].include?(format) &&
|
84
|
+
method("#{format}_enabled?").call
|
85
|
+
method("plantuml_#{format}_content").call(code, format, attrs)
|
87
86
|
else
|
88
87
|
plantuml_invalid_content(format, attrs)
|
89
88
|
end
|
@@ -125,7 +124,7 @@ module Asciidoctor
|
|
125
124
|
plantuml_ascii_content(f.read, attrs)
|
126
125
|
end
|
127
126
|
rescue OpenURI::HTTPError, Errno::ECONNREFUSED, SocketError
|
128
|
-
|
127
|
+
plantuml_png_content(code, format, attrs)
|
129
128
|
end
|
130
129
|
|
131
130
|
def plantuml_ascii_content(code, attrs = {})
|
@@ -140,7 +139,7 @@ module Asciidoctor
|
|
140
139
|
content + '</div>'
|
141
140
|
end
|
142
141
|
|
143
|
-
def
|
142
|
+
def plantuml_png_content(code, format, attrs = {})
|
144
143
|
content = '<div class="imageblock">'
|
145
144
|
content += '<div class="content">'
|
146
145
|
content += '<img '
|
@@ -154,37 +153,43 @@ module Asciidoctor
|
|
154
153
|
content + '</div>'
|
155
154
|
end
|
156
155
|
|
157
|
-
def
|
158
|
-
content = '<div class="
|
156
|
+
def plantuml_svg_content(code, format, attrs = {})
|
157
|
+
content = '<div class="imageblock">'
|
159
158
|
content += '<div class="content">'
|
160
|
-
content += '<
|
159
|
+
content += '<object type="image/svg+xml" '
|
160
|
+
content += "data=\"#{gen_url(code, format)}\" "
|
161
161
|
content += "id=\"#{attrs['id']}\" " if attrs['id']
|
162
|
-
content += '
|
163
|
-
content += "
|
164
|
-
content += '
|
162
|
+
content += "width=\"#{attrs['width']}\" " if attrs['width']
|
163
|
+
content += "height=\"#{attrs['height']}\" " if attrs['height']
|
164
|
+
content += '>'
|
165
|
+
attrs['id'] = 'fallback_' + attrs['id'] if attrs['id']
|
166
|
+
content += plantuml_png_content(code, format, attrs)
|
167
|
+
content += '</object>'
|
165
168
|
content += '</div>'
|
166
169
|
content + '</div>'
|
167
170
|
end
|
168
171
|
|
172
|
+
def plantuml_invalid_content(format, attrs = {})
|
173
|
+
error = "PlantUML Error: Invalid format \"#{format}\""
|
174
|
+
_plantuml_error_content(error, attrs)
|
175
|
+
end
|
176
|
+
|
169
177
|
def plantuml_server_unavailable_content(url, attrs = {})
|
170
|
-
|
171
|
-
|
172
|
-
content += '<pre '
|
173
|
-
content += "id=\"#{attrs['id']}\" " if attrs['id']
|
174
|
-
content += 'class="plantuml plantuml-error"> '
|
175
|
-
content += "Error: cannot connect to PlantUML server at \"#{url}\""
|
176
|
-
content += '</pre>'
|
177
|
-
content += '</div>'
|
178
|
-
content + '</div>'
|
178
|
+
error = "Error: cannot connect to PlantUML server at \"#{url}\""
|
179
|
+
_plantuml_error_content(error, attrs)
|
179
180
|
end
|
180
181
|
|
181
182
|
def plantuml_disabled_content(code, attrs = {})
|
183
|
+
_plantuml_error_content(code, attrs)
|
184
|
+
end
|
185
|
+
|
186
|
+
def _plantuml_error_content(error, attrs = {})
|
182
187
|
content = '<div class="listingblock">'
|
183
188
|
content += '<div class="content">'
|
184
189
|
content += '<pre '
|
185
190
|
content += "id=\"#{attrs['id']}\" " if attrs['id']
|
186
191
|
content += 'class="plantuml plantuml-error">\n'
|
187
|
-
content +=
|
192
|
+
content += error
|
188
193
|
content += '</pre>'
|
189
194
|
content += '</div>'
|
190
195
|
content + '</div>'
|
@@ -259,7 +264,7 @@ module Asciidoctor
|
|
259
264
|
class BlockProcessor < Asciidoctor::Extensions::BlockProcessor
|
260
265
|
use_dsl
|
261
266
|
named :plantuml
|
262
|
-
on_context :listing
|
267
|
+
on_context :listing, :literal
|
263
268
|
content_model :simple
|
264
269
|
|
265
270
|
def process(parent, target, attrs)
|
data/test/test_plantuml.rb
CHANGED
@@ -17,6 +17,17 @@ DOC_BASIC = <<~ENDOFSTRING
|
|
17
17
|
----
|
18
18
|
ENDOFSTRING
|
19
19
|
|
20
|
+
DOC_BASIC_LITERAL = <<~ENDOFSTRING
|
21
|
+
= Hello PlantUML!
|
22
|
+
|
23
|
+
[plantuml, format="png"]
|
24
|
+
.Title Of this
|
25
|
+
....
|
26
|
+
User -> (Start)
|
27
|
+
User --> (Use the application) : Label
|
28
|
+
....
|
29
|
+
ENDOFSTRING
|
30
|
+
|
20
31
|
DOC_BASIC2 = <<~ENDOFSTRING
|
21
32
|
= Hello PlantUML!
|
22
33
|
|
@@ -31,6 +42,20 @@ DOC_BASIC2 = <<~ENDOFSTRING
|
|
31
42
|
----
|
32
43
|
ENDOFSTRING
|
33
44
|
|
45
|
+
DOC_BASIC2_LITERAL = <<~ENDOFSTRING
|
46
|
+
= Hello PlantUML!
|
47
|
+
|
48
|
+
[plantuml, format="png"]
|
49
|
+
.Title Of this
|
50
|
+
[[fig-xref]]
|
51
|
+
....
|
52
|
+
@startuml
|
53
|
+
User -> (Start)
|
54
|
+
User --> (Use the application) : Label
|
55
|
+
@enduml
|
56
|
+
....
|
57
|
+
ENDOFSTRING
|
58
|
+
|
34
59
|
DOC_BASIC3 = <<~ENDOFSTRING
|
35
60
|
= Hello Compound PlantUML!
|
36
61
|
|
@@ -43,6 +68,18 @@ DOC_BASIC3 = <<~ENDOFSTRING
|
|
43
68
|
----
|
44
69
|
ENDOFSTRING
|
45
70
|
|
71
|
+
DOC_BASIC3_LITERAL = <<~ENDOFSTRING
|
72
|
+
= Hello Compound PlantUML!
|
73
|
+
|
74
|
+
[plantuml, format="png"]
|
75
|
+
....
|
76
|
+
[COMP1]
|
77
|
+
[COMP2]
|
78
|
+
[COMP1] -> [COMP2]
|
79
|
+
[COMP2] --> [COMP3]
|
80
|
+
....
|
81
|
+
ENDOFSTRING
|
82
|
+
|
46
83
|
DOC_ID = <<~ENDOFSTRING
|
47
84
|
= Hello PlantUML!
|
48
85
|
|
@@ -105,6 +142,28 @@ DOC_MULTI = <<~ENDOFSTRING
|
|
105
142
|
----
|
106
143
|
ENDOFSTRING
|
107
144
|
|
145
|
+
DOC_MULTI_LITERAL = <<~ENDOFSTRING
|
146
|
+
= Hello PlantUML!
|
147
|
+
|
148
|
+
[plantuml, format="png"]
|
149
|
+
....
|
150
|
+
User -> (Start)
|
151
|
+
User --> (Use the application) : Label
|
152
|
+
....
|
153
|
+
|
154
|
+
[plantuml, format="png"]
|
155
|
+
....
|
156
|
+
User -> (Start)
|
157
|
+
User --> (Use the application) : Label
|
158
|
+
....
|
159
|
+
|
160
|
+
[plantuml, format="txt"]
|
161
|
+
....
|
162
|
+
User -> (Start)
|
163
|
+
User --> (Use the application) : Label
|
164
|
+
....
|
165
|
+
ENDOFSTRING
|
166
|
+
|
108
167
|
DOC_TXT = <<~ENDOFSTRING
|
109
168
|
= Hello PlantUML!
|
110
169
|
|
@@ -115,15 +174,28 @@ DOC_TXT = <<~ENDOFSTRING
|
|
115
174
|
----
|
116
175
|
ENDOFSTRING
|
117
176
|
|
177
|
+
DOC_SVG = <<~ENDOFSTRING
|
178
|
+
= Hello PlantUML!
|
179
|
+
|
180
|
+
[plantuml, format="svg"]
|
181
|
+
----
|
182
|
+
User -> (Start)
|
183
|
+
User --> (Use the application) : Label
|
184
|
+
----
|
185
|
+
ENDOFSTRING
|
186
|
+
|
118
187
|
class PlantUmlTest < Test::Unit::TestCase
|
119
188
|
GENURL = 'http://localhost:8080/plantuml/png/U9npA2v9B2efpStX2YrEBLBGjLFG20Q9Q4Bv804WIw4a8rKXiQ0W9pCviIGpFqzJmKh19p4fDOVB8JKl1QWT05kd5wq0'
|
120
189
|
GENURL2 = 'http://localhost:8080/plantuml/png/U9npA2v9B2efpStXYdRszmqmZ8NGHh4mleAkdGAAa15G22Pc7Clba9gN0jGE00W75Cm0'
|
121
190
|
GENURL_ENCODING = 'http://localhost:8080/plantuml/png/~1U9npA2v9B2efpStX2YrEBLBGjLFG20Q9Q4Bv804WIw4a8rKXiQ0W9pCviIGpFqzJmKh19p4fDOVB8JKl1QWT05kd5wq0'
|
191
|
+
SVGGENURL = 'http://localhost:8080/plantuml/svg/~1U9npA2v9B2efpStX2YrEBLBGjLFG20Q9Q4Bv804WIw4a8rKXiQ0W9pCviIGpFqzJmKh19p4fDOVB8JKl1QWT05kd5wq0'
|
122
192
|
|
123
193
|
def setup
|
124
194
|
Asciidoctor::PlantUml.configure do |c|
|
125
195
|
c.url = 'http://localhost:8080/plantuml'
|
126
196
|
c.txt_enable = true
|
197
|
+
c.png_enable = true
|
198
|
+
c.svg_enable = true
|
127
199
|
end
|
128
200
|
end
|
129
201
|
|
@@ -140,8 +212,40 @@ class PlantUmlTest < Test::Unit::TestCase
|
|
140
212
|
assert_equal GENURL, element['src']
|
141
213
|
end
|
142
214
|
|
215
|
+
def test_plantuml_block_literal_processor
|
216
|
+
html = ::Asciidoctor.convert(
|
217
|
+
StringIO.new(DOC_BASIC_LITERAL), backend: 'html5'
|
218
|
+
)
|
219
|
+
page = Nokogiri::HTML(html)
|
220
|
+
|
221
|
+
elements = page.css('img.plantuml')
|
222
|
+
|
223
|
+
assert_equal elements.size, 1
|
224
|
+
|
225
|
+
element = elements.first
|
226
|
+
|
227
|
+
assert_equal GENURL, element['src']
|
228
|
+
end
|
229
|
+
|
143
230
|
def test_plantuml_block_processor2
|
144
|
-
html = ::Asciidoctor.convert(
|
231
|
+
html = ::Asciidoctor.convert(
|
232
|
+
StringIO.new(DOC_BASIC2), backend: 'html5'
|
233
|
+
)
|
234
|
+
page = Nokogiri::HTML(html)
|
235
|
+
|
236
|
+
elements = page.css('img.plantuml')
|
237
|
+
|
238
|
+
assert_equal elements.size, 1
|
239
|
+
|
240
|
+
element = elements.first
|
241
|
+
|
242
|
+
assert_equal GENURL, element['src']
|
243
|
+
end
|
244
|
+
|
245
|
+
def test_plantuml_block_literal_processor2
|
246
|
+
html = ::Asciidoctor.convert(
|
247
|
+
StringIO.new(DOC_BASIC2_LITERAL), backend: 'html5'
|
248
|
+
)
|
145
249
|
page = Nokogiri::HTML(html)
|
146
250
|
|
147
251
|
elements = page.css('img.plantuml')
|
@@ -166,6 +270,21 @@ class PlantUmlTest < Test::Unit::TestCase
|
|
166
270
|
assert_equal GENURL2, element['src']
|
167
271
|
end
|
168
272
|
|
273
|
+
def test_plantuml_block_literal_processor3
|
274
|
+
html = ::Asciidoctor.convert(
|
275
|
+
StringIO.new(DOC_BASIC3_LITERAL), backend: 'html5'
|
276
|
+
)
|
277
|
+
page = Nokogiri::HTML(html)
|
278
|
+
|
279
|
+
elements = page.css('img.plantuml')
|
280
|
+
|
281
|
+
assert_equal elements.size, 1
|
282
|
+
|
283
|
+
element = elements.first
|
284
|
+
|
285
|
+
assert_equal GENURL2, element['src']
|
286
|
+
end
|
287
|
+
|
169
288
|
def test_plantuml_block_processor_encoding
|
170
289
|
Asciidoctor::PlantUml.configure do |c|
|
171
290
|
c.encoding = 'deflate'
|
@@ -229,7 +348,7 @@ class PlantUmlTest < Test::Unit::TestCase
|
|
229
348
|
assert_equal elements.size, 1
|
230
349
|
end
|
231
350
|
|
232
|
-
def
|
351
|
+
def test_plantuml_multiple_listing
|
233
352
|
html = ::Asciidoctor.convert(StringIO.new(DOC_MULTI), backend: 'html5')
|
234
353
|
page = Nokogiri::HTML(html)
|
235
354
|
|
@@ -240,6 +359,19 @@ class PlantUmlTest < Test::Unit::TestCase
|
|
240
359
|
assert_equal elements.size, 0
|
241
360
|
end
|
242
361
|
|
362
|
+
def test_plantuml_multiple_literal
|
363
|
+
html = ::Asciidoctor.convert(
|
364
|
+
StringIO.new(DOC_MULTI_LITERAL), backend: 'html5'
|
365
|
+
)
|
366
|
+
page = Nokogiri::HTML(html)
|
367
|
+
|
368
|
+
elements = page.css('img.plantuml')
|
369
|
+
assert elements.size >= 2
|
370
|
+
|
371
|
+
elements = page.css('.plantuml-error')
|
372
|
+
assert_equal elements.size, 0
|
373
|
+
end
|
374
|
+
|
243
375
|
def test_plantuml_bad_server
|
244
376
|
Asciidoctor::PlantUml.configure do |c|
|
245
377
|
c.url = 'http://nonexistent.com/plantuml'
|
@@ -299,4 +431,44 @@ class PlantUmlTest < Test::Unit::TestCase
|
|
299
431
|
elements = page.css('pre.plantuml-error')
|
300
432
|
assert_equal elements.size, 1
|
301
433
|
end
|
434
|
+
|
435
|
+
def test_svg
|
436
|
+
Asciidoctor::PlantUml.configure do |c|
|
437
|
+
c.url = 'http://localhost:8080/plantuml'
|
438
|
+
c.svg_enable = true
|
439
|
+
end
|
440
|
+
|
441
|
+
html = ::Asciidoctor.convert(StringIO.new(DOC_SVG), backend: 'html5')
|
442
|
+
page = Nokogiri::HTML(html)
|
443
|
+
elements = page.css("object[type='image/svg+xml']")
|
444
|
+
assert_equal elements.size, 1
|
445
|
+
|
446
|
+
element = elements.first
|
447
|
+
|
448
|
+
assert_equal SVGGENURL, element['data']
|
449
|
+
end
|
450
|
+
|
451
|
+
def test_disable_svg
|
452
|
+
Asciidoctor::PlantUml.configure do |c|
|
453
|
+
c.url = 'http://localhost:8080/plantuml'
|
454
|
+
c.svg_enable = false
|
455
|
+
end
|
456
|
+
|
457
|
+
html = ::Asciidoctor.convert(StringIO.new(DOC_SVG), backend: 'html5')
|
458
|
+
page = Nokogiri::HTML(html)
|
459
|
+
elements = page.css('pre.plantuml-error')
|
460
|
+
assert_equal elements.size, 1
|
461
|
+
end
|
462
|
+
|
463
|
+
def test_disable_png
|
464
|
+
Asciidoctor::PlantUml.configure do |c|
|
465
|
+
c.url = 'http://localhost:8080/plantuml'
|
466
|
+
c.png_enable = false
|
467
|
+
end
|
468
|
+
|
469
|
+
html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC_LITERAL), backend: 'html5')
|
470
|
+
page = Nokogiri::HTML(html)
|
471
|
+
elements = page.css('pre.plantuml-error')
|
472
|
+
assert_equal elements.size, 1
|
473
|
+
end
|
302
474
|
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.13
|
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: 2021-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '1.7'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '1.7'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: test-unit
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,8 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
requirements: []
|
133
|
-
|
134
|
-
rubygems_version: 2.7.6
|
133
|
+
rubygems_version: 3.1.2
|
135
134
|
signing_key:
|
136
135
|
specification_version: 4
|
137
136
|
summary: Asciidoctor support for PlantUML diagrams.
|