asciidoctor-kroki 0.1.0 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c9c6ddeb0a82d775506971be5d140b80f3b06a0799a740430c109e7718312f4
4
- data.tar.gz: 9f354c2a63e2426e40471ba6db010088e14163bc0a7bcd3cb3e9693a70685521
3
+ metadata.gz: 21f55b23e0184ad4f0555a2c51ecf039239d31a12b18ff4437722b76aa85ec0a
4
+ data.tar.gz: ad49ab9972baa23a093320fa0f5630b07d23d4e429cf8d928d2dc02b7ebb6473
5
5
  SHA512:
6
- metadata.gz: fde22365b6ce1ac9379bfefd955324b07ada0dbc3bc51e8edc90efce696c15bb1142068819d2ad56cedcf1315290d22451fe36d1caf10d891384d98bf9ca0e91
7
- data.tar.gz: 2b1906da6dea90f743e104cfd0cb279f3b469b08c8ed791e9e39e10c0945568b60cdd2a2d374e45636847ccb04282d9391d804138ed7a57683af55ce4c874978
6
+ metadata.gz: ac44b98b38d54189f6c71c83d3c747c991284f99ff54833a44d2c56c42b3b626ddf9e43be22f298321828084851dfe2c68ceea4951853b58ce1ebdf183a90ccb
7
+ data.tar.gz: 87f3181f4e87f5555c7765cb98b33ab1c561f87d3887039f1990eb874c706ff894b2b660cfc350e31bf3f4770f2673096340ccbab09a452806d51a63b69094b2
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.0)
4
+ asciidoctor-kroki (0.2.2)
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.0'
5
+ s.version = '0.2.2'
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,38 @@ module AsciidoctorExtensions
46
46
  end
47
47
  end
48
48
 
49
+ # Kroki API
50
+ #
51
+ module Kroki
52
+ SUPPORTED_DIAGRAM_NAMES = %w[
53
+ plantuml
54
+ ditaa
55
+ graphviz
56
+ blockdiag
57
+ seqdiag
58
+ actdiag
59
+ nwdiag
60
+ packetdiag
61
+ rackdiag
62
+ c4plantuml
63
+ erd
64
+ mermaid
65
+ nomnoml
66
+ svgbob
67
+ umlet
68
+ vega
69
+ vegalite
70
+ wavedrom
71
+ bytefield
72
+ bpmn
73
+ ].freeze
74
+ end
75
+
49
76
  # Internal processor
50
77
  #
51
78
  class KrokiProcessor
79
+ TEXT_FORMATS = %w[txt atxt utxt].freeze
80
+
52
81
  class << self
53
82
  def process(processor, parent, attrs, diagram_type, diagram_text)
54
83
  doc = parent.document
@@ -64,11 +93,18 @@ module AsciidoctorExtensions
64
93
  role = attrs['role']
65
94
  format = get_format(doc, attrs, diagram_type)
66
95
  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
96
  attrs['format'] = format
70
- block = processor.create_image_block(parent, attrs)
71
- block.title = title
97
+ kroki_diagram = KrokiDiagram.new(diagram_type, format, diagram_text)
98
+ kroki_client = KrokiClient.new(server_url(doc), http_method(doc), KrokiHttpClient)
99
+ if TEXT_FORMATS.include?(format)
100
+ text_content = kroki_client.text_content(kroki_diagram)
101
+ block = processor.create_block(parent, 'literal', text_content, attrs)
102
+ else
103
+ attrs['alt'] = get_alt(attrs)
104
+ attrs['target'] = create_image_src(doc, kroki_diagram, kroki_client)
105
+ block = processor.create_image_block(parent, attrs)
106
+ end
107
+ block.title = title if title
72
108
  block.assign_caption(caption, 'figure')
73
109
  block
74
110
  end
@@ -119,13 +155,168 @@ module AsciidoctorExtensions
119
155
  format
120
156
  end
121
157
 
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}"
158
+ def create_image_src(doc, kroki_diagram, kroki_client)
159
+ if doc.attr('kroki-fetch-diagram')
160
+ kroki_diagram.save(output_dir_path(doc), kroki_client)
161
+ else
162
+ kroki_diagram.get_diagram_uri(server_url(doc))
163
+ end
125
164
  end
126
165
 
127
166
  def server_url(doc)
128
- doc.attr('kroki-server-url') || 'https://kroki.io'
167
+ doc.attr('kroki-server-url', 'https://kroki.io')
168
+ end
169
+
170
+ def http_method(doc)
171
+ doc.attr('kroki-http-method', 'adaptive').downcase
172
+ end
173
+
174
+ def output_dir_path(doc)
175
+ images_output_dir = doc.attr('imagesoutdir')
176
+ out_dir = doc.attr('outdir')
177
+ to_dir = doc.attr('to_dir')
178
+ base_dir = doc.base_dir
179
+ images_dir = doc.attr('imagesdir', '')
180
+ if images_output_dir
181
+ images_output_dir
182
+ elsif out_dir
183
+ File.join(out_dir, images_dir)
184
+ elsif to_dir
185
+ File.join(to_dir, images_dir)
186
+ else
187
+ File.join(base_dir, images_dir)
188
+ end
189
+ end
190
+ end
191
+ end
192
+
193
+ # Kroki diagram
194
+ #
195
+ class KrokiDiagram
196
+ require 'fileutils'
197
+ require 'zlib'
198
+ require 'digest'
199
+
200
+ attr_reader :type
201
+ attr_reader :text
202
+ attr_reader :format
203
+
204
+ def initialize(type, format, text)
205
+ @text = text
206
+ @type = type
207
+ @format = format
208
+ end
209
+
210
+ def get_diagram_uri(server_url)
211
+ _join_uri_segments(server_url, @type, @format, encode)
212
+ end
213
+
214
+ def encode
215
+ Base64.urlsafe_encode64(Zlib::Deflate.deflate(@text, 9))
216
+ end
217
+
218
+ def save(output_dir_path, kroki_client)
219
+ diagram_url = get_diagram_uri(kroki_client.server_url)
220
+ diagram_name = "diag-#{Digest::SHA256.hexdigest diagram_url}.#{@format}"
221
+ file_path = File.join(output_dir_path, diagram_name)
222
+ encoding = if @format == 'txt' || @format == 'atxt' || @format == 'utxt'
223
+ 'utf8'
224
+ elsif @format == 'svg'
225
+ 'binary'
226
+ else
227
+ 'binary'
228
+ end
229
+ # file is either (already) on the file system or we should read it from Kroki
230
+ contents = File.exist?(file_path) ? File.open(file_path, &:read) : kroki_client.get_image(self, encoding)
231
+ FileUtils.mkdir_p(output_dir_path)
232
+ if encoding == 'binary'
233
+ File.binwrite(file_path, contents)
234
+ else
235
+ File.write(file_path, contents)
236
+ end
237
+ diagram_name
238
+ end
239
+
240
+ private
241
+
242
+ def _join_uri_segments(base, *uris)
243
+ segments = []
244
+ # remove trailing slashes
245
+ segments.push(base.gsub(%r{[/]+$}, ''))
246
+ segments.concat(uris.map do |uri|
247
+ # remove leading and trailing slashes
248
+ uri.to_s
249
+ .gsub(%r{^[/]+}, '')
250
+ .gsub(%r{[/]+$}, '')
251
+ end)
252
+ segments.join('/')
253
+ end
254
+ end
255
+
256
+ # Kroki client
257
+ #
258
+ class KrokiClient
259
+ attr_reader :server_url
260
+ attr_reader :method
261
+
262
+ SUPPORTED_HTTP_METHODS = %w[get post adaptive].freeze
263
+
264
+ def initialize(server_url, http_method, http_client)
265
+ @server_url = server_url
266
+ @max_uri_length = 4096
267
+ @http_client = http_client
268
+ method = (http_method || 'adaptive').downcase
269
+ if SUPPORTED_HTTP_METHODS.include?(method)
270
+ @method = method
271
+ else
272
+ puts "Invalid value '#{method}' for kroki-http-method attribute. The value must be either: 'get', 'post' or 'adaptive'. Proceeding using: 'adaptive'."
273
+ @method = 'adaptive'
274
+ end
275
+ end
276
+
277
+ def text_content(kroki_diagram)
278
+ get_image(kroki_diagram, 'utf-8')
279
+ end
280
+
281
+ def get_image(kroki_diagram, encoding)
282
+ type = kroki_diagram.type
283
+ format = kroki_diagram.format
284
+ text = kroki_diagram.text
285
+ if @method == 'adaptive' || @method == 'get'
286
+ uri = kroki_diagram.get_diagram_uri(server_url)
287
+ if uri.length > @max_uri_length
288
+ # The request URI is longer than 4096.
289
+ if @method == 'get'
290
+ # The request might be rejected by the server with a 414 Request-URI Too Large.
291
+ # Consider using the attribute kroki-http-method with the value 'adaptive'.
292
+ @http_client.get(uri, encoding)
293
+ else
294
+ @http_client.post("#{@server_url}/#{type}/#{format}", text, encoding)
295
+ end
296
+ else
297
+ @http_client.get(uri, encoding)
298
+ end
299
+ else
300
+ @http_client.post("#{@server_url}/#{type}/#{format}", text, encoding)
301
+ end
302
+ end
303
+ end
304
+
305
+ # Kroki HTTP client
306
+ #
307
+ class KrokiHttpClient
308
+ require 'net/http'
309
+ require 'uri'
310
+ require 'json'
311
+
312
+ class << self
313
+ def get(uri, _)
314
+ ::OpenURI.open_uri(uri, 'r', &:read)
315
+ end
316
+
317
+ def post(uri, data, _)
318
+ res = ::Net::HTTP.request_post(uri, data)
319
+ res.body
129
320
  end
130
321
  end
131
322
  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')
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.0
4
+ version: 0.2.2
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: 2020-11-06 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