asciidoctor-kroki 0.1.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17489df3a1c86ebd143ad0d0b842be3da6dbe90971146787b7de481c304c080d
4
- data.tar.gz: 5f2e38eba631ca800d84538da25dffe91834d7baaaae0080da6bf5328a8ab400
3
+ metadata.gz: c68a706bac6918c95daef5ada0de0d6a8471cbd69cc83ced875119ca69b90f58
4
+ data.tar.gz: c2683ddf3c70e743faff32a73442ef651fd17145191148e4a5930ac7d16852f9
5
5
  SHA512:
6
- metadata.gz: dcb1e59a258bb4edd067fbc51f8cac8a80cf6d047fffb37e4a6504ffcf6f650c4ad84b86fd52c98899061c52cf5eb409009a469021ccbdb6bbf3b28797671602
7
- data.tar.gz: 199d312c09ccb73f91019fe2603bc0085ad18b01e24b631c7a8e6c8de27c8cfcd3a788e1d8cf2897302f5ba83667a426264aedb61e8fa5d8901d285c70ae249c
6
+ metadata.gz: 45ea1d0252ebfab9fc9dfba56b13a3497ddf1e5ca58cb05777c941829ec2316f0f194a87bef490483c800d43cd7cf0e008804cb4f92ad4955cc864203ad26dfb
7
+ data.tar.gz: 3fec5d036175f848b0fa26df6c47439ee2f61a776393c097ecb0e79e0f407939e99df233bb1461360feaf4aae4224377aadff7bbc9d93ffa6fad6af62f7fc40e
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  pkg/
2
+ .asciidoctor/kroki
@@ -8,7 +8,10 @@ Metrics/MethodLength:
8
8
  Max: 50
9
9
 
10
10
  Metrics/CyclomaticComplexity:
11
- Max : 10
11
+ Max: 10
12
+
13
+ Metrics/PerceivedComplexity:
14
+ Max: 10
12
15
 
13
16
  Metrics/AbcSize:
14
- Max: 25
17
+ Max: 30
@@ -1,62 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- asciidoctor-kroki (0.1.1)
4
+ asciidoctor-kroki (0.3.0)
5
5
  asciidoctor (~> 2.0)
6
- asciidoctor-pdf (= 1.5.3)
7
6
 
8
7
  GEM
9
8
  remote: https://rubygems.org/
10
9
  specs:
11
- Ascii85 (1.0.3)
12
- addressable (2.7.0)
13
- public_suffix (>= 2.0.2, < 5.0)
14
- afm (0.2.2)
15
10
  asciidoctor (2.0.10)
16
- asciidoctor-pdf (1.5.3)
17
- asciidoctor (>= 1.5.3, < 3.0.0)
18
- concurrent-ruby (~> 1.1.0)
19
- prawn (~> 2.2.0)
20
- prawn-icon (~> 2.5.0)
21
- prawn-svg (~> 0.30.0)
22
- prawn-table (~> 0.2.0)
23
- prawn-templates (~> 0.1.0)
24
- safe_yaml (~> 1.0.0)
25
- thread_safe (~> 0.3.0)
26
- treetop (~> 1.6.0)
27
- ttfunk (~> 1.5.0, >= 1.5.1)
28
11
  ast (2.4.1)
29
- concurrent-ruby (1.1.6)
30
- css_parser (1.7.1)
31
- addressable
32
12
  diff-lcs (1.3)
33
- hashery (2.1.2)
34
13
  jaro_winkler (1.5.4)
35
14
  parallel (1.19.1)
36
15
  parser (2.7.1.3)
37
16
  ast (~> 2.4.0)
38
- pdf-core (0.7.0)
39
- pdf-reader (2.4.0)
40
- Ascii85 (~> 1.0.0)
41
- afm (~> 0.2.1)
42
- hashery (~> 2.0)
43
- ruby-rc4
44
- ttfunk
45
- polyglot (0.3.5)
46
- prawn (2.2.2)
47
- pdf-core (~> 0.7.0)
48
- ttfunk (~> 1.5)
49
- prawn-icon (2.5.0)
50
- prawn (>= 1.1.0, < 3.0.0)
51
- prawn-svg (0.30.0)
52
- css_parser (~> 1.6)
53
- prawn (>= 0.11.1, < 3)
54
- prawn-table (0.2.2)
55
- prawn (>= 1.3.0, < 3.0.0)
56
- prawn-templates (0.1.2)
57
- pdf-reader (~> 2.0)
58
- prawn (~> 2.2)
59
- public_suffix (4.0.5)
60
17
  rainbow (3.0.0)
61
18
  rake (12.3.3)
62
19
  rspec (3.8.0)
@@ -80,12 +37,6 @@ GEM
80
37
  ruby-progressbar (~> 1.7)
81
38
  unicode-display_width (>= 1.4.0, < 1.7)
82
39
  ruby-progressbar (1.10.1)
83
- ruby-rc4 (0.1.5)
84
- safe_yaml (1.0.5)
85
- thread_safe (0.3.6)
86
- treetop (1.6.10)
87
- polyglot (~> 0.3)
88
- ttfunk (1.5.1)
89
40
  unicode-display_width (1.6.1)
90
41
 
91
42
  PLATFORMS
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'asciidoctor-kroki'
5
- s.version = '0.1.1'
5
+ s.version = '0.3.0'
6
6
  s.summary = 'Asciidoctor extension to convert diagrams to images using Kroki'
7
7
  s.description = 'An extension for Asciidoctor to convert diagrams to images using https://kroki.io'
8
8
 
@@ -19,7 +19,6 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ['lib']
20
20
 
21
21
  s.add_runtime_dependency 'asciidoctor', '~> 2.0'
22
- s.add_runtime_dependency 'asciidoctor-pdf', '1.5.3'
23
22
 
24
23
  s.add_development_dependency 'rake', '~> 12.3.2'
25
24
  s.add_development_dependency 'rspec', '~> 3.8.0'
@@ -0,0 +1,5 @@
1
+ # rubocop:disable Naming/FileName
2
+ # rubocop:enable Naming/FileName
3
+ # frozen_string_literal: true
4
+
5
+ require_relative 'asciidoctor/extensions/asciidoctor_kroki'
@@ -4,8 +4,7 @@ require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
4
4
  require_relative 'asciidoctor_kroki/extension'
5
5
 
6
6
  Asciidoctor::Extensions.register do
7
- names = %w[plantuml ditaa graphviz blockdiag seqdiag actdiag nwdiag packetdiag rackdiag c4plantuml erd mermaid nomnoml svgbob umlet vega vegalite wavedrom]
8
- names.each do |name|
7
+ ::AsciidoctorExtensions::Kroki::SUPPORTED_DIAGRAM_NAMES.each do |name|
9
8
  block_macro ::AsciidoctorExtensions::KrokiBlockMacroProcessor, name
10
9
  block ::AsciidoctorExtensions::KrokiBlockProcessor, name
11
10
  end
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
4
- require 'stringio'
5
- require 'zlib'
6
4
 
7
5
  # Asciidoctor extensions
8
6
  #
@@ -29,9 +27,11 @@ module AsciidoctorExtensions
29
27
  class KrokiBlockMacroProcessor < Asciidoctor::Extensions::BlockMacroProcessor
30
28
  use_dsl
31
29
 
30
+ name_positional_attributes 'format'
31
+
32
32
  def process(parent, target, attrs)
33
33
  diagram_type = @name
34
- target = parent.apply_subs(target, ['attributes'])
34
+ target = parent.apply_subs(target, [:attributes])
35
35
  diagram_text = read(target)
36
36
  KrokiProcessor.process(self, parent, attrs, diagram_type, diagram_text)
37
37
  end
@@ -46,9 +46,39 @@ module AsciidoctorExtensions
46
46
  end
47
47
  end
48
48
 
49
+ # Kroki API
50
+ #
51
+ module Kroki
52
+ SUPPORTED_DIAGRAM_NAMES = %w[
53
+ actdiag
54
+ blockdiag
55
+ bpmn
56
+ bytefield
57
+ c4plantuml
58
+ ditaa
59
+ erd
60
+ excalidraw
61
+ graphviz
62
+ mermaid
63
+ nomnoml
64
+ nwdiag
65
+ packetdiag
66
+ plantuml
67
+ rackdiag
68
+ seqdiag
69
+ svgbob
70
+ umlet
71
+ vega
72
+ vegalite
73
+ wavedrow
74
+ ].freeze
75
+ end
76
+
49
77
  # Internal processor
50
78
  #
51
79
  class KrokiProcessor
80
+ TEXT_FORMATS = %w[txt atxt utxt].freeze
81
+
52
82
  class << self
53
83
  def process(processor, parent, attrs, diagram_type, diagram_text)
54
84
  doc = parent.document
@@ -64,11 +94,18 @@ module AsciidoctorExtensions
64
94
  role = attrs['role']
65
95
  format = get_format(doc, attrs, diagram_type)
66
96
  attrs['role'] = get_role(format, role)
67
- attrs['alt'] = get_alt(attrs)
68
- attrs['target'] = create_image_src(doc, diagram_type, format, diagram_text)
69
97
  attrs['format'] = format
70
- block = processor.create_image_block(parent, attrs)
71
- block.title = title
98
+ kroki_diagram = KrokiDiagram.new(diagram_type, format, diagram_text)
99
+ kroki_client = KrokiClient.new(server_url(doc), http_method(doc), KrokiHttpClient)
100
+ if TEXT_FORMATS.include?(format)
101
+ text_content = kroki_client.text_content(kroki_diagram)
102
+ block = processor.create_block(parent, 'literal', text_content, attrs)
103
+ else
104
+ attrs['alt'] = get_alt(attrs)
105
+ attrs['target'] = create_image_src(doc, kroki_diagram, kroki_client)
106
+ block = processor.create_image_block(parent, attrs)
107
+ end
108
+ block.title = title if title
72
109
  block.assign_caption(caption, 'figure')
73
110
  block
74
111
  end
@@ -119,13 +156,168 @@ module AsciidoctorExtensions
119
156
  format
120
157
  end
121
158
 
122
- def create_image_src(doc, type, format, text)
123
- data = Base64.urlsafe_encode64(Zlib::Deflate.deflate(text, 9))
124
- "#{server_url(doc)}/#{type}/#{format}/#{data}"
159
+ def create_image_src(doc, kroki_diagram, kroki_client)
160
+ if doc.attr('kroki-fetch-diagram')
161
+ kroki_diagram.save(output_dir_path(doc), kroki_client)
162
+ else
163
+ kroki_diagram.get_diagram_uri(server_url(doc))
164
+ end
125
165
  end
126
166
 
127
167
  def server_url(doc)
128
- doc.attr('kroki-server-url') || 'https://kroki.io'
168
+ doc.attr('kroki-server-url', 'https://kroki.io')
169
+ end
170
+
171
+ def http_method(doc)
172
+ doc.attr('kroki-http-method', 'adaptive').downcase
173
+ end
174
+
175
+ def output_dir_path(doc)
176
+ images_output_dir = doc.attr('imagesoutdir')
177
+ out_dir = doc.attr('outdir')
178
+ to_dir = doc.attr('to_dir')
179
+ base_dir = doc.base_dir
180
+ images_dir = doc.attr('imagesdir', '')
181
+ if images_output_dir
182
+ images_output_dir
183
+ elsif out_dir
184
+ File.join(out_dir, images_dir)
185
+ elsif to_dir
186
+ File.join(to_dir, images_dir)
187
+ else
188
+ File.join(base_dir, images_dir)
189
+ end
190
+ end
191
+ end
192
+ end
193
+
194
+ # Kroki diagram
195
+ #
196
+ class KrokiDiagram
197
+ require 'fileutils'
198
+ require 'zlib'
199
+ require 'digest'
200
+
201
+ attr_reader :type
202
+ attr_reader :text
203
+ attr_reader :format
204
+
205
+ def initialize(type, format, text)
206
+ @text = text
207
+ @type = type
208
+ @format = format
209
+ end
210
+
211
+ def get_diagram_uri(server_url)
212
+ _join_uri_segments(server_url, @type, @format, encode)
213
+ end
214
+
215
+ def encode
216
+ Base64.urlsafe_encode64(Zlib::Deflate.deflate(@text, 9))
217
+ end
218
+
219
+ def save(output_dir_path, kroki_client)
220
+ diagram_url = get_diagram_uri(kroki_client.server_url)
221
+ diagram_name = "diag-#{Digest::SHA256.hexdigest diagram_url}.#{@format}"
222
+ file_path = File.join(output_dir_path, diagram_name)
223
+ encoding = if @format == 'txt' || @format == 'atxt' || @format == 'utxt'
224
+ 'utf8'
225
+ elsif @format == 'svg'
226
+ 'binary'
227
+ else
228
+ 'binary'
229
+ end
230
+ # file is either (already) on the file system or we should read it from Kroki
231
+ contents = File.exist?(file_path) ? File.open(file_path, &:read) : kroki_client.get_image(self, encoding)
232
+ FileUtils.mkdir_p(output_dir_path)
233
+ if encoding == 'binary'
234
+ File.binwrite(file_path, contents)
235
+ else
236
+ File.write(file_path, contents)
237
+ end
238
+ diagram_name
239
+ end
240
+
241
+ private
242
+
243
+ def _join_uri_segments(base, *uris)
244
+ segments = []
245
+ # remove trailing slashes
246
+ segments.push(base.gsub(%r{[/]+$}, ''))
247
+ segments.concat(uris.map do |uri|
248
+ # remove leading and trailing slashes
249
+ uri.to_s
250
+ .gsub(%r{^[/]+}, '')
251
+ .gsub(%r{[/]+$}, '')
252
+ end)
253
+ segments.join('/')
254
+ end
255
+ end
256
+
257
+ # Kroki client
258
+ #
259
+ class KrokiClient
260
+ attr_reader :server_url
261
+ attr_reader :method
262
+
263
+ SUPPORTED_HTTP_METHODS = %w[get post adaptive].freeze
264
+
265
+ def initialize(server_url, http_method, http_client)
266
+ @server_url = server_url
267
+ @max_uri_length = 4096
268
+ @http_client = http_client
269
+ method = (http_method || 'adaptive').downcase
270
+ if SUPPORTED_HTTP_METHODS.include?(method)
271
+ @method = method
272
+ else
273
+ puts "Invalid value '#{method}' for kroki-http-method attribute. The value must be either: 'get', 'post' or 'adaptive'. Proceeding using: 'adaptive'."
274
+ @method = 'adaptive'
275
+ end
276
+ end
277
+
278
+ def text_content(kroki_diagram)
279
+ get_image(kroki_diagram, 'utf-8')
280
+ end
281
+
282
+ def get_image(kroki_diagram, encoding)
283
+ type = kroki_diagram.type
284
+ format = kroki_diagram.format
285
+ text = kroki_diagram.text
286
+ if @method == 'adaptive' || @method == 'get'
287
+ uri = kroki_diagram.get_diagram_uri(server_url)
288
+ if uri.length > @max_uri_length
289
+ # The request URI is longer than 4096.
290
+ if @method == 'get'
291
+ # The request might be rejected by the server with a 414 Request-URI Too Large.
292
+ # Consider using the attribute kroki-http-method with the value 'adaptive'.
293
+ @http_client.get(uri, encoding)
294
+ else
295
+ @http_client.post("#{@server_url}/#{type}/#{format}", text, encoding)
296
+ end
297
+ else
298
+ @http_client.get(uri, encoding)
299
+ end
300
+ else
301
+ @http_client.post("#{@server_url}/#{type}/#{format}", text, encoding)
302
+ end
303
+ end
304
+ end
305
+
306
+ # Kroki HTTP client
307
+ #
308
+ class KrokiHttpClient
309
+ require 'net/http'
310
+ require 'uri'
311
+ require 'json'
312
+
313
+ class << self
314
+ def get(uri, _)
315
+ ::OpenURI.open_uri(uri, 'r', &:read)
316
+ end
317
+
318
+ def post(uri, data, _)
319
+ res = ::Net::HTTP.request_post(uri, data)
320
+ res.body
129
321
  end
130
322
  end
131
323
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec_helper'
4
+ require 'asciidoctor'
5
+ require_relative '../lib/asciidoctor/extensions/asciidoctor_kroki'
6
+
7
+ describe ::AsciidoctorExtensions::KrokiClient do
8
+ it 'should use adaptive method when http method is invalid' do
9
+ kroki_http_client = ::AsciidoctorExtensions::KrokiHttpClient
10
+ kroki_client = ::AsciidoctorExtensions::KrokiClient.new('http://localhost:8000', 'patch', kroki_http_client)
11
+ expect(kroki_client.method).to eq('adaptive')
12
+ end
13
+ it 'should use post method when http method is post' do
14
+ kroki_http_client = ::AsciidoctorExtensions::KrokiHttpClient
15
+ kroki_client = ::AsciidoctorExtensions::KrokiClient.new('http://localhost:8000', 'POST', kroki_http_client)
16
+ expect(kroki_client.method).to eq('post')
17
+ end
18
+ it 'should use get method when http method is get' do
19
+ kroki_http_client = ::AsciidoctorExtensions::KrokiHttpClient
20
+ kroki_client = ::AsciidoctorExtensions::KrokiClient.new('http://localhost:8000', 'get', kroki_http_client)
21
+ expect(kroki_client.method).to eq('get')
22
+ end
23
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec_helper'
4
+ require 'asciidoctor'
5
+ require_relative '../lib/asciidoctor/extensions/asciidoctor_kroki'
6
+
7
+ describe ::AsciidoctorExtensions::KrokiDiagram do
8
+ it 'should compute a diagram URI' do
9
+ kroki_diagram = ::AsciidoctorExtensions::KrokiDiagram.new('vegalite', 'png', '{}')
10
+ diagram_uri = kroki_diagram.get_diagram_uri('http://localhost:8000')
11
+ expect(diagram_uri).to eq('http://localhost:8000/vegalite/png/eNqrrgUAAXUA-Q==')
12
+ end
13
+ it 'should compute a diagram URI with a trailing slashes' do
14
+ kroki_diagram = ::AsciidoctorExtensions::KrokiDiagram.new('vegalite', 'png', '{}')
15
+ diagram_uri = kroki_diagram.get_diagram_uri('https://my.domain.org/kroki/')
16
+ expect(diagram_uri).to eq('https://my.domain.org/kroki/vegalite/png/eNqrrgUAAXUA-Q==')
17
+ end
18
+ it 'should compute a diagram URI with trailing slashes' do
19
+ kroki_diagram = ::AsciidoctorExtensions::KrokiDiagram.new('vegalite', 'png', '{}')
20
+ diagram_uri = kroki_diagram.get_diagram_uri('https://my-server/kroki//')
21
+ expect(diagram_uri).to eq('https://my-server/kroki/vegalite/png/eNqrrgUAAXUA-Q==')
22
+ end
23
+ it 'should encode a diagram text definition' do
24
+ kroki_diagram = ::AsciidoctorExtensions::KrokiDiagram.new('plantuml', 'txt', ' alice -> bob: hello')
25
+ diagram_definition_encoded = kroki_diagram.encode
26
+ expect(diagram_definition_encoded).to eq('eNpTSMzJTE5V0LVTSMpPslLISM3JyQcAQAwGaw==')
27
+ end
28
+ it 'should fetch a diagram from Kroki and save it to disk' do
29
+ kroki_diagram = ::AsciidoctorExtensions::KrokiDiagram.new('plantuml', 'txt', ' alice -> bob: hello')
30
+ kroki_http_client = ::AsciidoctorExtensions::KrokiHttpClient
31
+ kroki_client = ::AsciidoctorExtensions::KrokiClient.new('https://kroki.io', 'get', kroki_http_client)
32
+ output_dir_path = "#{__dir__}/../.asciidoctor/kroki"
33
+ diagram_name = kroki_diagram.save(output_dir_path, kroki_client)
34
+ diagram_path = File.join(output_dir_path, diagram_name)
35
+ expect(File.exist?(diagram_path)).to be_truthy, "expected diagram to be saved at #{diagram_path}"
36
+ content = <<-TXT.chomp
37
+ ,-----. ,---.
38
+ |alice| |bob|
39
+ `--+--' `-+-'
40
+ | hello |
41
+ |-------------->|
42
+ ,--+--. ,-+-.
43
+ |alice| |bob|
44
+ `-----' `---'
45
+ TXT
46
+ expect(File.read(diagram_path).split("\n").map(&:rstrip).join("\n")).to eq(content)
47
+ end
48
+ it 'should fetch a diagram from Kroki with the same definition only once' do
49
+ kroki_diagram = ::AsciidoctorExtensions::KrokiDiagram.new('plantuml', 'png', ' guillaume -> dan: hello')
50
+ kroki_http_client = ::AsciidoctorExtensions::KrokiHttpClient
51
+ kroki_client = ::AsciidoctorExtensions::KrokiClient.new('https://kroki.io', 'get', kroki_http_client)
52
+ output_dir_path = "#{__dir__}/../.asciidoctor/kroki"
53
+ # make sure that we are doing only one GET request
54
+ expect(kroki_http_client).to receive(:get).once
55
+ diagram_name = kroki_diagram.save(output_dir_path, kroki_client)
56
+ diagram_path = File.join(output_dir_path, diagram_name)
57
+ expect(File.exist?(diagram_path)).to be_truthy, "expected diagram to be saved at #{diagram_path}"
58
+ # calling again... should read the file from disk (and not do a GET request)
59
+ kroki_diagram.save(output_dir_path, kroki_client)
60
+ end
61
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rspec_helper'
3
4
  require 'asciidoctor'
4
5
  require_relative '../lib/asciidoctor/extensions/asciidoctor_kroki'
5
6
 
@@ -47,5 +48,47 @@ describe ::AsciidoctorExtensions::KrokiBlockProcessor do
47
48
  </div>
48
49
  </div>)
49
50
  end
51
+ it 'should create SVG diagram in imagesdir if kroki-fetch-diagram is set' do
52
+ input = <<~'ADOC'
53
+ :imagesdir: .asciidoctor/kroki
54
+
55
+ plantuml::spec/fixtures/alice.puml[svg,role=sequence]
56
+ ADOC
57
+ output = Asciidoctor.convert(input, attributes: { 'kroki-fetch-diagram' => '' }, standalone: false)
58
+ (expect output).to eql %(<div class="imageblock sequence kroki-format-svg kroki">
59
+ <div class="content">
60
+ <img src=".asciidoctor/kroki/diag-f6acdc206506b6ca7badd3fe722f252af992871426e580c8361ff4d47c2c7d9b.svg" alt="Diagram">
61
+ </div>
62
+ </div>)
63
+ end
64
+ it 'should create PNG diagram in imagesdir if kroki-fetch-diagram is set' do
65
+ input = <<~'ADOC'
66
+ :imagesdir: .asciidoctor/kroki
67
+
68
+ plantuml::spec/fixtures/alice.puml[png,role=sequence]
69
+ ADOC
70
+ output = Asciidoctor.convert(input, attributes: { 'kroki-fetch-diagram' => '' }, standalone: false)
71
+ (expect output).to eql %(<div class="imageblock sequence kroki-format-png kroki">
72
+ <div class="content">
73
+ <img src=".asciidoctor/kroki/diag-d4f314b2d4e75cc08aa4f8c2c944f7bf78321895d8ec5f665b42476d4e67e610.png" alt="Diagram">
74
+ </div>
75
+ </div>)
76
+ end
77
+ end
78
+ end
79
+
80
+ describe ::AsciidoctorExtensions::Kroki do
81
+ it 'should return the list of supported diagrams' do
82
+ diagram_names = ::AsciidoctorExtensions::Kroki::SUPPORTED_DIAGRAM_NAMES
83
+ expect(diagram_names).to include('vegalite', 'plantuml', 'bytefield', 'bpmn', 'excalidraw')
84
+ end
85
+ it 'should register the extension for the list of supported diagrams' do
86
+ doc = Asciidoctor::Document.new
87
+ registry = Asciidoctor::Extensions::Registry.new
88
+ registry.activate doc
89
+ ::AsciidoctorExtensions::Kroki::SUPPORTED_DIAGRAM_NAMES.each do |name|
90
+ expect(registry.find_block_extension(name)).to_not be_nil, "expected block extension named '#{name}' to be registered"
91
+ expect(registry.find_block_macro_extension(name)).to_not be_nil, "expected block macro extension named '#{name}' to be registered "
92
+ end
50
93
  end
51
94
  end
@@ -0,0 +1 @@
1
+ alice -> bob: hello
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe 'require' do
4
+ it 'should require the library' do
5
+ lib = File.expand_path('lib', __dir__)
6
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
+ require 'asciidoctor-kroki'
8
+
9
+ (expect Asciidoctor::Extensions.groups[:extgrp0]).to_not be_nil
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.configure do |config|
4
+ config.before(:suite) do
5
+ FileUtils.rm(Dir.glob("#{__dir__}/../.asciidoctor/kroki/diag-*"))
6
+ end
7
+ config.after(:suite) do
8
+ FileUtils.rm(Dir.glob("#{__dir__}/../.asciidoctor/kroki/diag-*")) unless ENV['DEBUG']
9
+ end
10
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-kroki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Grossetie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-13 00:00:00.000000000 Z
11
+ date: 2021-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
- - !ruby/object:Gem::Dependency
28
- name: asciidoctor-pdf
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '='
32
- - !ruby/object:Gem::Version
33
- version: 1.5.3
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '='
39
- - !ruby/object:Gem::Version
40
- version: 1.5.3
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -87,6 +73,7 @@ executables: []
87
73
  extensions: []
88
74
  extra_rdoc_files: []
89
75
  files:
76
+ - ".asciidoctor/kroki/.gitkeep"
90
77
  - ".gitignore"
91
78
  - ".rubocop.yml"
92
79
  - ".ruby-version"
@@ -94,11 +81,17 @@ files:
94
81
  - Gemfile.lock
95
82
  - Rakefile
96
83
  - asciidoctor-kroki.gemspec
84
+ - lib/asciidoctor-kroki.rb
97
85
  - lib/asciidoctor/extensions/asciidoctor_kroki.rb
98
86
  - lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb
99
87
  - spec/.rubocop.yml
88
+ - spec/asciidoctor_kroki_client_spec.rb
89
+ - spec/asciidoctor_kroki_diagram_spec.rb
100
90
  - spec/asciidoctor_kroki_spec.rb
91
+ - spec/fixtures/alice.puml
101
92
  - spec/fixtures/config.puml
93
+ - spec/require_spec.rb
94
+ - spec/rspec_helper.rb
102
95
  - tasks/bundler.rake
103
96
  - tasks/lint.rake
104
97
  - tasks/rspec.rake
@@ -129,8 +122,13 @@ specification_version: 4
129
122
  summary: Asciidoctor extension to convert diagrams to images using Kroki
130
123
  test_files:
131
124
  - spec/.rubocop.yml
125
+ - spec/asciidoctor_kroki_client_spec.rb
126
+ - spec/asciidoctor_kroki_diagram_spec.rb
132
127
  - spec/asciidoctor_kroki_spec.rb
128
+ - spec/fixtures/alice.puml
133
129
  - spec/fixtures/config.puml
130
+ - spec/require_spec.rb
131
+ - spec/rspec_helper.rb
134
132
  - tasks/bundler.rake
135
133
  - tasks/lint.rake
136
134
  - tasks/rspec.rake