asciidoctor-kroki 0.4.0 → 0.7.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/.rubocop.yml +10 -2
- data/.ruby-version +1 -1
- data/Gemfile.lock +36 -31
- data/asciidoctor-kroki.gemspec +8 -6
- data/lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb +109 -66
- data/lib/asciidoctor/extensions/asciidoctor_kroki/version.rb +7 -0
- data/lib/asciidoctor/extensions/asciidoctor_kroki.rb +1 -0
- data/spec/asciidoctor_kroki_block_macro_spec.rb +4 -2
- data/spec/asciidoctor_kroki_client_spec.rb +16 -14
- data/spec/asciidoctor_kroki_diagram_spec.rb +46 -5
- data/spec/asciidoctor_kroki_processor_spec.rb +33 -0
- data/spec/asciidoctor_kroki_spec.rb +70 -11
- data/spec/fixtures/plantuml-diagram.png +0 -0
- metadata +14 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46f326afecfa57d4b918121fdf939c2c8dcf46897daeff74236a551628ffbfdf
|
4
|
+
data.tar.gz: c43629e9e6d4303fa59d761b61e95e6b63006cea1a27faf1dc3e80ceb9994f8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70eac4468da00da494aa490e3c413189feb13474d25aa778f1d0cb301957c7ce1811bbc82cc7d1e2782a43223452f5b1de75a150b446824c2de7f9380811defc
|
7
|
+
data.tar.gz: e9d6cbbdc63c8f28dd99c1921f1496765ccbb873210756c765d879d1311994243af42f55f3d4dc18e0500be299ef89d5027bbccf5afefee24255d65c71e829d4
|
data/.rubocop.yml
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.7
|
3
|
+
SuggestExtensions: false
|
4
|
+
NewCops: enable
|
5
|
+
|
1
6
|
Style/Encoding:
|
2
7
|
Enabled: false
|
3
8
|
|
4
9
|
Layout/EndOfLine:
|
5
10
|
EnforcedStyle: lf
|
6
11
|
|
7
|
-
|
12
|
+
Layout/LineLength:
|
8
13
|
Max: 180
|
9
14
|
|
10
15
|
Metrics/ClassLength:
|
@@ -20,7 +25,10 @@ Metrics/PerceivedComplexity:
|
|
20
25
|
Max: 10
|
21
26
|
|
22
27
|
Metrics/AbcSize:
|
23
|
-
Max:
|
28
|
+
Max: 31
|
24
29
|
|
25
30
|
Metrics/ParameterLists:
|
26
31
|
Max: 7
|
32
|
+
|
33
|
+
Gemspec/RequiredRubyVersion:
|
34
|
+
Enabled: false
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.1.2
|
data/Gemfile.lock
CHANGED
@@ -1,52 +1,57 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
asciidoctor-kroki (0.
|
4
|
+
asciidoctor-kroki (0.7.0)
|
5
5
|
asciidoctor (~> 2.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
asciidoctor (2.0.
|
11
|
-
ast (2.4.
|
12
|
-
diff-lcs (1.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
rspec-
|
22
|
-
rspec-
|
23
|
-
|
24
|
-
|
25
|
-
|
10
|
+
asciidoctor (2.0.17)
|
11
|
+
ast (2.4.2)
|
12
|
+
diff-lcs (1.4.4)
|
13
|
+
parallel (1.22.1)
|
14
|
+
parser (3.1.2.0)
|
15
|
+
ast (~> 2.4.1)
|
16
|
+
rainbow (3.1.1)
|
17
|
+
rake (13.0.6)
|
18
|
+
regexp_parser (2.5.0)
|
19
|
+
rexml (3.2.5)
|
20
|
+
rspec (3.10.0)
|
21
|
+
rspec-core (~> 3.10.0)
|
22
|
+
rspec-expectations (~> 3.10.0)
|
23
|
+
rspec-mocks (~> 3.10.0)
|
24
|
+
rspec-core (3.10.1)
|
25
|
+
rspec-support (~> 3.10.0)
|
26
|
+
rspec-expectations (3.10.1)
|
26
27
|
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
-
rspec-support (~> 3.
|
28
|
-
rspec-mocks (3.
|
28
|
+
rspec-support (~> 3.10.0)
|
29
|
+
rspec-mocks (3.10.2)
|
29
30
|
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
-
rspec-support (~> 3.
|
31
|
-
rspec-support (3.
|
32
|
-
rubocop (
|
33
|
-
jaro_winkler (~> 1.5.1)
|
31
|
+
rspec-support (~> 3.10.0)
|
32
|
+
rspec-support (3.10.2)
|
33
|
+
rubocop (1.30.0)
|
34
34
|
parallel (~> 1.10)
|
35
|
-
parser (>=
|
35
|
+
parser (>= 3.1.0.0)
|
36
36
|
rainbow (>= 2.2.2, < 4.0)
|
37
|
+
regexp_parser (>= 1.8, < 3.0)
|
38
|
+
rexml (>= 3.2.5, < 4.0)
|
39
|
+
rubocop-ast (>= 1.18.0, < 2.0)
|
37
40
|
ruby-progressbar (~> 1.7)
|
38
|
-
unicode-display_width (>= 1.4.0, <
|
39
|
-
|
40
|
-
|
41
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
42
|
+
rubocop-ast (1.18.0)
|
43
|
+
parser (>= 3.1.1.0)
|
44
|
+
ruby-progressbar (1.11.0)
|
45
|
+
unicode-display_width (2.1.0)
|
41
46
|
|
42
47
|
PLATFORMS
|
43
48
|
ruby
|
44
49
|
|
45
50
|
DEPENDENCIES
|
46
51
|
asciidoctor-kroki!
|
47
|
-
rake (~>
|
48
|
-
rspec (~> 3.
|
49
|
-
rubocop (~>
|
52
|
+
rake (~> 13.0.6)
|
53
|
+
rspec (~> 3.10.0)
|
54
|
+
rubocop (~> 1.30)
|
50
55
|
|
51
56
|
BUNDLED WITH
|
52
|
-
|
57
|
+
2.3.15
|
data/asciidoctor-kroki.gemspec
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'lib/asciidoctor/extensions/asciidoctor_kroki/version'
|
4
|
+
|
3
5
|
Gem::Specification.new do |s|
|
4
6
|
s.name = 'asciidoctor-kroki'
|
5
|
-
s.version =
|
7
|
+
s.version = Asciidoctor::AsciidoctorKroki::VERSION
|
6
8
|
s.summary = 'Asciidoctor extension to convert diagrams to images using Kroki'
|
7
9
|
s.description = 'An extension for Asciidoctor to convert diagrams to images using https://kroki.io'
|
8
10
|
|
@@ -12,15 +14,15 @@ Gem::Specification.new do |s|
|
|
12
14
|
s.license = 'MIT'
|
13
15
|
s.metadata = {
|
14
16
|
'bug_tracker_uri' => 'https://github.com/Mogztter/asciidoctor-kroki/issues',
|
15
|
-
'source_code_uri' => 'https://github.com/Mogztter/asciidoctor-kroki'
|
17
|
+
'source_code_uri' => 'https://github.com/Mogztter/asciidoctor-kroki',
|
18
|
+
'rubygems_mfa_required' => 'true'
|
16
19
|
}
|
17
20
|
s.files = `git ls-files`.split($RS)
|
18
|
-
s.test_files = s.files.grep(%r{^(test|spec|features|tasks)/})
|
19
21
|
s.require_paths = ['lib']
|
20
22
|
|
21
23
|
s.add_runtime_dependency 'asciidoctor', '~> 2.0'
|
22
24
|
|
23
|
-
s.add_development_dependency 'rake', '~>
|
24
|
-
s.add_development_dependency 'rspec', '~> 3.
|
25
|
-
s.add_development_dependency 'rubocop', '~>
|
25
|
+
s.add_development_dependency 'rake', '~> 13.0.6'
|
26
|
+
s.add_development_dependency 'rspec', '~> 3.10.0'
|
27
|
+
s.add_development_dependency 'rubocop', '~> 1.30'
|
26
28
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'cgi'
|
3
4
|
require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
|
4
5
|
|
5
6
|
# Asciidoctor extensions
|
@@ -17,11 +18,11 @@ module AsciidoctorExtensions
|
|
17
18
|
|
18
19
|
# @param name [String] name of the block macro (optional)
|
19
20
|
# @param config [Hash] a config hash (optional)
|
20
|
-
#
|
21
|
+
# - :logger a logger used to log warning and errors (optional)
|
21
22
|
#
|
22
|
-
def initialize(name = nil, config = {}
|
23
|
+
def initialize(name = nil, config = {})
|
24
|
+
@logger = (config || {}).delete(:logger) { ::Asciidoctor::LoggerManager.logger }
|
23
25
|
super(name, config)
|
24
|
-
@logger = logger
|
25
26
|
end
|
26
27
|
|
27
28
|
def process(parent, reader, attrs)
|
@@ -38,17 +39,18 @@ module AsciidoctorExtensions
|
|
38
39
|
# A block macro extension that converts a diagram into an image.
|
39
40
|
#
|
40
41
|
class KrokiBlockMacroProcessor < Asciidoctor::Extensions::BlockMacroProcessor
|
42
|
+
include Asciidoctor::Logging
|
41
43
|
use_dsl
|
42
44
|
|
43
45
|
name_positional_attributes 'format'
|
44
46
|
|
45
47
|
# @param name [String] name of the block macro (optional)
|
46
48
|
# @param config [Hash] a config hash (optional)
|
47
|
-
#
|
49
|
+
# - :logger a logger used to log warning and errors (optional)
|
48
50
|
#
|
49
|
-
def initialize(name = nil, config = {}
|
51
|
+
def initialize(name = nil, config = {})
|
52
|
+
@logger = (config || {}).delete(:logger) { ::Asciidoctor::LoggerManager.logger }
|
50
53
|
super(name, config)
|
51
|
-
@logger = logger
|
52
54
|
end
|
53
55
|
|
54
56
|
def process(parent, target, attrs)
|
@@ -61,14 +63,14 @@ module AsciidoctorExtensions
|
|
61
63
|
end
|
62
64
|
|
63
65
|
unless (path = resolve_target_path(target))
|
64
|
-
logger.error "#{diagram_type} block macro not found: #{target}."
|
65
|
-
create_block(parent, 'paragraph', unresolved_block_macro_message(diagram_type, target), {})
|
66
|
+
logger.error message_with_context "#{diagram_type} block macro not found: #{target}.", source_location: parent.document.reader.cursor_at_mark
|
67
|
+
return create_block(parent, 'paragraph', unresolved_block_macro_message(diagram_type, target), {})
|
66
68
|
end
|
67
69
|
|
68
70
|
begin
|
69
71
|
diagram_text = read(path)
|
70
|
-
rescue => e # rubocop:disable RescueStandardError
|
71
|
-
logger.error "Failed to read #{diagram_type} file: #{path}. #{e}."
|
72
|
+
rescue => e # rubocop:disable Style/RescueStandardError
|
73
|
+
logger.error message_with_context "Failed to read #{diagram_type} file: #{path}. #{e}.", source_location: parent.document.reader.cursor_at_mark
|
72
74
|
return create_block(parent, 'paragraph', unresolved_block_macro_message(diagram_type, path), {})
|
73
75
|
end
|
74
76
|
KrokiProcessor.process(self, parent, attrs, diagram_type, diagram_text, @logger)
|
@@ -89,9 +91,9 @@ module AsciidoctorExtensions
|
|
89
91
|
def read(target)
|
90
92
|
if target.start_with?('http://') || target.start_with?('https://')
|
91
93
|
require 'open-uri'
|
92
|
-
|
94
|
+
::OpenURI.open_uri(target, &:read)
|
93
95
|
else
|
94
|
-
File.
|
96
|
+
File.read(target, mode: 'rb:utf-8:utf-8')
|
95
97
|
end
|
96
98
|
end
|
97
99
|
|
@@ -117,6 +119,7 @@ module AsciidoctorExtensions
|
|
117
119
|
nomnoml
|
118
120
|
nwdiag
|
119
121
|
packetdiag
|
122
|
+
pikchr
|
120
123
|
plantuml
|
121
124
|
rackdiag
|
122
125
|
seqdiag
|
@@ -125,15 +128,20 @@ module AsciidoctorExtensions
|
|
125
128
|
vega
|
126
129
|
vegalite
|
127
130
|
wavedrom
|
131
|
+
structurizr
|
128
132
|
].freeze
|
129
133
|
end
|
130
134
|
|
131
135
|
# Internal processor
|
132
136
|
#
|
133
137
|
class KrokiProcessor
|
138
|
+
include Asciidoctor::Logging
|
139
|
+
|
134
140
|
TEXT_FORMATS = %w[txt atxt utxt].freeze
|
141
|
+
BUILTIN_ATTRIBUTES = %w[target width height format fallback link float align role caption title cloaked-context subs].freeze
|
135
142
|
|
136
143
|
class << self
|
144
|
+
# rubocop:disable Metrics/AbcSize
|
137
145
|
def process(processor, parent, attrs, diagram_type, diagram_text, logger)
|
138
146
|
doc = parent.document
|
139
147
|
diagram_text = prepend_plantuml_config(diagram_text, diagram_type, doc, logger)
|
@@ -142,20 +150,27 @@ module AsciidoctorExtensions
|
|
142
150
|
if (subs = attrs['subs'])
|
143
151
|
diagram_text = parent.apply_subs(diagram_text, parent.resolve_subs(subs))
|
144
152
|
end
|
145
|
-
title = attrs.delete('title')
|
146
|
-
caption = attrs.delete('caption')
|
147
153
|
attrs.delete('opts')
|
148
|
-
role = attrs['role']
|
149
154
|
format = get_format(doc, attrs, diagram_type)
|
150
|
-
attrs['role'] = get_role(format, role)
|
155
|
+
attrs['role'] = get_role(format, attrs['role'])
|
151
156
|
attrs['format'] = format
|
152
|
-
|
153
|
-
|
157
|
+
opts = attrs.filter { |key, _| key.is_a?(String) && BUILTIN_ATTRIBUTES.none? { |k| key == k } && !key.end_with?('-option') }
|
158
|
+
kroki_diagram = KrokiDiagram.new(diagram_type, format, diagram_text, attrs['target'], opts)
|
159
|
+
kroki_client = KrokiClient.new({
|
160
|
+
server_url: server_url(doc),
|
161
|
+
http_method: http_method(doc),
|
162
|
+
max_uri_length: max_uri_length(doc),
|
163
|
+
source_location: doc.reader.cursor_at_mark,
|
164
|
+
http_client: KrokiHttpClient
|
165
|
+
}, logger)
|
166
|
+
alt = get_alt(attrs)
|
167
|
+
title = attrs.delete('title')
|
168
|
+
caption = attrs.delete('caption')
|
154
169
|
if TEXT_FORMATS.include?(format)
|
155
170
|
text_content = kroki_client.text_content(kroki_diagram)
|
156
171
|
block = processor.create_block(parent, 'literal', text_content, attrs)
|
157
172
|
else
|
158
|
-
attrs['alt'] =
|
173
|
+
attrs['alt'] = alt
|
159
174
|
attrs['target'] = create_image_src(doc, kroki_diagram, kroki_client)
|
160
175
|
block = processor.create_image_block(parent, attrs)
|
161
176
|
end
|
@@ -163,6 +178,7 @@ module AsciidoctorExtensions
|
|
163
178
|
block.assign_caption(caption, 'figure')
|
164
179
|
block
|
165
180
|
end
|
181
|
+
# rubocop:enable Metrics/AbcSize
|
166
182
|
|
167
183
|
private
|
168
184
|
|
@@ -173,9 +189,10 @@ module AsciidoctorExtensions
|
|
173
189
|
plantuml_include_path = doc.normalize_system_path(doc.attr('kroki-plantuml-include'))
|
174
190
|
if ::File.readable? plantuml_include_path
|
175
191
|
config = File.read(plantuml_include_path)
|
176
|
-
diagram_text = config
|
192
|
+
diagram_text = "#{config}\n#{diagram_text}"
|
177
193
|
else
|
178
|
-
logger.warn "Unable to read plantuml-include. File not found or not readable: #{plantuml_include_path}."
|
194
|
+
logger.warn message_with_context "Unable to read plantuml-include. File not found or not readable: #{plantuml_include_path}.",
|
195
|
+
source_location: doc.reader.cursor_at_mark
|
179
196
|
end
|
180
197
|
end
|
181
198
|
diagram_text
|
@@ -204,13 +221,13 @@ module AsciidoctorExtensions
|
|
204
221
|
end
|
205
222
|
|
206
223
|
def get_format(doc, attrs, diagram_type)
|
207
|
-
format = attrs['format'] || 'svg'
|
208
|
-
|
209
|
-
|
210
|
-
#
|
211
|
-
# Currently,
|
212
|
-
svg_only_diagram_types = %
|
213
|
-
format = '
|
224
|
+
format = attrs['format'] || doc.attr('kroki-default-format') || 'svg'
|
225
|
+
if format == 'png'
|
226
|
+
# redirect PNG format to SVG if the diagram library only supports SVG as output format.
|
227
|
+
# this is useful when the default format has been set to PNG
|
228
|
+
# Currently, nomnoml, svgbob, wavedrom only support SVG as output format.
|
229
|
+
svg_only_diagram_types = %i[nomnoml svgbob wavedrom]
|
230
|
+
format = 'svg' if svg_only_diagram_types.include?(diagram_type)
|
214
231
|
end
|
215
232
|
format
|
216
233
|
end
|
@@ -239,10 +256,9 @@ module AsciidoctorExtensions
|
|
239
256
|
images_dir = doc.attr('imagesdir', '')
|
240
257
|
if (images_output_dir = doc.attr('imagesoutdir'))
|
241
258
|
images_output_dir
|
242
|
-
|
259
|
+
# the nested document logic will become obsolete once https://github.com/asciidoctor/asciidoctor/commit/7edc9da023522be67b17e2a085d72e056703a438 is released
|
260
|
+
elsif (out_dir = doc.attr('outdir') || (doc.nested? ? doc.parent_document : doc).options[:to_dir])
|
243
261
|
File.join(out_dir, images_dir)
|
244
|
-
elsif (to_dir = doc.attr('to_dir'))
|
245
|
-
File.join(to_dir, images_dir)
|
246
262
|
else
|
247
263
|
File.join(doc.base_dir, images_dir)
|
248
264
|
end
|
@@ -257,18 +273,19 @@ module AsciidoctorExtensions
|
|
257
273
|
require 'zlib'
|
258
274
|
require 'digest'
|
259
275
|
|
260
|
-
attr_reader :type
|
261
|
-
attr_reader :text
|
262
|
-
attr_reader :format
|
276
|
+
attr_reader :type, :text, :format, :target, :opts
|
263
277
|
|
264
|
-
def initialize(type, format, text)
|
278
|
+
def initialize(type, format, text, target = nil, opts = {})
|
265
279
|
@text = text
|
266
280
|
@type = type
|
267
281
|
@format = format
|
282
|
+
@target = target
|
283
|
+
@opts = opts
|
268
284
|
end
|
269
285
|
|
270
286
|
def get_diagram_uri(server_url)
|
271
|
-
|
287
|
+
query_params = opts.map { |k, v| "#{k}=#{_url_encode(v.to_s)}" }.join('&') unless opts.empty?
|
288
|
+
_join_uri_segments(server_url, @type, @format, encode) + (query_params ? "?#{query_params}" : '')
|
272
289
|
end
|
273
290
|
|
274
291
|
def encode
|
@@ -277,37 +294,39 @@ module AsciidoctorExtensions
|
|
277
294
|
|
278
295
|
def save(output_dir_path, kroki_client)
|
279
296
|
diagram_url = get_diagram_uri(kroki_client.server_url)
|
280
|
-
diagram_name = "diag-#{Digest::SHA256.hexdigest diagram_url}.#{@format}"
|
297
|
+
diagram_name = "#{@target || 'diag'}-#{Digest::SHA256.hexdigest diagram_url}.#{@format}"
|
281
298
|
file_path = File.join(output_dir_path, diagram_name)
|
282
|
-
encoding =
|
299
|
+
encoding = case @format
|
300
|
+
when 'txt', 'atxt', 'utxt', 'svg'
|
283
301
|
'utf8'
|
284
|
-
elsif @format == 'svg'
|
285
|
-
'binary'
|
286
302
|
else
|
287
303
|
'binary'
|
288
304
|
end
|
289
305
|
# file is either (already) on the file system or we should read it from Kroki
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
File.
|
294
|
-
else
|
295
|
-
File.write(file_path, contents)
|
306
|
+
unless File.exist?(file_path)
|
307
|
+
contents = kroki_client.get_image(self, encoding)
|
308
|
+
FileUtils.mkdir_p(output_dir_path)
|
309
|
+
File.write(file_path, contents, mode: 'wb')
|
296
310
|
end
|
311
|
+
|
297
312
|
diagram_name
|
298
313
|
end
|
299
314
|
|
300
315
|
private
|
301
316
|
|
317
|
+
def _url_encode(text)
|
318
|
+
CGI.escape(text).gsub(/\+/, '%20')
|
319
|
+
end
|
320
|
+
|
302
321
|
def _join_uri_segments(base, *uris)
|
303
322
|
segments = []
|
304
323
|
# remove trailing slashes
|
305
|
-
segments.push(base.gsub(%r{
|
324
|
+
segments.push(base.gsub(%r{/+$}, ''))
|
306
325
|
segments.concat(uris.map do |uri|
|
307
326
|
# remove leading and trailing slashes
|
308
327
|
uri.to_s
|
309
|
-
.gsub(%r{
|
310
|
-
.gsub(%r{
|
328
|
+
.gsub(%r{^/+}, '')
|
329
|
+
.gsub(%r{/+$}, '')
|
311
330
|
end)
|
312
331
|
segments.join('/')
|
313
332
|
end
|
@@ -316,21 +335,23 @@ module AsciidoctorExtensions
|
|
316
335
|
# Kroki client
|
317
336
|
#
|
318
337
|
class KrokiClient
|
319
|
-
|
320
|
-
|
321
|
-
attr_reader :max_uri_length
|
338
|
+
include Asciidoctor::Logging
|
339
|
+
|
340
|
+
attr_reader :server_url, :method, :max_uri_length
|
322
341
|
|
323
342
|
SUPPORTED_HTTP_METHODS = %w[get post adaptive].freeze
|
324
343
|
|
325
|
-
def initialize(
|
326
|
-
@server_url = server_url
|
327
|
-
@max_uri_length = max_uri_length
|
328
|
-
@http_client = http_client
|
329
|
-
method = (http_method
|
344
|
+
def initialize(opts, logger = ::Asciidoctor::LoggerManager.logger)
|
345
|
+
@server_url = opts[:server_url]
|
346
|
+
@max_uri_length = opts.fetch(:max_uri_length, 4000)
|
347
|
+
@http_client = opts[:http_client]
|
348
|
+
method = opts.fetch(:http_method, 'adaptive').downcase
|
330
349
|
if SUPPORTED_HTTP_METHODS.include?(method)
|
331
350
|
@method = method
|
332
351
|
else
|
333
|
-
logger.warn "Invalid value '#{method}' for kroki-http-method attribute. The value must be either:
|
352
|
+
logger.warn message_with_context "Invalid value '#{method}' for kroki-http-method attribute. The value must be either: " \
|
353
|
+
"'get', 'post' or 'adaptive'. Proceeding using: 'adaptive'.",
|
354
|
+
source_location: opts[:source_location]
|
334
355
|
@method = 'adaptive'
|
335
356
|
end
|
336
357
|
end
|
@@ -343,6 +364,7 @@ module AsciidoctorExtensions
|
|
343
364
|
type = kroki_diagram.type
|
344
365
|
format = kroki_diagram.format
|
345
366
|
text = kroki_diagram.text
|
367
|
+
opts = kroki_diagram.opts
|
346
368
|
if @method == 'adaptive' || @method == 'get'
|
347
369
|
uri = kroki_diagram.get_diagram_uri(server_url)
|
348
370
|
if uri.length > @max_uri_length
|
@@ -350,15 +372,15 @@ module AsciidoctorExtensions
|
|
350
372
|
if @method == 'get'
|
351
373
|
# The request might be rejected by the server with a 414 Request-URI Too Large.
|
352
374
|
# Consider using the attribute kroki-http-method with the value 'adaptive'.
|
353
|
-
@http_client.get(uri, encoding)
|
375
|
+
@http_client.get(uri, opts, encoding)
|
354
376
|
else
|
355
|
-
@http_client.post("#{@server_url}/#{type}/#{format}", text, encoding)
|
377
|
+
@http_client.post("#{@server_url}/#{type}/#{format}", text, opts, encoding)
|
356
378
|
end
|
357
379
|
else
|
358
|
-
@http_client.get(uri, encoding)
|
380
|
+
@http_client.get(uri, opts, encoding)
|
359
381
|
end
|
360
382
|
else
|
361
|
-
@http_client.post("#{@server_url}/#{type}/#{format}", text, encoding)
|
383
|
+
@http_client.post("#{@server_url}/#{type}/#{format}", text, opts, encoding)
|
362
384
|
end
|
363
385
|
end
|
364
386
|
end
|
@@ -371,12 +393,33 @@ module AsciidoctorExtensions
|
|
371
393
|
require 'json'
|
372
394
|
|
373
395
|
class << self
|
374
|
-
|
375
|
-
|
396
|
+
REFERER = "asciidoctor/kroki.rb/#{Asciidoctor::AsciidoctorKroki::VERSION}"
|
397
|
+
|
398
|
+
def get(uri, opts, _)
|
399
|
+
uri = URI(uri)
|
400
|
+
headers = opts.transform_keys { |key| "Kroki-Diagram-Options-#{key}" }
|
401
|
+
.merge({ 'referer' => REFERER })
|
402
|
+
request = ::Net::HTTP::Get.new(uri, headers)
|
403
|
+
::Net::HTTP.start(
|
404
|
+
uri.hostname,
|
405
|
+
uri.port,
|
406
|
+
use_ssl: (uri.scheme == 'https')
|
407
|
+
) do |http|
|
408
|
+
http.request(request).body
|
409
|
+
end
|
376
410
|
end
|
377
411
|
|
378
|
-
def post(uri, data, _)
|
379
|
-
|
412
|
+
def post(uri, data, opts, _)
|
413
|
+
headers = opts.transform_keys { |key| "Kroki-Diagram-Options-#{key}" }
|
414
|
+
.merge({
|
415
|
+
'Content-Type' => 'text/plain',
|
416
|
+
'referer' => REFERER
|
417
|
+
})
|
418
|
+
res = ::Net::HTTP.post(
|
419
|
+
URI(uri),
|
420
|
+
data,
|
421
|
+
headers
|
422
|
+
)
|
380
423
|
res.body
|
381
424
|
end
|
382
425
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# rubocop:disable Lint/ConstantDefinitionInBlock
|
1
2
|
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'rspec_helper'
|
@@ -88,7 +89,7 @@ describe ::AsciidoctorExtensions::KrokiBlockMacroProcessor do
|
|
88
89
|
</div>
|
89
90
|
</div>)
|
90
91
|
end
|
91
|
-
it 'should display unresolved block macro message when the
|
92
|
+
it 'should display unresolved block macro message when the target cannot be resolved' do
|
92
93
|
# noinspection RubyClassModuleNamingConvention
|
93
94
|
class UnresolvedTargetKrokiBlockMacroProcessor < ::AsciidoctorExtensions::KrokiBlockMacroProcessor
|
94
95
|
def resolve_target_path(_target)
|
@@ -103,7 +104,7 @@ describe ::AsciidoctorExtensions::KrokiBlockMacroProcessor do
|
|
103
104
|
ADOC
|
104
105
|
output = Asciidoctor.convert(input, standalone: false, extension_registry: registry)
|
105
106
|
(expect output).to eql %(<div class="paragraph">
|
106
|
-
<p>Unresolved block macro - plantuml::[]</p>
|
107
|
+
<p>Unresolved block macro - plantuml::alice.puml[]</p>
|
107
108
|
</div>)
|
108
109
|
end
|
109
110
|
it 'should override the unresolved block macro message' do
|
@@ -126,3 +127,4 @@ describe ::AsciidoctorExtensions::KrokiBlockMacroProcessor do
|
|
126
127
|
end
|
127
128
|
end
|
128
129
|
end
|
130
|
+
# rubocop:enable Lint/ConstantDefinitionInBlock
|
@@ -7,27 +7,27 @@ require_relative '../lib/asciidoctor/extensions/asciidoctor_kroki'
|
|
7
7
|
describe ::AsciidoctorExtensions::KrokiClient do
|
8
8
|
it 'should use adaptive method when http method is invalid' do
|
9
9
|
kroki_http_client = ::AsciidoctorExtensions::KrokiHttpClient
|
10
|
-
kroki_client = ::AsciidoctorExtensions::KrokiClient.new('http://localhost:8000', 'patch', kroki_http_client)
|
10
|
+
kroki_client = ::AsciidoctorExtensions::KrokiClient.new(server_url: 'http://localhost:8000', http_method: 'patch', http_client: kroki_http_client)
|
11
11
|
expect(kroki_client.method).to eq('adaptive')
|
12
12
|
end
|
13
13
|
it 'should use post method when http method is post' do
|
14
14
|
kroki_http_client = ::AsciidoctorExtensions::KrokiHttpClient
|
15
|
-
kroki_client = ::AsciidoctorExtensions::KrokiClient.new('http://localhost:8000', 'POST', kroki_http_client)
|
15
|
+
kroki_client = ::AsciidoctorExtensions::KrokiClient.new(server_url: 'http://localhost:8000', http_method: 'POST', http_client: kroki_http_client)
|
16
16
|
expect(kroki_client.method).to eq('post')
|
17
17
|
end
|
18
18
|
it 'should use get method when http method is get' do
|
19
19
|
kroki_http_client = ::AsciidoctorExtensions::KrokiHttpClient
|
20
|
-
kroki_client = ::AsciidoctorExtensions::KrokiClient.new('http://localhost:8000', 'get', kroki_http_client)
|
20
|
+
kroki_client = ::AsciidoctorExtensions::KrokiClient.new(server_url: 'http://localhost:8000', http_method: 'get', http_client: kroki_http_client)
|
21
21
|
expect(kroki_client.method).to eq('get')
|
22
22
|
end
|
23
23
|
it 'should use 4000 as the default max URI length' do
|
24
24
|
kroki_http_client = ::AsciidoctorExtensions::KrokiHttpClient
|
25
|
-
kroki_client = ::AsciidoctorExtensions::KrokiClient.new('http://localhost:8000', 'get', kroki_http_client)
|
25
|
+
kroki_client = ::AsciidoctorExtensions::KrokiClient.new(server_url: 'http://localhost:8000', http_method: 'get', http_client: kroki_http_client)
|
26
26
|
expect(kroki_client.max_uri_length).to eq(4000)
|
27
27
|
end
|
28
28
|
it 'should use a custom value as max URI length' do
|
29
29
|
kroki_http_client = ::AsciidoctorExtensions::KrokiHttpClient
|
30
|
-
kroki_client = ::AsciidoctorExtensions::KrokiClient.new('http://localhost:8000', 'get', kroki_http_client,
|
30
|
+
kroki_client = ::AsciidoctorExtensions::KrokiClient.new(server_url: 'http://localhost:8000', http_method: 'get', http_client: kroki_http_client, max_uri_length: 8000)
|
31
31
|
expect(kroki_client.max_uri_length).to eq(8000)
|
32
32
|
end
|
33
33
|
it 'should get an image with POST request if the URI length is greater than the value configured' do
|
@@ -37,54 +37,56 @@ describe ::AsciidoctorExtensions::KrokiClient do
|
|
37
37
|
"GET #{uri}"
|
38
38
|
end
|
39
39
|
|
40
|
-
def post(uri, data, _)
|
40
|
+
def post(uri, data, _, _)
|
41
41
|
"POST #{uri} - #{data}"
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
45
|
kroki_diagram = Class.new do
|
46
|
-
attr_reader :type, :text, :format
|
46
|
+
attr_reader :type, :text, :format, :opts
|
47
47
|
|
48
|
-
def initialize(type, format, text)
|
48
|
+
def initialize(type, format, text, opts = {})
|
49
49
|
@text = text
|
50
50
|
@type = type
|
51
51
|
@format = format
|
52
|
+
@opts = opts
|
52
53
|
end
|
53
54
|
|
54
55
|
def get_diagram_uri(_)
|
55
56
|
'diagram-uri'
|
56
57
|
end
|
57
58
|
end.new('type', 'format', 'text')
|
58
|
-
kroki_client = ::AsciidoctorExtensions::KrokiClient.new('http://localhost:8000', 'adaptive', kroki_http_client,
|
59
|
+
kroki_client = ::AsciidoctorExtensions::KrokiClient.new(server_url: 'http://localhost:8000', http_method: 'adaptive', http_client: kroki_http_client, max_uri_length: 10)
|
59
60
|
result = kroki_client.get_image(kroki_diagram, 'utf8')
|
60
61
|
expect(result).to eq('POST http://localhost:8000/type/format - text')
|
61
62
|
end
|
62
63
|
it 'should get an image with GET request if the URI length is lower or equals than the value configured' do
|
63
64
|
kroki_http_client = Class.new do
|
64
65
|
class << self
|
65
|
-
def get(uri, _)
|
66
|
+
def get(uri, _, _)
|
66
67
|
"GET #{uri}"
|
67
68
|
end
|
68
69
|
|
69
|
-
def post(uri, data, _)
|
70
|
+
def post(uri, data, _, _)
|
70
71
|
"POST #{uri} - #{data}"
|
71
72
|
end
|
72
73
|
end
|
73
74
|
end
|
74
75
|
kroki_diagram = Class.new do
|
75
|
-
attr_reader :type, :text, :format
|
76
|
+
attr_reader :type, :text, :format, :opts
|
76
77
|
|
77
|
-
def initialize(type, format, text)
|
78
|
+
def initialize(type, format, text, opts = {})
|
78
79
|
@text = text
|
79
80
|
@type = type
|
80
81
|
@format = format
|
82
|
+
@opts = opts
|
81
83
|
end
|
82
84
|
|
83
85
|
def get_diagram_uri(_)
|
84
86
|
'diagram-uri'
|
85
87
|
end
|
86
88
|
end.new('type', 'format', 'text')
|
87
|
-
kroki_client = ::AsciidoctorExtensions::KrokiClient.new('http://localhost:8000', 'adaptive', kroki_http_client,
|
89
|
+
kroki_client = ::AsciidoctorExtensions::KrokiClient.new(server_url: 'http://localhost:8000', http_method: 'adaptive', http_client: kroki_http_client, max_uri_length: 11)
|
88
90
|
result = kroki_client.get_image(kroki_diagram, 'utf8')
|
89
91
|
expect(result).to eq('GET diagram-uri')
|
90
92
|
end
|
@@ -20,6 +20,24 @@ describe ::AsciidoctorExtensions::KrokiDiagram do
|
|
20
20
|
diagram_uri = kroki_diagram.get_diagram_uri('https://my-server/kroki//')
|
21
21
|
expect(diagram_uri).to eq('https://my-server/kroki/vegalite/png/eNqrrgUAAXUA-Q==')
|
22
22
|
end
|
23
|
+
it 'should compute a diagram URI with query parameters' do
|
24
|
+
text = %q{
|
25
|
+
.---.
|
26
|
+
/-o-/--
|
27
|
+
.-/ / /->
|
28
|
+
( * \/
|
29
|
+
'-. \
|
30
|
+
\ /
|
31
|
+
'
|
32
|
+
}
|
33
|
+
opts = {
|
34
|
+
'stroke-width' => 1,
|
35
|
+
'background' => 'black'
|
36
|
+
}
|
37
|
+
kroki_diagram = ::AsciidoctorExtensions::KrokiDiagram.new('svgbob', 'png', text, nil, opts)
|
38
|
+
diagram_uri = kroki_diagram.get_diagram_uri('http://localhost:8000')
|
39
|
+
expect(diagram_uri).to eq('http://localhost:8000/svgbob/png/eNrjUoAAPV1dXT0uCFtfN19XX1eXCyysrwCEunZAjoaCloJCjD5IWF1XD8gEK49R0IdoUwdTAN3kC7U=?stroke-width=1&background=black')
|
40
|
+
end
|
23
41
|
it 'should encode a diagram text definition' do
|
24
42
|
kroki_diagram = ::AsciidoctorExtensions::KrokiDiagram.new('plantuml', 'txt', ' alice -> bob: hello')
|
25
43
|
diagram_definition_encoded = kroki_diagram.encode
|
@@ -28,11 +46,32 @@ describe ::AsciidoctorExtensions::KrokiDiagram do
|
|
28
46
|
it 'should fetch a diagram from Kroki and save it to disk' do
|
29
47
|
kroki_diagram = ::AsciidoctorExtensions::KrokiDiagram.new('plantuml', 'txt', ' alice -> bob: hello')
|
30
48
|
kroki_http_client = ::AsciidoctorExtensions::KrokiHttpClient
|
31
|
-
kroki_client = ::AsciidoctorExtensions::KrokiClient.new('https://kroki.io', 'get', kroki_http_client)
|
49
|
+
kroki_client = ::AsciidoctorExtensions::KrokiClient.new(server_url: 'https://kroki.io', http_method: 'get', http_client: kroki_http_client)
|
50
|
+
output_dir_path = "#{__dir__}/../.asciidoctor/kroki"
|
51
|
+
diagram_name = kroki_diagram.save(output_dir_path, kroki_client)
|
52
|
+
diagram_path = File.join(output_dir_path, diagram_name)
|
53
|
+
expect(File.exist?(diagram_path)).to be_truthy, "diagram should be saved at: #{diagram_path}"
|
54
|
+
content = <<-TXT.chomp
|
55
|
+
,-----. ,---.
|
56
|
+
|alice| |bob|
|
57
|
+
`--+--' `-+-'
|
58
|
+
| hello |
|
59
|
+
|-------------->|
|
60
|
+
,--+--. ,-+-.
|
61
|
+
|alice| |bob|
|
62
|
+
`-----' `---'
|
63
|
+
TXT
|
64
|
+
expect(File.read(diagram_path).split("\n").map(&:rstrip).join("\n")).to eq(content)
|
65
|
+
end
|
66
|
+
it 'should fetch a diagram from Kroki and save it to disk using the target name' do
|
67
|
+
kroki_diagram = ::AsciidoctorExtensions::KrokiDiagram.new('plantuml', 'txt', ' alice -> bob: hello', 'hello-world')
|
68
|
+
kroki_http_client = ::AsciidoctorExtensions::KrokiHttpClient
|
69
|
+
kroki_client = ::AsciidoctorExtensions::KrokiClient.new(server_url: 'https://kroki.io', http_method: 'get', http_client: kroki_http_client)
|
32
70
|
output_dir_path = "#{__dir__}/../.asciidoctor/kroki"
|
33
71
|
diagram_name = kroki_diagram.save(output_dir_path, kroki_client)
|
34
72
|
diagram_path = File.join(output_dir_path, diagram_name)
|
35
|
-
expect(
|
73
|
+
expect(diagram_name).to start_with('hello-world-'), "diagram name should use the target as a prefix, got: #{diagram_name}"
|
74
|
+
expect(File.exist?(diagram_path)).to be_truthy, "diagram should be saved at: #{diagram_path}"
|
36
75
|
content = <<-TXT.chomp
|
37
76
|
,-----. ,---.
|
38
77
|
|alice| |bob|
|
@@ -48,14 +87,16 @@ describe ::AsciidoctorExtensions::KrokiDiagram do
|
|
48
87
|
it 'should fetch a diagram from Kroki with the same definition only once' do
|
49
88
|
kroki_diagram = ::AsciidoctorExtensions::KrokiDiagram.new('plantuml', 'png', ' guillaume -> dan: hello')
|
50
89
|
kroki_http_client = ::AsciidoctorExtensions::KrokiHttpClient
|
51
|
-
kroki_client = ::AsciidoctorExtensions::KrokiClient.new('https://kroki.io', 'get', kroki_http_client)
|
90
|
+
kroki_client = ::AsciidoctorExtensions::KrokiClient.new(server_url: 'https://kroki.io', http_method: 'get', http_client: kroki_http_client)
|
52
91
|
output_dir_path = "#{__dir__}/../.asciidoctor/kroki"
|
53
92
|
# make sure that we are doing only one GET request
|
54
|
-
|
93
|
+
diagram_contents = File.read("#{__dir__}/fixtures/plantuml-diagram.png", mode: 'rb')
|
94
|
+
expect(kroki_http_client).to receive(:get).once.and_return(diagram_contents)
|
55
95
|
diagram_name = kroki_diagram.save(output_dir_path, kroki_client)
|
56
96
|
diagram_path = File.join(output_dir_path, diagram_name)
|
57
|
-
expect(File.exist?(diagram_path)).to be_truthy, "
|
97
|
+
expect(File.exist?(diagram_path)).to be_truthy, "diagram should be saved at: #{diagram_path}"
|
58
98
|
# calling again... should read the file from disk (and not do a GET request)
|
59
99
|
kroki_diagram.save(output_dir_path, kroki_client)
|
100
|
+
expect(File.size(diagram_path)).to be_eql(diagram_contents.length), 'diagram should be fully saved on disk'
|
60
101
|
end
|
61
102
|
end
|
@@ -0,0 +1,33 @@
|
|
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::KrokiProcessor' do
|
8
|
+
it 'should return the images output directory (imagesoutdir attribute)' do
|
9
|
+
doc = Asciidoctor.load('hello', attributes: { 'imagesoutdir' => '.asciidoctor/kroki/images', 'imagesdir' => '../images' })
|
10
|
+
output_dir_path = AsciidoctorExtensions::KrokiProcessor.send(:output_dir_path, doc)
|
11
|
+
expect(output_dir_path).to eq '.asciidoctor/kroki/images'
|
12
|
+
end
|
13
|
+
it 'should return a path relative to output directory (to_dir option)' do
|
14
|
+
doc = Asciidoctor.load('hello', to_dir: '.asciidoctor/kroki/relative', attributes: { 'imagesdir' => '../images' })
|
15
|
+
output_dir_path = AsciidoctorExtensions::KrokiProcessor.send(:output_dir_path, doc)
|
16
|
+
expect(output_dir_path).to eq '.asciidoctor/kroki/relative/../images'
|
17
|
+
end
|
18
|
+
it 'should return a path relative to output directory (outdir attribute)' do
|
19
|
+
doc = Asciidoctor.load('hello', attributes: { 'imagesdir' => 'resources/images', 'outdir' => '.asciidoctor/kroki/out' })
|
20
|
+
output_dir_path = AsciidoctorExtensions::KrokiProcessor.send(:output_dir_path, doc)
|
21
|
+
expect(output_dir_path).to eq '.asciidoctor/kroki/out/resources/images'
|
22
|
+
end
|
23
|
+
it 'should return a path relative to the base directory (base_dir option)' do
|
24
|
+
doc = Asciidoctor.load('hello', base_dir: '.asciidoctor/kroki', attributes: { 'imagesdir' => 'img' })
|
25
|
+
output_dir_path = AsciidoctorExtensions::KrokiProcessor.send(:output_dir_path, doc)
|
26
|
+
expect(output_dir_path).to eq "#{::Dir.pwd}/.asciidoctor/kroki/img"
|
27
|
+
end
|
28
|
+
it 'should return a path relative to the base directory (default value is current working directory)' do
|
29
|
+
doc = Asciidoctor.load('hello', attributes: { 'imagesdir' => 'img' })
|
30
|
+
output_dir_path = AsciidoctorExtensions::KrokiProcessor.send(:output_dir_path, doc)
|
31
|
+
expect(output_dir_path).to eq "#{::Dir.pwd}/img"
|
32
|
+
end
|
33
|
+
end
|
@@ -20,18 +20,64 @@ describe ::AsciidoctorExtensions::KrokiBlockProcessor do
|
|
20
20
|
</div>
|
21
21
|
</div>)
|
22
22
|
end
|
23
|
-
it 'should
|
23
|
+
it 'should only pass diagram options as query parameters' do
|
24
|
+
input = <<~'ADOC'
|
25
|
+
[plantuml,alice-bob,svg,role=sequence,width=100,format=svg,link=https://asciidoc.org/,align=center,float=right,theme=bluegray]
|
26
|
+
....
|
27
|
+
alice -> bob: hello
|
28
|
+
....
|
29
|
+
ADOC
|
30
|
+
output = Asciidoctor.convert(input, standalone: false)
|
31
|
+
(expect output).to eql %(<div class="imageblock right text-center sequence kroki-format-svg kroki">
|
32
|
+
<div class="content">
|
33
|
+
<a class="image" href="https://asciidoc.org/"><img src="https://kroki.io/plantuml/svg/eNpLzMlMTlXQtVNIyk-yUshIzcnJBwA9iwZL?theme=bluegray" alt="alice-bob" width="100"></a>
|
34
|
+
</div>
|
35
|
+
</div>)
|
36
|
+
end
|
37
|
+
it 'should use the title attribute as the alt value' do
|
38
|
+
input = <<~'ADOC'
|
39
|
+
[plantuml,title="Alice saying hello to Bob"]
|
40
|
+
....
|
41
|
+
alice -> bob: hello
|
42
|
+
....
|
43
|
+
ADOC
|
44
|
+
output = Asciidoctor.convert(input, standalone: false)
|
45
|
+
(expect output).to eql %(<div class="imageblock kroki">
|
46
|
+
<div class="content">
|
47
|
+
<img src="https://kroki.io/plantuml/svg/eNpLzMlMTlXQtVNIyk-yUshIzcnJBwA9iwZL" alt="Alice saying hello to Bob">
|
48
|
+
</div>
|
49
|
+
<div class="title">Figure 1. Alice saying hello to Bob</div>
|
50
|
+
</div>)
|
51
|
+
end
|
52
|
+
it 'should use png if kroki-default-format is set to png' do
|
24
53
|
input = <<~'ADOC'
|
25
54
|
[plantuml]
|
26
55
|
....
|
27
56
|
alice -> bob: hello
|
28
57
|
....
|
29
58
|
ADOC
|
30
|
-
output = Asciidoctor.convert(input, attributes: { '
|
59
|
+
output = Asciidoctor.convert(input, attributes: { 'kroki-default-format' => 'png' }, standalone: false)
|
31
60
|
(expect output).to eql %(<div class="imageblock kroki">
|
32
61
|
<div class="content">
|
33
62
|
<img src="https://kroki.io/plantuml/png/eNpLzMlMTlXQtVNIyk-yUshIzcnJBwA9iwZL" alt="Diagram">
|
34
63
|
</div>
|
64
|
+
</div>)
|
65
|
+
end
|
66
|
+
it 'should use svg if kroki-default-format is set to png and the diagram type does not support png' do
|
67
|
+
input = <<~'ADOC'
|
68
|
+
[nomnoml]
|
69
|
+
....
|
70
|
+
[Pirate|eyeCount: Int|raid();pillage()|
|
71
|
+
[beard]--[parrot]
|
72
|
+
[beard]-:>[foul mouth]
|
73
|
+
]
|
74
|
+
....
|
75
|
+
ADOC
|
76
|
+
output = Asciidoctor.convert(input, attributes: { 'kroki-default-format' => 'png' }, standalone: false)
|
77
|
+
(expect output).to eql %(<div class="imageblock kroki">
|
78
|
+
<div class="content">
|
79
|
+
<img src="https://kroki.io/nomnoml/svg/eNqLDsgsSixJrUmtTHXOL80rsVLwzCupKUrMTNHQtC7IzMlJTE_V0KzhUlCITkpNLEqJ1dWNLkgsKsoviUUSs7KLTssvzVHIzS8tyYjligUAMhEd0g==" alt="Diagram">
|
80
|
+
</div>
|
35
81
|
</div>)
|
36
82
|
end
|
37
83
|
it 'should include the plantuml-include file when safe mode is safe' do
|
@@ -41,10 +87,12 @@ describe ::AsciidoctorExtensions::KrokiBlockProcessor do
|
|
41
87
|
alice -> bob: hello
|
42
88
|
....
|
43
89
|
ADOC
|
44
|
-
output = Asciidoctor.convert(input,
|
90
|
+
output = Asciidoctor.convert(input,
|
91
|
+
attributes: { 'kroki-plantuml-include' => 'spec/fixtures/config.puml' },
|
92
|
+
standalone: false, safe: :safe)
|
45
93
|
(expect output).to eql %(<div class="imageblock kroki">
|
46
94
|
<div class="content">
|
47
|
-
<img src="https://kroki.io/plantuml/
|
95
|
+
<img src="https://kroki.io/plantuml/svg/eNorzs7MK0gsSsxVyM3Py0_OKMrPTVUoKSpN5eJKzMlMTlXQtVNIyk-yUshIzcnJBwCT9xBc" alt="Diagram">
|
48
96
|
</div>
|
49
97
|
</div>)
|
50
98
|
end
|
@@ -55,10 +103,10 @@ describe ::AsciidoctorExtensions::KrokiBlockProcessor do
|
|
55
103
|
alice -> bob: hello
|
56
104
|
....
|
57
105
|
ADOC
|
58
|
-
output = Asciidoctor.convert(input, attributes: { '
|
106
|
+
output = Asciidoctor.convert(input, attributes: { 'kroki-plantuml-include' => '../../../spec/fixtures/config.puml' }, standalone: false, safe: :safe)
|
59
107
|
(expect output).to eql %(<div class="imageblock kroki">
|
60
108
|
<div class="content">
|
61
|
-
<img src="https://kroki.io/plantuml/
|
109
|
+
<img src="https://kroki.io/plantuml/svg/eNorzs7MK0gsSsxVyM3Py0_OKMrPTVUoKSpN5eJKzMlMTlXQtVNIyk-yUshIzcnJBwCT9xBc" alt="Diagram">
|
62
110
|
</div>
|
63
111
|
</div>)
|
64
112
|
end
|
@@ -69,10 +117,10 @@ describe ::AsciidoctorExtensions::KrokiBlockProcessor do
|
|
69
117
|
alice -> bob: hello
|
70
118
|
....
|
71
119
|
ADOC
|
72
|
-
output = Asciidoctor.convert(input, attributes: { '
|
120
|
+
output = Asciidoctor.convert(input, attributes: { 'kroki-plantuml-include' => '/etc/passwd' }, standalone: false, safe: :safe)
|
73
121
|
(expect output).to eql %(<div class="imageblock kroki">
|
74
122
|
<div class="content">
|
75
|
-
<img src="https://kroki.io/plantuml/
|
123
|
+
<img src="https://kroki.io/plantuml/svg/eNpLzMlMTlXQtVNIyk-yUshIzcnJBwA9iwZL" alt="Diagram">
|
76
124
|
</div>
|
77
125
|
</div>)
|
78
126
|
end
|
@@ -83,10 +131,10 @@ describe ::AsciidoctorExtensions::KrokiBlockProcessor do
|
|
83
131
|
alice -> bob: hello
|
84
132
|
....
|
85
133
|
ADOC
|
86
|
-
output = Asciidoctor.convert(input, attributes: { '
|
134
|
+
output = Asciidoctor.convert(input, attributes: { 'kroki-plantuml-include' => 'spec/fixtures/config.puml' }, standalone: false, safe: :secure)
|
87
135
|
(expect output).to eql %(<div class="imageblock kroki">
|
88
136
|
<div class="content">
|
89
|
-
<img src="https://kroki.io/plantuml/
|
137
|
+
<img src="https://kroki.io/plantuml/svg/eNpLzMlMTlXQtVNIyk-yUshIzcnJBwA9iwZL" alt="Diagram">
|
90
138
|
</div>
|
91
139
|
</div>)
|
92
140
|
end
|
@@ -130,12 +178,23 @@ describe ::AsciidoctorExtensions::KrokiBlockProcessor do
|
|
130
178
|
</div>)
|
131
179
|
end
|
132
180
|
end
|
181
|
+
context 'instantiate' do
|
182
|
+
it 'should instantiate block processor without warning' do
|
183
|
+
original_stderr = $stderr
|
184
|
+
$stderr = StringIO.new
|
185
|
+
::AsciidoctorExtensions::KrokiBlockProcessor.new :plantuml, {}
|
186
|
+
output = $stderr.string
|
187
|
+
(expect output).to eql ''
|
188
|
+
ensure
|
189
|
+
$stderr = original_stderr
|
190
|
+
end
|
191
|
+
end
|
133
192
|
end
|
134
193
|
|
135
194
|
describe ::AsciidoctorExtensions::Kroki do
|
136
195
|
it 'should return the list of supported diagrams' do
|
137
196
|
diagram_names = ::AsciidoctorExtensions::Kroki::SUPPORTED_DIAGRAM_NAMES
|
138
|
-
expect(diagram_names).to include('vegalite', 'plantuml', 'bytefield', 'bpmn', 'excalidraw', 'wavedrom')
|
197
|
+
expect(diagram_names).to include('vegalite', 'plantuml', 'bytefield', 'bpmn', 'excalidraw', 'wavedrom', 'pikchr', 'structurizr')
|
139
198
|
end
|
140
199
|
it 'should register the extension for the list of supported diagrams' do
|
141
200
|
doc = Asciidoctor::Document.new
|
Binary file
|
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.
|
4
|
+
version: 0.7.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:
|
11
|
+
date: 2022-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -30,42 +30,42 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 13.0.6
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 13.0.6
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 3.
|
47
|
+
version: 3.10.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 3.
|
54
|
+
version: 3.10.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rubocop
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '1.30'
|
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.30'
|
69
69
|
description: An extension for Asciidoctor to convert diagrams to images using https://kroki.io
|
70
70
|
email:
|
71
71
|
- ggrossetie@yuzutech.fr
|
@@ -84,13 +84,16 @@ files:
|
|
84
84
|
- lib/asciidoctor-kroki.rb
|
85
85
|
- lib/asciidoctor/extensions/asciidoctor_kroki.rb
|
86
86
|
- lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb
|
87
|
+
- lib/asciidoctor/extensions/asciidoctor_kroki/version.rb
|
87
88
|
- spec/.rubocop.yml
|
88
89
|
- spec/asciidoctor_kroki_block_macro_spec.rb
|
89
90
|
- spec/asciidoctor_kroki_client_spec.rb
|
90
91
|
- spec/asciidoctor_kroki_diagram_spec.rb
|
92
|
+
- spec/asciidoctor_kroki_processor_spec.rb
|
91
93
|
- spec/asciidoctor_kroki_spec.rb
|
92
94
|
- spec/fixtures/alice.puml
|
93
95
|
- spec/fixtures/config.puml
|
96
|
+
- spec/fixtures/plantuml-diagram.png
|
94
97
|
- spec/require_spec.rb
|
95
98
|
- spec/rspec_helper.rb
|
96
99
|
- tasks/bundler.rake
|
@@ -102,6 +105,7 @@ licenses:
|
|
102
105
|
metadata:
|
103
106
|
bug_tracker_uri: https://github.com/Mogztter/asciidoctor-kroki/issues
|
104
107
|
source_code_uri: https://github.com/Mogztter/asciidoctor-kroki
|
108
|
+
rubygems_mfa_required: 'true'
|
105
109
|
post_install_message:
|
106
110
|
rdoc_options: []
|
107
111
|
require_paths:
|
@@ -117,20 +121,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
121
|
- !ruby/object:Gem::Version
|
118
122
|
version: '0'
|
119
123
|
requirements: []
|
120
|
-
rubygems_version: 3.
|
124
|
+
rubygems_version: 3.1.6
|
121
125
|
signing_key:
|
122
126
|
specification_version: 4
|
123
127
|
summary: Asciidoctor extension to convert diagrams to images using Kroki
|
124
|
-
test_files:
|
125
|
-
- spec/.rubocop.yml
|
126
|
-
- spec/asciidoctor_kroki_block_macro_spec.rb
|
127
|
-
- spec/asciidoctor_kroki_client_spec.rb
|
128
|
-
- spec/asciidoctor_kroki_diagram_spec.rb
|
129
|
-
- spec/asciidoctor_kroki_spec.rb
|
130
|
-
- spec/fixtures/alice.puml
|
131
|
-
- spec/fixtures/config.puml
|
132
|
-
- spec/require_spec.rb
|
133
|
-
- spec/rspec_helper.rb
|
134
|
-
- tasks/bundler.rake
|
135
|
-
- tasks/lint.rake
|
136
|
-
- tasks/rspec.rake
|
128
|
+
test_files: []
|