Skip to content

Commit

Permalink
Add support for the PlantUML Smetana layout engine
Browse files Browse the repository at this point in the history
  • Loading branch information
pepijnve committed Feb 4, 2024
1 parent a52b5f9 commit 1f29346
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
= Asciidoctor-diagram Changelog

== 2.2.18

Enhancements::

* Add opt-in support for the PlantUML Smetana layout engine

== 2.2.17

Bugfixes::
Expand Down
1 change: 1 addition & 0 deletions docs/modules/ROOT/pages/diagram_types/plantuml.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ It is particularly well-suited for users who prefer a simple, text-based approac
|size-limit |4096 |The maximum dimensions (width and height) of generated diagrams.
|includedir |unspecified |sets a common directory for puml includes (plantuml.include.path)
|preprocess |true |Preprocess PlantUML code before rendering the diagram.
|options |unspecified |a comma separate list of flags that modify the image rendering. Currently only `smetana` is supported which enables the Smetana layout engine.
|===
14 changes: 10 additions & 4 deletions lib/asciidoctor-diagram/plantuml/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ def supported_formats

def collect_options(source)
options = {
:size_limit => source.attr('size-limit', '4096')
:size_limit => source.attr('size-limit', '4096'),
}

options[:smetana] = true if source.opt('smetana')

theme = source.attr('theme', nil)
options[:theme] = theme if theme

Expand Down Expand Up @@ -106,9 +108,13 @@ def convert(source, format, options)
add_theme_header(headers, options[:theme])
add_size_limit_header(headers, options[:size_limit])

dot = source.find_command('dot', :alt_attrs => ['graphvizdot'], :raise_on_error => false)
if dot
headers['X-Graphviz'] = ::Asciidoctor::Diagram::Platform.host_os_path(dot)
if options[:smetana]
headers['X-Graphviz'] = 'smetana'
else
dot = source.find_command('dot', :alt_attrs => ['graphvizdot'], :raise_on_error => false)
if dot
headers['X-Graphviz'] = ::Asciidoctor::Diagram::Platform.host_os_path(dot)
end
end

response = Java.send_request(
Expand Down
Binary file removed lib/asciidoctor-diagram/plantuml/plantuml-2.0.0.jar
Binary file not shown.
Binary file not shown.
24 changes: 24 additions & 0 deletions spec/plantuml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -835,4 +835,28 @@ class {child-class}
expect(b.attributes['width']).to_not be_nil
expect(b.attributes['height']).to_not be_nil
end

it 'should support the Smetana layout engine' do
doc = <<-eos
= Hello, Smetana!
Doc Writer <doc@example.com>
== First Section
[plantuml, format="png", target="unscaled", opts="smetana"]
----
#{PLANTUML_CODE}
----
eos

d = load_asciidoc doc, :attributes => {'backend' => 'html5'}
b = d.find { |bl| bl.context == :image }

target = b.attributes['target']
expect(target).to_not be_nil
expect(File.exist?(target)).to be true

expect(b.attributes['width']).to_not be_nil
expect(b.attributes['height']).to_not be_nil
end
end

0 comments on commit 1f29346

Please sign in to comment.