diff --git a/ruby/lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb b/ruby/lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb
index bc145cd0..ae3d9c71 100644
--- a/ruby/lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb
+++ b/ruby/lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb
@@ -272,7 +272,7 @@ class KrokiDiagram
attr_reader :type, :text, :format, :target
- def initialize(type, format, text, target)
+ def initialize(type, format, text, target = nil)
@text = text
@type = type
@format = format
diff --git a/ruby/spec/asciidoctor_kroki_diagram_spec.rb b/ruby/spec/asciidoctor_kroki_diagram_spec.rb
index f4a88275..13321d47 100644
--- a/ruby/spec/asciidoctor_kroki_diagram_spec.rb
+++ b/ruby/spec/asciidoctor_kroki_diagram_spec.rb
@@ -32,7 +32,28 @@
output_dir_path = "#{__dir__}/../.asciidoctor/kroki"
diagram_name = kroki_diagram.save(output_dir_path, kroki_client)
diagram_path = File.join(output_dir_path, diagram_name)
- expect(File.exist?(diagram_path)).to be_truthy, "expected diagram to be saved at #{diagram_path}"
+ expect(File.exist?(diagram_path)).to be_truthy, "diagram should be saved at: #{diagram_path}"
+ content = <<-TXT.chomp
+ ,-----. ,---.
+ |alice| |bob|
+ `--+--' `-+-'
+ | hello |
+ |-------------->|
+ ,--+--. ,-+-.
+ |alice| |bob|
+ `-----' `---'
+ TXT
+ expect(File.read(diagram_path).split("\n").map(&:rstrip).join("\n")).to eq(content)
+ end
+ it 'should fetch a diagram from Kroki and save it to disk using the target name' do
+ kroki_diagram = ::AsciidoctorExtensions::KrokiDiagram.new('plantuml', 'txt', ' alice -> bob: hello', 'hello-world')
+ kroki_http_client = ::AsciidoctorExtensions::KrokiHttpClient
+ kroki_client = ::AsciidoctorExtensions::KrokiClient.new(server_url: 'https://kroki.io', http_method: 'get', http_client: kroki_http_client)
+ output_dir_path = "#{__dir__}/../.asciidoctor/kroki"
+ diagram_name = kroki_diagram.save(output_dir_path, kroki_client)
+ diagram_path = File.join(output_dir_path, diagram_name)
+ expect(diagram_name).to start_with('hello-world-'), "diagram name should use the target as a prefix, got: #{diagram_name}"
+ expect(File.exist?(diagram_path)).to be_truthy, "diagram should be saved at: #{diagram_path}"
content = <<-TXT.chomp
,-----. ,---.
|alice| |bob|
@@ -55,9 +76,9 @@
expect(kroki_http_client).to receive(:get).once.and_return(diagram_contents)
diagram_name = kroki_diagram.save(output_dir_path, kroki_client)
diagram_path = File.join(output_dir_path, diagram_name)
- expect(File.exist?(diagram_path)).to be_truthy, "expected diagram to be saved at #{diagram_path}"
+ expect(File.exist?(diagram_path)).to be_truthy, "diagram should be saved at: #{diagram_path}"
# calling again... should read the file from disk (and not do a GET request)
kroki_diagram.save(output_dir_path, kroki_client)
- expect(File.size(diagram_path)).to be_eql(diagram_contents.length), 'expected diagram to be fully saved on disk'
+ expect(File.size(diagram_path)).to be_eql(diagram_contents.length), 'diagram should be fully saved on disk'
end
end
diff --git a/test/antora/test.spec.js b/test/antora/test.spec.js
index 463c5bd4..1827f87f 100644
--- a/test/antora/test.spec.js
+++ b/test/antora/test.spec.js
@@ -20,7 +20,7 @@ describe('Antora integration', () => {
expect(imageElements.length).to.equal(6)
imageElements.each((i, imageElement) => {
const src = $(imageElement).attr('src')
- expect(src).to.startWith('_images/diag-')
+ expect(src).to.startWith('_images/ab-')
})
}).timeout(50000)
})
diff --git a/test/test.spec.js b/test/test.spec.js
index 617f1449..80cd2deb 100644
--- a/test/test.spec.js
+++ b/test/test.spec.js
@@ -240,7 +240,7 @@ Hello -> World
extension_registry: registry,
attributes: { 'kroki-fetch-diagram': true }
})
- expect(html).to.contain('')
+ expect(html).to.contain('')
}).timeout(5000)
it('should download and save an image to a local folder and generated name', () => {
const input = `