asciidoctor / asciidoctor-diagram

:left_right_arrow: Asciidoctor diagram extension, with support for AsciiToSVG, BlockDiag (BlockDiag, SeqDiag, ActDiag, NwDiag), Ditaa, Erd, GraphViz, Mermaid, Msc, PlantUML, Shaape, SvgBob, Syntrax, UMLet, Vega, Vega-Lite and WaveDrom.
http://asciidoctor.org
MIT License
435 stars 106 forks source link

Feature request: PlantUML `?=` syntax support #353

Closed HeinrichAD closed 3 years ago

HeinrichAD commented 3 years ago

PlantUML supports to assign a value to a variable, only if it is not already defined, with the syntax !$a ?= "foo".

!$a ?= "foo" could be considered the short form of the following:

!if %not(%variable_exists("$a"))
  !$a = "foo"
!endif

Since there is a workaround, this is prio low, but once you start working with a lot of customizable parameters, it's pretty annoying and the code gets messy quickly.

References

Documentation: https://plantuml.com/preprocessing#788fa5fb2276ed17

Example below in action: PlantUML Online Example

Example

= Test

[plantuml]
----
@startuml
Alice -> Bob : 1. **$name** should be empty

!$name ?= "Charlie"
Alice -> Bob : 2. **$name** should be Charlie

!$name = "David"
Alice -> Bob : 3. **$name** should be David

!$name ?= "Ethan"
Alice -> Bob : 4. **$name** should be David
@enduml
----

Expected

image

Actual

Syntax Error

``` > asciidoctor -r asciidoctor-diagram --failure-level ERROR -b xhtml5 -a data-uri -D generated test.adoc asciidoctor: ERROR: test.adoc: line 5: Failed to generate image: PlantUML preprocessing failed: [From (line 4) ] @startuml Alice -> Bob : 1. **$name** should be empty !$name ?= "Charlie" ^^^^^ Syntax Error? asciidoctor: FAILED: /documents/test.adoc: Failed to load AsciiDoc document - PlantUML preprocessing failed: [From (line 4) ] @startuml Alice -> Bob : 1. **$name** should be empty !$name ?= "Charlie" ^^^^^ Syntax Error? (RuntimeError) Use --trace for backtrace ```
pepijnve commented 3 years ago

This seems to have been added in a recent version of PlantUML. The currently bundled version is 1.2021.2. I've updated the gem containing the PlantUML jar to 1.2021.5. Could you update the gem on your end and retest?

HeinrichAD commented 3 years ago

Thank you. I confirm the functionality. It's working without issues.

Example of above with asciidoctor-diagram. ![image](https://user-images.githubusercontent.com/5962361/117679934-ff44ee00-b1b0-11eb-861e-f2fc6e84fed0.png)