asciidoctor-kroki 0.10.2 → 0.19.0
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/Gemfile +8 -0
- data/Gemfile.lock +15 -1
- data/README.md +2 -0
- data/asciidoctor-kroki.gemspec +1 -0
- data/lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb +27 -20
- data/lib/asciidoctor/extensions/asciidoctor_kroki/version.rb +1 -1
- data/spec/asciidoctor_kroki_client_spec.rb +46 -0
- data/spec/asciidoctor_kroki_diagram_spec.rb +24 -22
- data/spec/asciidoctor_kroki_spec.rb +31 -7
- data/spec/rspec_helper.rb +39 -2
- metadata +17 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 13950d71fa8552c2021db4943c0b706c6a7a71a87324ad380ad37614a0fab665
|
|
4
|
+
data.tar.gz: f449e68ab584d868f356673cc12a60daac1405654b49e7b0ec7b06724fc7cdc3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1e0b55bac8d6f4c2e1f1c1177b12a0ddf3ae829d6d71b3931c8c8f163b4857b43e64071e8fec95d1b2dbf368622f438cc9d2d3d64abe2620bc7c5afcb7dd370d
|
|
7
|
+
data.tar.gz: 5a70924dc6d2c2c3ecff3717544bc1fa7a2f8a2f9432148d935af820b9c4186643866cb849872ba8222697f73fdf8efe19db8bf98e45e278816d3bd0ae845d12
|
data/Gemfile
CHANGED
|
@@ -3,3 +3,11 @@
|
|
|
3
3
|
source 'https://rubygems.org'
|
|
4
4
|
|
|
5
5
|
gemspec
|
|
6
|
+
|
|
7
|
+
# Dependencies of testcontainers-core: the latest versions compatible with Ruby 2.7 (tested in CI),
|
|
8
|
+
# since Gemfile.lock is shared by all the Ruby versions.
|
|
9
|
+
gem 'excon', '< 1.2.6'
|
|
10
|
+
gem 'multi_json', '< 1.16'
|
|
11
|
+
|
|
12
|
+
# required by testcontainers-core but not declared, and no longer a default gem since Ruby 3.4
|
|
13
|
+
gem 'base64', '~> 0.3.0'
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
asciidoctor-kroki (0.
|
|
4
|
+
asciidoctor-kroki (0.19.0)
|
|
5
5
|
asciidoctor (~> 2.0)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
@@ -9,10 +9,18 @@ GEM
|
|
|
9
9
|
specs:
|
|
10
10
|
asciidoctor (2.0.22)
|
|
11
11
|
ast (2.4.3)
|
|
12
|
+
base64 (0.3.0)
|
|
12
13
|
diff-lcs (1.6.2)
|
|
14
|
+
docker-api (2.4.0)
|
|
15
|
+
excon (>= 0.64.0)
|
|
16
|
+
multi_json
|
|
17
|
+
excon (1.2.5)
|
|
18
|
+
logger
|
|
13
19
|
json (2.13.0)
|
|
14
20
|
language_server-protocol (3.17.0.5)
|
|
15
21
|
lint_roller (1.1.0)
|
|
22
|
+
logger (1.7.0)
|
|
23
|
+
multi_json (1.15.0)
|
|
16
24
|
parallel (1.27.0)
|
|
17
25
|
parser (3.3.8.0)
|
|
18
26
|
ast (~> 2.4.1)
|
|
@@ -50,6 +58,8 @@ GEM
|
|
|
50
58
|
parser (>= 3.3.7.2)
|
|
51
59
|
prism (~> 1.4)
|
|
52
60
|
ruby-progressbar (1.13.0)
|
|
61
|
+
testcontainers-core (0.2.0)
|
|
62
|
+
docker-api (~> 2.2)
|
|
53
63
|
unicode-display_width (3.1.4)
|
|
54
64
|
unicode-emoji (~> 4.0, >= 4.0.4)
|
|
55
65
|
unicode-emoji (4.0.4)
|
|
@@ -59,9 +69,13 @@ PLATFORMS
|
|
|
59
69
|
|
|
60
70
|
DEPENDENCIES
|
|
61
71
|
asciidoctor-kroki!
|
|
72
|
+
base64 (~> 0.3.0)
|
|
73
|
+
excon (< 1.2.6)
|
|
74
|
+
multi_json (< 1.16)
|
|
62
75
|
rake (~> 13.3.0)
|
|
63
76
|
rspec (~> 3.13.1)
|
|
64
77
|
rubocop (~> 1.78)
|
|
78
|
+
testcontainers-core (~> 0.2.0)
|
|
65
79
|
|
|
66
80
|
BUNDLED WITH
|
|
67
81
|
2.3.15
|
data/README.md
CHANGED
|
@@ -317,7 +317,9 @@ Kroki currently supports the following diagram libraries:
|
|
|
317
317
|
* [Ditaa](http://ditaa.sourceforge.net): `ditaa`
|
|
318
318
|
* [ERD](https://github.com/BurntSushi/erd): `erd`
|
|
319
319
|
* [Excalidraw](https://github.com/excalidraw/excalidraw): `excalidraw`
|
|
320
|
+
* [GoAT](https://github.com/blampe/goat): `goat`
|
|
320
321
|
* [GraphViz](https://www.graphviz.org/): `graphviz`
|
|
322
|
+
* [Lini](https://lini.rs): `lini` _(requires Kroki 0.34.0 or later)_
|
|
321
323
|
* [Mermaid](https://github.com/knsv/mermaid): `mermaid`
|
|
322
324
|
* [Nomnoml](https://github.com/skanaar/nomnoml): `nomnoml`
|
|
323
325
|
* [NwDiag](https://github.com/blockdiag/nwdiag): `nwdiag`
|
data/asciidoctor-kroki.gemspec
CHANGED
|
@@ -124,7 +124,9 @@ module AsciidoctorExtensions
|
|
|
124
124
|
ditaa
|
|
125
125
|
erd
|
|
126
126
|
excalidraw
|
|
127
|
+
goat
|
|
127
128
|
graphviz
|
|
129
|
+
lini
|
|
128
130
|
mermaid
|
|
129
131
|
nomnoml
|
|
130
132
|
nwdiag
|
|
@@ -239,8 +241,8 @@ module AsciidoctorExtensions
|
|
|
239
241
|
if format == 'png'
|
|
240
242
|
# redirect PNG format to SVG if the diagram library only supports SVG as output format.
|
|
241
243
|
# this is useful when the default format has been set to PNG
|
|
242
|
-
# Currently, nomnoml, svgbob, wavedrom only support SVG as output format.
|
|
243
|
-
svg_only_diagram_types = %i[nomnoml svgbob wavedrom]
|
|
244
|
+
# Currently, bpmn, bytefield, d2, dbml, excalidraw, goat, lini, nomnoml, pikchr, svgbob, wavedrom only support SVG as output format.
|
|
245
|
+
svg_only_diagram_types = %i[bpmn bytefield d2 dbml excalidraw goat lini nomnoml pikchr svgbob wavedrom]
|
|
244
246
|
format = 'svg' if svg_only_diagram_types.include?(diagram_type)
|
|
245
247
|
end
|
|
246
248
|
format
|
|
@@ -297,9 +299,20 @@ module AsciidoctorExtensions
|
|
|
297
299
|
@opts = opts
|
|
298
300
|
end
|
|
299
301
|
|
|
302
|
+
# Builds the query string that carries the diagram options.
|
|
303
|
+
# The options are only sent as query parameters, with GET and with POST, like the JavaScript extension does.
|
|
304
|
+
# A custom request header, such as Kroki-Diagram-Options-*, would make a browser send a CORS preflight request.
|
|
305
|
+
#
|
|
306
|
+
# @param opts [Hash] the diagram options
|
|
307
|
+
# @return [String] the query string, including the leading "?", or an empty string without options
|
|
308
|
+
def self.options_query_string(opts)
|
|
309
|
+
return '' if opts.nil? || opts.empty?
|
|
310
|
+
|
|
311
|
+
"?#{opts.map { |k, v| "#{k}=#{CGI.escape(v.to_s).gsub('+', '%20')}" }.join('&')}"
|
|
312
|
+
end
|
|
313
|
+
|
|
300
314
|
def get_diagram_uri(server_url)
|
|
301
|
-
|
|
302
|
-
_join_uri_segments(server_url, @type, @format, encode) + (query_params ? "?#{query_params}" : '')
|
|
315
|
+
_join_uri_segments(server_url, @type, @format, encode) + KrokiDiagram.options_query_string(opts)
|
|
303
316
|
end
|
|
304
317
|
|
|
305
318
|
def encode
|
|
@@ -328,10 +341,6 @@ module AsciidoctorExtensions
|
|
|
328
341
|
|
|
329
342
|
private
|
|
330
343
|
|
|
331
|
-
def _url_encode(text)
|
|
332
|
-
CGI.escape(text).gsub('+', '%20')
|
|
333
|
-
end
|
|
334
|
-
|
|
335
344
|
def _join_uri_segments(base, *uris)
|
|
336
345
|
segments = []
|
|
337
346
|
# remove trailing slashes
|
|
@@ -379,6 +388,8 @@ module AsciidoctorExtensions
|
|
|
379
388
|
format = kroki_diagram.format
|
|
380
389
|
text = kroki_diagram.text
|
|
381
390
|
opts = kroki_diagram.opts
|
|
391
|
+
# the diagram source is sent as the body, and the diagram options as query parameters
|
|
392
|
+
post_uri = "#{@server_url}/#{type}/#{format}#{KrokiDiagram.options_query_string(opts)}"
|
|
382
393
|
if @method == 'adaptive' || @method == 'get'
|
|
383
394
|
uri = kroki_diagram.get_diagram_uri(server_url)
|
|
384
395
|
if uri.length > @max_uri_length
|
|
@@ -388,13 +399,13 @@ module AsciidoctorExtensions
|
|
|
388
399
|
# Consider using the attribute kroki-http-method with the value 'adaptive'.
|
|
389
400
|
@http_client.get(uri, opts, encoding)
|
|
390
401
|
else
|
|
391
|
-
@http_client.post(
|
|
402
|
+
@http_client.post(post_uri, text, opts, encoding)
|
|
392
403
|
end
|
|
393
404
|
else
|
|
394
405
|
@http_client.get(uri, opts, encoding)
|
|
395
406
|
end
|
|
396
407
|
else
|
|
397
|
-
@http_client.post(
|
|
408
|
+
@http_client.post(post_uri, text, opts, encoding)
|
|
398
409
|
end
|
|
399
410
|
end
|
|
400
411
|
end
|
|
@@ -409,11 +420,10 @@ module AsciidoctorExtensions
|
|
|
409
420
|
class << self
|
|
410
421
|
REFERER = "asciidoctor/kroki.rb/#{Asciidoctor::AsciidoctorKroki::VERSION}"
|
|
411
422
|
|
|
412
|
-
|
|
423
|
+
# The diagram options (_opts) are part of the URI, they are not sent as request headers.
|
|
424
|
+
def get(uri, _opts, _)
|
|
413
425
|
uri = URI(uri)
|
|
414
|
-
|
|
415
|
-
.merge({ 'referer' => REFERER })
|
|
416
|
-
request = ::Net::HTTP::Get.new(uri, headers)
|
|
426
|
+
request = ::Net::HTTP::Get.new(uri, { 'referer' => REFERER })
|
|
417
427
|
::Net::HTTP.start(
|
|
418
428
|
uri.hostname,
|
|
419
429
|
uri.port,
|
|
@@ -423,12 +433,9 @@ module AsciidoctorExtensions
|
|
|
423
433
|
end
|
|
424
434
|
end
|
|
425
435
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
'Content-Type' => 'text/plain',
|
|
430
|
-
'referer' => REFERER
|
|
431
|
-
})
|
|
436
|
+
# The diagram options (_opts) are part of the URI, they are not sent as request headers.
|
|
437
|
+
def post(uri, data, _opts, _)
|
|
438
|
+
headers = { 'Content-Type' => 'text/plain', 'referer' => REFERER }
|
|
432
439
|
res = ::Net::HTTP.post(
|
|
433
440
|
URI(uri),
|
|
434
441
|
data,
|
|
@@ -60,6 +60,52 @@ describe AsciidoctorExtensions::KrokiClient do
|
|
|
60
60
|
result = kroki_client.get_image(kroki_diagram, 'utf8')
|
|
61
61
|
expect(result).to eq('POST http://localhost:8000/type/format - text')
|
|
62
62
|
end
|
|
63
|
+
context 'with diagram options' do
|
|
64
|
+
it 'should send the diagram options as URL-encoded query parameters with a POST request' do
|
|
65
|
+
kroki_http_client = Class.new do
|
|
66
|
+
class << self
|
|
67
|
+
def post(uri, data, _, _)
|
|
68
|
+
"POST #{uri} - #{data}"
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
kroki_diagram = AsciidoctorExtensions::KrokiDiagram.new('plantuml', 'svg', 'alice -> bob', nil, { 'theme' => 'my theme/value', 'no-separation' => true })
|
|
73
|
+
kroki_client = AsciidoctorExtensions::KrokiClient.new(server_url: 'http://localhost:8000', http_method: 'post', http_client: kroki_http_client)
|
|
74
|
+
result = kroki_client.get_image(kroki_diagram, 'utf8')
|
|
75
|
+
expect(result).to eq('POST http://localhost:8000/plantuml/svg?theme=my%20theme%2Fvalue&no-separation=true - alice -> bob')
|
|
76
|
+
end
|
|
77
|
+
it 'should not send the diagram options as request headers' do
|
|
78
|
+
server = TCPServer.new('127.0.0.1', 0)
|
|
79
|
+
headers = []
|
|
80
|
+
thread = Thread.new do
|
|
81
|
+
client = server.accept
|
|
82
|
+
while (line = client.gets) && line != "\r\n"
|
|
83
|
+
headers << line.chomp.downcase
|
|
84
|
+
end
|
|
85
|
+
# the body must be read before the connection is closed, otherwise the client gets a connection reset on Windows
|
|
86
|
+
client.read(headers.grep(/^content-length:/).first.to_s.split(':').last.to_i)
|
|
87
|
+
client.write("HTTP/1.1 200 OK\r\nContent-Length: 2\r\nConnection: close\r\n\r\nok")
|
|
88
|
+
client.close
|
|
89
|
+
end
|
|
90
|
+
url = "http://127.0.0.1:#{server.addr[1]}/plantuml/svg?theme=bluegray"
|
|
91
|
+
result = AsciidoctorExtensions::KrokiHttpClient.post(url, 'alice -> bob', { 'theme' => 'bluegray' }, 'utf8')
|
|
92
|
+
thread.join(5)
|
|
93
|
+
server.close
|
|
94
|
+
expect(result).to eq('ok')
|
|
95
|
+
expect(headers.grep(/^kroki-diagram-options-/)).to be_empty
|
|
96
|
+
expect(headers).to include('content-type: text/plain')
|
|
97
|
+
end
|
|
98
|
+
it 'should apply the diagram options with a POST request', kroki_server: true do
|
|
99
|
+
http_client = AsciidoctorExtensions::KrokiHttpClient
|
|
100
|
+
post_client = AsciidoctorExtensions::KrokiClient.new(server_url: kroki_server_url, http_method: 'post', http_client: http_client)
|
|
101
|
+
get_client = AsciidoctorExtensions::KrokiClient.new(server_url: kroki_server_url, http_method: 'get', http_client: http_client)
|
|
102
|
+
themed = AsciidoctorExtensions::KrokiDiagram.new('plantuml', 'svg', 'alice -> bob', nil, { 'theme' => 'bluegray' })
|
|
103
|
+
plain = AsciidoctorExtensions::KrokiDiagram.new('plantuml', 'svg', 'alice -> bob')
|
|
104
|
+
themed_svg = post_client.text_content(themed)
|
|
105
|
+
expect(themed_svg).to eq(get_client.text_content(themed))
|
|
106
|
+
expect(themed_svg).not_to eq(post_client.text_content(plain))
|
|
107
|
+
end
|
|
108
|
+
end
|
|
63
109
|
it 'should get an image with GET request if the URI length is lower or equals than the value configured' do
|
|
64
110
|
kroki_http_client = Class.new do
|
|
65
111
|
class << self
|
|
@@ -43,44 +43,46 @@ describe AsciidoctorExtensions::KrokiDiagram do
|
|
|
43
43
|
diagram_definition_encoded = kroki_diagram.encode
|
|
44
44
|
expect(diagram_definition_encoded).to eq('eNpTSMzJTE5V0LVTSMpPslLISM3JyQcAQAwGaw==')
|
|
45
45
|
end
|
|
46
|
-
it 'should fetch a diagram from Kroki and save it to disk' do
|
|
46
|
+
it 'should fetch a diagram from Kroki and save it to disk', kroki_server: true do
|
|
47
47
|
kroki_diagram = AsciidoctorExtensions::KrokiDiagram.new('plantuml', 'txt', ' alice -> bob: hello')
|
|
48
48
|
kroki_http_client = AsciidoctorExtensions::KrokiHttpClient
|
|
49
|
-
kroki_client = AsciidoctorExtensions::KrokiClient.new(server_url:
|
|
49
|
+
kroki_client = AsciidoctorExtensions::KrokiClient.new(server_url: kroki_server_url, http_method: 'get', http_client: kroki_http_client)
|
|
50
50
|
output_dir_path = "#{__dir__}/../.asciidoctor/kroki"
|
|
51
51
|
diagram_name = kroki_diagram.save(output_dir_path, kroki_client)
|
|
52
52
|
diagram_path = File.join(output_dir_path, diagram_name)
|
|
53
53
|
expect(File.exist?(diagram_path)).to be_truthy, "diagram should be saved at: #{diagram_path}"
|
|
54
|
-
content =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
content = <<~TXT.chomp
|
|
55
|
+
,-----. ,---.
|
|
56
|
+
|alice| |bob|
|
|
57
|
+
`--+--' `-+-'
|
|
58
|
+
| hello |
|
|
59
|
+
|------->|
|
|
60
|
+
| |
|
|
61
|
+
,--+--. ,-+-.
|
|
62
|
+
|alice| |bob|
|
|
63
|
+
`-----' `---'
|
|
63
64
|
TXT
|
|
64
65
|
expect(File.read(diagram_path).split("\n").map(&:rstrip).join("\n")).to eq(content)
|
|
65
66
|
end
|
|
66
|
-
it 'should fetch a diagram from Kroki and save it to disk using the target name' do
|
|
67
|
+
it 'should fetch a diagram from Kroki and save it to disk using the target name', kroki_server: true do
|
|
67
68
|
kroki_diagram = AsciidoctorExtensions::KrokiDiagram.new('plantuml', 'txt', ' alice -> bob: hello', 'hello-world')
|
|
68
69
|
kroki_http_client = AsciidoctorExtensions::KrokiHttpClient
|
|
69
|
-
kroki_client = AsciidoctorExtensions::KrokiClient.new(server_url:
|
|
70
|
+
kroki_client = AsciidoctorExtensions::KrokiClient.new(server_url: kroki_server_url, http_method: 'get', http_client: kroki_http_client)
|
|
70
71
|
output_dir_path = "#{__dir__}/../.asciidoctor/kroki"
|
|
71
72
|
diagram_name = kroki_diagram.save(output_dir_path, kroki_client)
|
|
72
73
|
diagram_path = File.join(output_dir_path, diagram_name)
|
|
73
74
|
expect(diagram_name).to start_with('hello-world-'), "diagram name should use the target as a prefix, got: #{diagram_name}"
|
|
74
75
|
expect(File.exist?(diagram_path)).to be_truthy, "diagram should be saved at: #{diagram_path}"
|
|
75
|
-
content =
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
content = <<~TXT.chomp
|
|
77
|
+
,-----. ,---.
|
|
78
|
+
|alice| |bob|
|
|
79
|
+
`--+--' `-+-'
|
|
80
|
+
| hello |
|
|
81
|
+
|------->|
|
|
82
|
+
| |
|
|
83
|
+
,--+--. ,-+-.
|
|
84
|
+
|alice| |bob|
|
|
85
|
+
`-----' `---'
|
|
84
86
|
TXT
|
|
85
87
|
expect(File.read(diagram_path).split("\n").map(&:rstrip).join("\n")).to eq(content)
|
|
86
88
|
end
|
|
@@ -80,6 +80,28 @@ describe AsciidoctorExtensions::KrokiBlockProcessor do
|
|
|
80
80
|
</div>
|
|
81
81
|
</div>)
|
|
82
82
|
end
|
|
83
|
+
%w[bpmn bytefield d2 dbml excalidraw goat lini nomnoml pikchr svgbob wavedrom].each do |diagram_type|
|
|
84
|
+
it "should use svg if kroki-default-format is set to png for #{diagram_type}" do
|
|
85
|
+
input = <<~ADOC.sub('DIAGRAM', diagram_type)
|
|
86
|
+
[DIAGRAM]
|
|
87
|
+
....
|
|
88
|
+
content
|
|
89
|
+
....
|
|
90
|
+
ADOC
|
|
91
|
+
output = Asciidoctor.convert(input, attributes: { 'kroki-default-format' => 'png' }, standalone: false)
|
|
92
|
+
(expect output).to include("https://kroki.io/#{diagram_type}/svg/")
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
it 'should keep png for symbolator if kroki-default-format is set to png' do
|
|
96
|
+
input = <<~ADOC
|
|
97
|
+
[symbolator]
|
|
98
|
+
....
|
|
99
|
+
content
|
|
100
|
+
....
|
|
101
|
+
ADOC
|
|
102
|
+
output = Asciidoctor.convert(input, attributes: { 'kroki-default-format' => 'png' }, standalone: false)
|
|
103
|
+
(expect output).to include('https://kroki.io/symbolator/png/')
|
|
104
|
+
end
|
|
83
105
|
it 'should include the plantuml-include file when safe mode is safe' do
|
|
84
106
|
input = <<~ADOC
|
|
85
107
|
[plantuml]
|
|
@@ -138,16 +160,17 @@ describe AsciidoctorExtensions::KrokiBlockProcessor do
|
|
|
138
160
|
</div>
|
|
139
161
|
</div>)
|
|
140
162
|
end
|
|
141
|
-
it 'should create SVG diagram in imagesdir if kroki-fetch-diagram is set' do
|
|
163
|
+
it 'should create SVG diagram in imagesdir if kroki-fetch-diagram is set', kroki_server: true do
|
|
142
164
|
input = <<~ADOC
|
|
143
165
|
:imagesdir: .asciidoctor/kroki
|
|
144
166
|
|
|
145
167
|
plantuml::spec/fixtures/alice.puml[svg,role=sequence]
|
|
146
168
|
ADOC
|
|
147
|
-
output = Asciidoctor.convert(input, attributes: { 'kroki-fetch-diagram' => '' }, standalone: false, safe: :safe)
|
|
169
|
+
output = Asciidoctor.convert(input, attributes: { 'kroki-fetch-diagram' => '', 'kroki-server-url' => kroki_server_url }, standalone: false, safe: :safe)
|
|
170
|
+
diagram_hash = Digest::SHA256.hexdigest("#{kroki_server_url}/plantuml/svg/eNpLzMlMTlXQtVNIyk-yUshIzcnJ5wIAQ-AGVQ==")
|
|
148
171
|
(expect output).to eql %(<div class="imageblock sequence kroki-format-svg kroki">
|
|
149
172
|
<div class="content">
|
|
150
|
-
<img src=".asciidoctor/kroki/diag
|
|
173
|
+
<img src=".asciidoctor/kroki/diag-#{diagram_hash}.svg" alt="Diagram">
|
|
151
174
|
</div>
|
|
152
175
|
</div>)
|
|
153
176
|
end
|
|
@@ -164,16 +187,17 @@ describe AsciidoctorExtensions::KrokiBlockProcessor do
|
|
|
164
187
|
</div>
|
|
165
188
|
</div>)
|
|
166
189
|
end
|
|
167
|
-
it 'should create PNG diagram in imagesdir if kroki-fetch-diagram is set' do
|
|
190
|
+
it 'should create PNG diagram in imagesdir if kroki-fetch-diagram is set', kroki_server: true do
|
|
168
191
|
input = <<~ADOC
|
|
169
192
|
:imagesdir: .asciidoctor/kroki
|
|
170
193
|
|
|
171
194
|
plantuml::spec/fixtures/alice.puml[png,role=sequence]
|
|
172
195
|
ADOC
|
|
173
|
-
output = Asciidoctor.convert(input, attributes: { 'kroki-fetch-diagram' => '' }, standalone: false, safe: :safe)
|
|
196
|
+
output = Asciidoctor.convert(input, attributes: { 'kroki-fetch-diagram' => '', 'kroki-server-url' => kroki_server_url }, standalone: false, safe: :safe)
|
|
197
|
+
diagram_hash = Digest::SHA256.hexdigest("#{kroki_server_url}/plantuml/png/eNpLzMlMTlXQtVNIyk-yUshIzcnJ5wIAQ-AGVQ==")
|
|
174
198
|
(expect output).to eql %(<div class="imageblock sequence kroki-format-png kroki">
|
|
175
199
|
<div class="content">
|
|
176
|
-
<img src=".asciidoctor/kroki/diag
|
|
200
|
+
<img src=".asciidoctor/kroki/diag-#{diagram_hash}.png" alt="Diagram">
|
|
177
201
|
</div>
|
|
178
202
|
</div>)
|
|
179
203
|
end
|
|
@@ -194,7 +218,7 @@ end
|
|
|
194
218
|
describe AsciidoctorExtensions::Kroki do
|
|
195
219
|
it 'should return the list of supported diagrams' do
|
|
196
220
|
diagram_names = AsciidoctorExtensions::Kroki::SUPPORTED_DIAGRAM_NAMES
|
|
197
|
-
expect(diagram_names).to include('vegalite', 'plantuml', 'bytefield', 'bpmn', 'excalidraw', 'wavedrom', 'pikchr', 'structurizr', 'diagramsnet')
|
|
221
|
+
expect(diagram_names).to include('vegalite', 'plantuml', 'bytefield', 'bpmn', 'excalidraw', 'wavedrom', 'pikchr', 'structurizr', 'diagramsnet', 'goat', 'lini')
|
|
198
222
|
end
|
|
199
223
|
it 'should register the extension for the list of supported diagrams' do
|
|
200
224
|
doc = Asciidoctor::Document.new
|
data/spec/rspec_helper.rb
CHANGED
|
@@ -1,10 +1,47 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'testcontainers'
|
|
4
|
+
|
|
5
|
+
# Kroki server used by the specs tagged with `kroki_server: true`, started once on first use.
|
|
6
|
+
# The image version is pinned in .kroki-version, so that an upgrade of kroki.io can't break the specs.
|
|
7
|
+
module KrokiServer
|
|
8
|
+
IMAGE = "yuzutech/kroki:#{File.read(File.expand_path('../../.kroki-version', __dir__)).strip}"
|
|
9
|
+
|
|
10
|
+
class << self
|
|
11
|
+
def url
|
|
12
|
+
@url ||= begin
|
|
13
|
+
@container = Testcontainers::DockerContainer.new(IMAGE).with_exposed_port(8000)
|
|
14
|
+
@container.start
|
|
15
|
+
@container.wait_for_http(path: '/health', container_port: 8000)
|
|
16
|
+
"http://#{@container.host}:#{@container.mapped_port(8000)}"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def stop
|
|
21
|
+
# @url is only set once the container is started
|
|
22
|
+
return unless @url
|
|
23
|
+
|
|
24
|
+
@container.stop
|
|
25
|
+
@container.remove
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
module Helper
|
|
30
|
+
def kroki_server_url
|
|
31
|
+
KrokiServer.url
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
3
36
|
RSpec.configure do |config|
|
|
37
|
+
# Linux containers are not available on Windows CI runners (same as the JavaScript test suite).
|
|
38
|
+
config.filter_run_excluding kroki_server: true if Gem.win_platform?
|
|
39
|
+
config.include KrokiServer::Helper, kroki_server: true
|
|
4
40
|
config.before(:suite) do
|
|
5
|
-
FileUtils.rm(Dir.glob("#{__dir__}/../.asciidoctor/kroki/diag-*"))
|
|
41
|
+
FileUtils.rm(Dir.glob("#{__dir__}/../.asciidoctor/kroki/{diag-*,hello-world-*}"))
|
|
6
42
|
end
|
|
7
43
|
config.after(:suite) do
|
|
8
|
-
FileUtils.rm(Dir.glob("#{__dir__}/../.asciidoctor/kroki/diag-*")) unless ENV['DEBUG']
|
|
44
|
+
FileUtils.rm(Dir.glob("#{__dir__}/../.asciidoctor/kroki/{diag-*,hello-world-*}")) unless ENV['DEBUG']
|
|
45
|
+
KrokiServer.stop
|
|
9
46
|
end
|
|
10
47
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: asciidoctor-kroki
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.19.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Guillaume Grossetie
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: asciidoctor
|
|
@@ -66,6 +65,20 @@ dependencies:
|
|
|
66
65
|
- - "~>"
|
|
67
66
|
- !ruby/object:Gem::Version
|
|
68
67
|
version: '1.78'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: testcontainers-core
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: 0.2.0
|
|
75
|
+
type: :development
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: 0.2.0
|
|
69
82
|
description: An extension for Asciidoctor to convert diagrams to images using https://kroki.io
|
|
70
83
|
email:
|
|
71
84
|
- ggrossetie@yuzutech.fr
|
|
@@ -107,7 +120,6 @@ metadata:
|
|
|
107
120
|
bug_tracker_uri: https://github.com/ggrossetie/asciidoctor-kroki/issues
|
|
108
121
|
source_code_uri: https://github.com/ggrossetie/asciidoctor-kroki
|
|
109
122
|
rubygems_mfa_required: 'true'
|
|
110
|
-
post_install_message:
|
|
111
123
|
rdoc_options: []
|
|
112
124
|
require_paths:
|
|
113
125
|
- lib
|
|
@@ -122,8 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
122
134
|
- !ruby/object:Gem::Version
|
|
123
135
|
version: '0'
|
|
124
136
|
requirements: []
|
|
125
|
-
rubygems_version: 3.
|
|
126
|
-
signing_key:
|
|
137
|
+
rubygems_version: 3.6.9
|
|
127
138
|
specification_version: 4
|
|
128
139
|
summary: Asciidoctor extension to convert diagrams to images using Kroki
|
|
129
140
|
test_files: []
|