asciidoctor-diagram 2.2.7 → 2.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +13 -0
  3. data/README.adoc +3 -3
  4. data/docs/modules/ROOT/pages/index.adoc +1 -1
  5. data/docs/modules/ROOT/partials/advanced.adoc +19 -4
  6. data/docs/modules/ROOT/partials/create_diagram.adoc +1 -0
  7. data/docs/modules/ROOT/partials/uris.adoc +3 -1
  8. data/lib/asciidoctor-diagram/d2/converter.rb +12 -4
  9. data/lib/asciidoctor-diagram/dbml/converter.rb +22 -0
  10. data/lib/asciidoctor-diagram/dbml/extension.rb +18 -0
  11. data/lib/asciidoctor-diagram/dbml.rb +8 -0
  12. data/lib/asciidoctor-diagram/diagram_processor.rb +2 -0
  13. data/lib/asciidoctor-diagram/diagram_source.rb +2 -2
  14. data/lib/asciidoctor-diagram/ditaa/converter.rb +9 -3
  15. data/lib/asciidoctor-diagram/ditaa/ditaa-2.0.0.jar +0 -0
  16. data/lib/asciidoctor-diagram/plantuml/converter.rb +8 -3
  17. data/lib/asciidoctor-diagram/plantuml/plantuml-2.0.0.jar +0 -0
  18. data/lib/asciidoctor-diagram/structurizr/converter.rb +67 -0
  19. data/lib/asciidoctor-diagram/structurizr/extension.rb +52 -0
  20. data/lib/asciidoctor-diagram/structurizr/renderers.rb +58 -0
  21. data/lib/asciidoctor-diagram/structurizr/structurizr-2.0.1.jar +0 -0
  22. data/lib/asciidoctor-diagram/structurizr.rb +7 -0
  23. data/lib/asciidoctor-diagram/syntrax/converter.rb +64 -17
  24. data/lib/asciidoctor-diagram/syntrax/syntrax-2.0.2.jar +0 -0
  25. data/lib/asciidoctor-diagram/util/cli.rb +10 -2
  26. data/lib/asciidoctor-diagram/util/cli_generator.rb +1 -0
  27. data/lib/asciidoctor-diagram/util/server-2.0.0.jar +0 -0
  28. data/lib/asciidoctor-diagram/version.rb +1 -1
  29. data/lib/asciidoctor-diagram.rb +2 -0
  30. data/spec/d2_spec.rb +23 -0
  31. data/spec/dbml_spec.rb +32 -0
  32. data/spec/plantuml_spec.rb +1 -1
  33. data/spec/shared_examples.rb +2 -2
  34. metadata +26 -10
  35. data/lib/asciidoctor-diagram/ditaa/ditaa-1.3.21.jar +0 -0
  36. data/lib/asciidoctor-diagram/plantuml/plantuml-1.3.24.jar +0 -0
  37. data/lib/asciidoctor-diagram/util/server-1.3.21.jar +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d16a4ceac53c9b8aa223e3b22a061ee0c92cc6876b24522c224530f7559c6d9
4
- data.tar.gz: 86d434f86830db71ea4369b2e1e08d05b0ca8d6ed8f3ed4927c90cb5458f0154
3
+ metadata.gz: ea06a8ee298a0f1331527d528d1e03bb3e018dda9c0dc69fa52506fb086e6b48
4
+ data.tar.gz: 26d12a8dd4da3cd38a6007d8e569b05892159c79c9538d99f3958d91be4792a2
5
5
  SHA512:
6
- metadata.gz: d365c1149d8b2d7ce00a0aecdf0d40435518aeda247448adb4bfe81bc7b4c9cefe69477c3c3a6e3cb1fcbd703dc7efe2ad4e519d49aa4f32a10a51ecf523eaab
7
- data.tar.gz: 567f9ba04c8bb97e09e6e2d70bfde26cd51700777257a5dd8a7a683ce101f6b0341f00d6729d12116400b620f38d5f4b3bea1113623641989c9d44a26110c04b
6
+ metadata.gz: e81762d1af76136b66f1d35fb60aa5ebdcdd2fca3ff9d09cbf59d36485ea82b7d8eab3c4656fb236ebbadd07975b545e1d1ed7e0a205e3d50d28a6377f9f8cc5
7
+ data.tar.gz: 6e2a003aa9049b72d12b6e5f82dec010029bb6b2e9ccf31c4e66951e6a3beb90694601769c452a2535cef8e891736a7c633aefde39c477647eef3febfcb7427a
data/CHANGELOG.adoc CHANGED
@@ -1,5 +1,17 @@
1
1
  = Asciidoctor-diagram Changelog
2
2
 
3
+ == 2.2.8
4
+
5
+ Enhancements::
6
+
7
+ * Add support for reusing JSyntrax subprocess instances to improve performance when rendering many syntax diagrams (@gitrbond, @inponomarev)
8
+ * Issue #386: Add basic https://structurizr.com[Structurizr] support
9
+
10
+ Bugfixes::
11
+
12
+ * Issue #409: Fix handling of the D2 `sketch` attribute
13
+ * Issue #410: Ensure current directory is always set to document base directory when invoking subprocesses
14
+
3
15
  == 2.2.7
4
16
 
5
17
  Enhancements::
@@ -25,6 +37,7 @@ Enhancements::
25
37
  Enhancements::
26
38
 
27
39
  * Issue #399: Add support for PlantUML theme attribute
40
+ * Add DBML support via https://github.com/softwaretechnik-berlin/dbml-renderer[dbml-renderer]
28
41
 
29
42
  == 2.2.3
30
43
 
data/README.adoc CHANGED
@@ -3,8 +3,8 @@ Pepijn Van_Eeckhoudt <https://github.com/pepijnve[@pepijnve]>; Sarah White <http
3
3
  :description: README for the Asciidoctor Diagram extension for Asciidoctor.
4
4
 
5
5
  image:https://github.com/asciidoctor/asciidoctor-diagram/workflows/Linux%20unit%20tests/badge.svg?branch=master["Linux Build Status", link="https://github.com/asciidoctor/asciidoctor-diagram/actions?query=workflow%3A%22Linux+unit+tests%22"]
6
- image:https://github.com/asciidoctor/asciidoctor-diagram/workflows/macOS%20unit%20tests/badge.svg?branch=master["macOS Build Status", link="https://github.com/asciidoctor/asciidoctor-diagram/actions?query=workflow%3A%22macOS+unit+tests%22"]
7
- image:https://github.com/asciidoctor/asciidoctor-diagram/workflows/Windows%20unit%20tests/badge.svg?branch=master["Windows Build Status", link="https://github.com/asciidoctor/asciidoctor-diagram/actions?query=workflow%3A%22Windows+unit+tests%22"]
6
+ // image:https://github.com/asciidoctor/asciidoctor-diagram/workflows/macOS%20unit%20tests/badge.svg?branch=master["macOS Build Status", link="https://github.com/asciidoctor/asciidoctor-diagram/actions?query=workflow%3A%22macOS+unit+tests%22"]
7
+ // image:https://github.com/asciidoctor/asciidoctor-diagram/workflows/Windows%20unit%20tests/badge.svg?branch=master["Windows Build Status", link="https://github.com/asciidoctor/asciidoctor-diagram/actions?query=workflow%3A%22Windows+unit+tests%22"]
8
8
  image:https://badge.fury.io/rb/asciidoctor-diagram.svg[Gem Version, link=https://rubygems.org/gems/asciidoctor-diagram]
9
9
 
10
10
  Asciidoctor Diagram is a set of Asciidoctor extensions that enable you to add diagrams, which you describe using plain text, to your AsciiDoc document.
@@ -38,4 +38,4 @@ The example below shows an embedded Ditaa diagram block.
38
38
 
39
39
  After processing by Asciidoctor, the output file will show a rendered version of the diagram instead of the diagram source code.
40
40
 
41
- image::docs/modules/ROOT/images/asciidoctor-diagram-process.png[]
41
+ image::docs/modules/ROOT/images/asciidoctor-diagram-process.png[]
@@ -5,7 +5,7 @@ include::partial$uris.adoc[]
5
5
 
6
6
  Asciidoctor Diagram is a set of Asciidoctor extensions that enable you to add diagrams, which you describe using plain text, to your AsciiDoc document.
7
7
 
8
- The extensions support the {uri-a2s}[AsciiToSVG], BlockDiag ({uri-blockdiag}[BlockDiag], {uri-seqdiag}[SeqDiag], {uri-actdiag}[ActDiag], {uri-nwdiag}[NwDiag]), {uri-bytefield}[Bytefield-SVG], {uri-ditaa}[Ditaa], {uri-dpic}[dpic], {uri-erd}[Erd], {uri-gnuplot}[Gnuplot], {uri-dot}[GraphViz], {uri-mermaid}[Mermaid], {uri-mscgen}[Msc], {uri-nomnoml}[Nomnoml], {uri-pikchr}[Pikchr], {uri-plantuml}[PlantUML], {uri-shaape}[Shaape], {uri-smcat}[State Machine Cat], {uri-svgbob}[SvgBob], {uri-symbolator}[Symbolator], {uri-syntrax}[Syntrax] / {uri-jsyntrax}[JSyntrax], {uri-umlet}[UMLet], {uri-vega}[Vega], {uri-vegalite}[Vega-Lite] and {uri-wavedrom}[WaveDrom] syntax.
8
+ The extensions support the {uri-a2s}[AsciiToSVG], BlockDiag ({uri-blockdiag}[BlockDiag], {uri-seqdiag}[SeqDiag], {uri-actdiag}[ActDiag], {uri-nwdiag}[NwDiag]), {uri-bytefield}[Bytefield-SVG], {uri-dbml}[DBML], {uri-ditaa}[Ditaa], {uri-dpic}[dpic], {uri-erd}[Erd], {uri-gnuplot}[Gnuplot], {uri-dot}[GraphViz], {uri-mermaid}[Mermaid], {uri-mscgen}[Msc], {uri-nomnoml}[Nomnoml], {uri-pikchr}[Pikchr], {uri-plantuml}[PlantUML], {uri-shaape}[Shaape], {uri-smcat}[State Machine Cat], {uri-structurizr}[Structurizr], {uri-svgbob}[SvgBob], {uri-symbolator}[Symbolator], {uri-syntrax}[Syntrax] / {uri-jsyntrax}[JSyntrax], {uri-umlet}[UMLet], {uri-vega}[Vega], {uri-vegalite}[Vega-Lite] and {uri-wavedrom}[WaveDrom] syntax.
9
9
 
10
10
  Each extension runs the diagram processor to generate an SVG, PNG, or TXT file from the input text.
11
11
  The generated file is then inserted into your converted document.
@@ -75,6 +75,7 @@ The following table lists the tools that are required for each diagram type, the
75
75
  |bytefield |{uri-bytefield}[bytefield-svg] |`bytefield-svg`
76
76
  |diagrams |{uri-python}[Python] |`diagrams-python`
77
77
  |D2 |{uri-d2}[D2] |`d2`
78
+ |DBML |{uri-dbml}[dbml-renderer] |`dbml-renderer`
78
79
  |ditaa |{uri-java}[Java] |`java`
79
80
  |dpic |{uri-dpic}[dpic] |`dpic`
80
81
  |erd |{uri-erd}[Erd] or {uri-erd-go}[Erd Go] |`erd`
@@ -92,9 +93,10 @@ The following table lists the tools that are required for each diagram type, the
92
93
  |seqdiag |{uri-seqdiag}[SeqDiag] |`seqdiag`
93
94
  |shaape |{uri-shaape}[Shaape] |`shaape`
94
95
  |smcat |{uri-smcat}[State Machine Cat] |`smcat`
96
+ |structurizr |{uri-java}[Java] and {uri-structurizr}[Structurizr CLI] |`java` and the `DIAGRAM_STRUCTURIZRCLI_HOME` environment variable
95
97
  |svgbob |{uri-svgbob}[SvgBob] |`svgbob`
96
98
  |symbolator |{uri-symbolator}[Symbolator] |`symbolator`
97
- |syntrax |{uri-syntrax}[Syntrax]/{uri-jsyntrax}[JSyntrax] |`syntrax`
99
+ |syntrax |{uri-syntrax}[Syntrax]/{uri-jsyntrax}[JSyntrax] |`syntrax` or `java` and the `DIAGRAM_JSYNTRAX_HOME` environment variable
98
100
  |tikz |A TeX distribution that supports {uri-tikz}[TikZ] |`pdflatex` and `pdf2svg`
99
101
  |umlet |{uri-umlet}[Umlet] |`umlet`
100
102
  |vega |{uri-vega}[vg2png] and/or {uri-vega}[vg2png] |`vg2png` and `vg2svg`
@@ -250,6 +252,10 @@ If the maximum size is exceeded, POST requests are used instead
250
252
  |font-bol |Source Sans Pro Bold |Path to .ttf file to use for the bold font
251
253
  |===
252
254
 
255
+ ==== DBML
256
+
257
+ No specific attributes.
258
+
253
259
  ==== Diagrams
254
260
 
255
261
  No specific attributes.
@@ -347,10 +353,19 @@ No specific attributes.
347
353
  [cols=">,<,<",options="header"]
348
354
  |===
349
355
  |Name |Default value |Description
350
- |direction |unspecifed |The direction of the state machine diagram. One of `top-down`, `bottom-top`, `left-right` or `right-left`.
356
+ |direction |unspecified |The direction of the state machine diagram. One of `top-down`, `bottom-top`, `left-right` or `right-left`.
351
357
  |engine |unspecified |The layout engine to use. One of `dot`, `circo`, `fdp`, `neato`, `osage`, or `twopi`
352
358
  |===
353
359
 
360
+ ==== Structurizr
361
+
362
+ [cols=">,<,<",options="header"]
363
+ |===
364
+ |Name |Default value |Description
365
+ |renderer |plantuml-c4 |The rendering backend to use. One of `d2`, `graphviz`, `mermaid`, `plantuml`, or `plantuml-c4`
366
+ |view |unspecified |The key of the view to render
367
+ |===
368
+
354
369
  ==== svgbob
355
370
 
356
371
  [cols=">,<,<",options="header"]
@@ -367,9 +382,9 @@ No specific attributes.
367
382
  [cols=">,<,<",options="header"]
368
383
  |===
369
384
  |Name |Default value |Description
370
- |heading |unspecifed |Diagram title
385
+ |heading |unspecified |Diagram title
371
386
  |scale |1 |A scale factor that is applied to the image.
372
- |style-file |unspecifed |Path to a style config file to pass to Syntrax.
387
+ |style-file |unspecified |Path to a style config file to pass to Syntrax.
373
388
  |transparent |false |Makes the background of the image transparent instead of opaque white.
374
389
  |===
375
390
 
@@ -46,6 +46,7 @@ The following diagram types and output formats are available:
46
46
  |{uri-seqdiag}[seqdiag] | |{check}|{check}|{check}|
47
47
  |{uri-shaape}[shaape] | | |{check}|{check}|
48
48
  |{uri-smcat}[smcat] | | | |{check}|
49
+ |{uri-structurizr}[structurizr] | | |{check}|{check}|
49
50
  |{uri-svgbob}[svgbob] | | | |{check}|{check}
50
51
  |{uri-symbolator}[symbolator] | |{check}|{check}|{check}|
51
52
  |{uri-syntrax}[syntrax] (Syntrax) | |{check}|{check}|{check}|
@@ -6,6 +6,7 @@
6
6
  :uri-bpmn: https://github.com/gtudan/bpmn-js-cmd
7
7
  :uri-bytefield: https://github.com/Deep-Symmetry/bytefield-svg
8
8
  :uri-d2: https://d2lang.com
9
+ :uri-dbml: https://github.com/softwaretechnik-berlin/dbml-renderer
9
10
  :uri-diagrams: https://diagrams.mingrammer.com
10
11
  :uri-ditaa: http://ditaa.sourceforge.net/
11
12
  :uri-dpic: https://gitlab.com/aplevich/dpic
@@ -16,6 +17,7 @@
16
17
  :uri-graphviz: https://graphviz.gitlab.io
17
18
  :uri-imagemagick: http://www.imagemagick.org
18
19
  :uri-java: http://java.sun.com
20
+ :uri-jsyntrax: https://atp-mipt.github.io/jsyntrax/
19
21
  :uri-mermaid: https://github.com/mermaid-js/mermaid-cli
20
22
  :uri-mscgen: http://www.mcternan.me.uk/mscgen/
21
23
  :uri-mscgen-js: https://github.com/mscgenjs/mscgenjs-cli
@@ -31,10 +33,10 @@
31
33
  :uri-seqdiag: http://blockdiag.com/en/seqdiag/index.html
32
34
  :uri-shaape: https://github.com/christiangoltz/shaape
33
35
  :uri-smcat: https://github.com/sverweij/state-machine-cat
36
+ :uri-structurizr: https://structurizr.com
34
37
  :uri-svgbob: https://github.com/ivanceras/svgbobrus
35
38
  :uri-symbolator: https://github.com/kevinpt/symbolator
36
39
  :uri-syntrax: https://kevinpt.github.io/syntrax/
37
- :uri-jsyntrax: https://atp-mipt.github.io/jsyntrax/
38
40
  :uri-tikz: https://github.com/pgf-tikz/pgf
39
41
  :uri-umlet: http://www.umlet.com/
40
42
  :uri-vega: https://vega.github.io/vega/
@@ -23,7 +23,7 @@ module Asciidoctor
23
23
  :font_regular => source.attr('font-regular'),
24
24
  :font_italic => source.attr('font-italic'),
25
25
  :font_bold => source.attr('font-bold')
26
- }.delete_if { |key, value| value.nil? }
26
+ }
27
27
  end
28
28
 
29
29
  def convert(source, format, options)
@@ -31,17 +31,25 @@ module Asciidoctor
31
31
  args = [tool_path, '--browser', 'false']
32
32
 
33
33
  options.each_pair do |key, value|
34
- args << "--#{key.to_s.gsub('_', '-')}"
34
+ flag = "--#{key.to_s.gsub('_', '-')}"
35
35
 
36
- if key.to_s.start_with?('font')
36
+ if key == :sketch && value != 'false'
37
+ args << flag
38
+ elsif key.to_s.start_with?('font') && !value.nil?
37
39
  args << Platform.native_path(value)
38
- else
40
+ elsif !value.nil?
41
+ args << flag
39
42
  args << value
40
43
  end
41
44
  end
42
45
 
43
46
  args << Platform.native_path(input_path)
44
47
  args << Platform.native_path(output_path)
48
+
49
+ {
50
+ :args => args,
51
+ :chdir => source.base_dir
52
+ }
45
53
  end
46
54
  end
47
55
  end
@@ -0,0 +1,22 @@
1
+ require_relative '../diagram_converter'
2
+ require_relative '../util/cli_generator'
3
+ require_relative '../util/platform'
4
+
5
+ module Asciidoctor
6
+ module Diagram
7
+ # @private
8
+ class DbmlConverter
9
+ include DiagramConverter
10
+ include CliGenerator
11
+
12
+
13
+ def supported_formats
14
+ [:svg]
15
+ end
16
+
17
+ def convert(source, format, options)
18
+ generate_stdin_stdout(source.find_command('dbml-renderer'), source.code)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ require_relative 'converter'
2
+ require_relative '../diagram_processor'
3
+
4
+ module Asciidoctor
5
+ module Diagram
6
+ class DbmlBlockProcessor < DiagramBlockProcessor
7
+ use_converter DbmlConverter
8
+ end
9
+
10
+ class DbmlBlockMacroProcessor < DiagramBlockMacroProcessor
11
+ use_converter DbmlConverter
12
+ end
13
+
14
+ class DbmlInlineMacroProcessor < DiagramInlineMacroProcessor
15
+ use_converter DbmlConverter
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ require 'asciidoctor/extensions'
2
+ require_relative 'dbml/extension'
3
+
4
+ Asciidoctor::Extensions.register do
5
+ block Asciidoctor::Diagram::DbmlBlockProcessor, :dbml
6
+ block_macro Asciidoctor::Diagram::DbmlBlockMacroProcessor, :dbml
7
+ inline_macro Asciidoctor::Diagram::DbmlInlineMacroProcessor, :dbml
8
+ end
@@ -356,6 +356,7 @@ module Asciidoctor
356
356
  include DiagramProcessor
357
357
 
358
358
  def self.inherited(subclass)
359
+ subclass.use_dsl
359
360
  subclass.name_positional_attributes ['target', 'format']
360
361
  subclass.contexts [:listing, :literal, :open]
361
362
  subclass.content_model :simple
@@ -374,6 +375,7 @@ module Asciidoctor
374
375
  include DiagramProcessor
375
376
 
376
377
  def self.inherited(subclass)
378
+ subclass.use_dsl
377
379
  subclass.name_positional_attributes ['format']
378
380
  end
379
381
 
@@ -50,7 +50,7 @@ module Asciidoctor
50
50
  # @return [String] the base directory against which relative paths in this diagram should be resolved
51
51
  # @abstract
52
52
  def base_dir
53
- attr('docdir', nil, true) || Dir.pwd
53
+ File.expand_path(attr('docdir', "", true))
54
54
  end
55
55
 
56
56
  # Alias for code
@@ -262,7 +262,7 @@ module Asciidoctor
262
262
  class FileSource < BasicSource
263
263
  def initialize(block_processor, parent_block, file_name, attributes)
264
264
  super(block_processor, parent_block, attributes)
265
- @file_name = file_name
265
+ @file_name = File.expand_path(file_name)
266
266
  end
267
267
 
268
268
  def base_dir
@@ -32,12 +32,14 @@ module Asciidoctor
32
32
  require 'asciidoctor-diagram/ditaa/classpath'
33
33
  ::Asciidoctor::Diagram::DitaaClasspath::JAR_FILES
34
34
  rescue LoadError
35
- raise "Could not load Ditaa. Eiter require 'asciidoctor-diagram-ditaamini' or specify the location of the Ditaa JAR(s) using the 'DIAGRAM_DITAA_CLASSPATH' environment variable."
35
+ nil
36
36
  end
37
37
  end
38
38
 
39
- Java.classpath.concat Dir[File.join(File.dirname(__FILE__), '*.jar')]
40
- Java.classpath.concat DITAA_JARS
39
+ if DITAA_JARS
40
+ Java.classpath.concat Dir[File.join(File.dirname(__FILE__), '*.jar')]
41
+ Java.classpath.concat DITAA_JARS
42
+ end
41
43
 
42
44
  def supported_formats
43
45
  [:png, :svg, :txt]
@@ -61,6 +63,10 @@ module Asciidoctor
61
63
  def convert(source, format, options)
62
64
  return source.to_s if format == :txt
63
65
 
66
+ unless DITAA_JARS
67
+ raise "Could not load Ditaa. Either require 'asciidoctor-diagram-ditaamini' or specify the location of the Ditaa JAR(s) using the 'DIAGRAM_DITAA_CLASSPATH' environment variable."
68
+ end
69
+
64
70
  Java.load
65
71
 
66
72
  flags = []
@@ -17,12 +17,14 @@ module Asciidoctor
17
17
  require 'asciidoctor-diagram/plantuml/classpath'
18
18
  ::Asciidoctor::Diagram::PlantUmlClasspath::JAR_FILES
19
19
  rescue LoadError
20
- raise "Could not load PlantUML. Eiter require 'asciidoctor-diagram-plantuml' or specify the location of the PlantUML JAR(s) using the 'DIAGRAM_PLANTUML_CLASSPATH' environment variable."
20
+ nil
21
21
  end
22
22
  end
23
23
 
24
- Java.classpath.concat Dir[File.join(File.dirname(__FILE__), '*.jar')].freeze
25
- Java.classpath.concat PLANTUML_JARS
24
+ if PLANTUML_JARS
25
+ Java.classpath.concat Dir[File.join(File.dirname(__FILE__), '*.jar')].freeze
26
+ Java.classpath.concat PLANTUML_JARS
27
+ end
26
28
 
27
29
  def wrap_source(source)
28
30
  PlantUMLPreprocessedSource.new(source, self)
@@ -72,6 +74,9 @@ module Asciidoctor
72
74
  end
73
75
 
74
76
  def convert(source, format, options)
77
+ unless PLANTUML_JARS
78
+ raise "Could not load PlantUML. Either require 'asciidoctor-diagram-plantuml' or specify the location of the PlantUML JAR(s) using the 'DIAGRAM_PLANTUML_CLASSPATH' environment variable."
79
+ end
75
80
  Java.load
76
81
 
77
82
  code = source.code
@@ -0,0 +1,67 @@
1
+ require 'set'
2
+
3
+ require_relative '../diagram_converter'
4
+ require_relative '../diagram_processor'
5
+ require_relative '../plantuml/converter'
6
+ require_relative '../util/java'
7
+
8
+ module Asciidoctor
9
+ module Diagram
10
+ # @private
11
+ class StructurizrConverter
12
+ include DiagramConverter
13
+
14
+ CLASSPATH_ENV = 'DIAGRAM_STRUCTURIZR_CLASSPATH'
15
+ CLI_HOME_ENV = 'DIAGRAM_STRUCTURIZRCLI_HOME'
16
+ STRUCTURIZR_JARS = if ENV.has_key?(CLASSPATH_ENV)
17
+ ENV[CLASSPATH_ENV].split(File::PATH_SEPARATOR)
18
+ elsif ENV.has_key?(CLI_HOME_ENV)
19
+ lib_dir = File.expand_path('lib', ENV[CLI_HOME_ENV])
20
+ Dir.children(lib_dir).select { |c| c.end_with? '.jar' }.map { |c| File.expand_path(c, lib_dir) }
21
+ else
22
+ nil
23
+ end
24
+
25
+ if STRUCTURIZR_JARS
26
+ Java.classpath.concat Dir[File.join(File.dirname(__FILE__), '*.jar')]
27
+ Java.classpath.concat STRUCTURIZR_JARS
28
+ end
29
+
30
+ def supported_formats
31
+ [:txt]
32
+ end
33
+
34
+ def collect_options(source)
35
+ {
36
+ :view => source.attr('view'),
37
+ :renderer => Renderers.get_renderer_type(source)
38
+ }
39
+ end
40
+
41
+ def convert(source, format, options)
42
+ unless STRUCTURIZR_JARS
43
+ raise "Could not load Structurizr. Specify the location of the Structurizr JAR(s) using the 'DIAGRAM_STRUCTURIZRCLI_HOME' or DIAGRAM_STRUCTURIZR_CLASSPATH' environment variable."
44
+ end
45
+
46
+ Java.load
47
+
48
+ headers = {
49
+ 'Accept' => Renderers.mime_type(options[:renderer])
50
+ }
51
+ headers['X-Structurizr-View'] = options[:view] if options[:view]
52
+
53
+ response = Java.send_request(
54
+ :url => '/structurizr',
55
+ :body => source.to_s,
56
+ :headers => headers
57
+ )
58
+
59
+ unless response[:code] == 200
60
+ raise Java.create_error("Structurizr code generation failed", response)
61
+ end
62
+
63
+ response[:body].force_encoding(Encoding::UTF_8)
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,52 @@
1
+ require_relative 'converter'
2
+ require_relative 'renderers.rb'
3
+ require_relative '../diagram_processor'
4
+
5
+ module Asciidoctor
6
+ module Diagram
7
+
8
+ class StructurizrConvertBlockProcessor < DiagramBlockProcessor
9
+ use_converter StructurizrConverter
10
+ end
11
+
12
+ class StructurizrBlockProcessor < Asciidoctor::Extensions::BlockProcessor
13
+ DiagramBlockProcessor.inherited(self)
14
+
15
+ def initialize(name = nil, config = nil)
16
+ super
17
+ @structurizr = StructurizrConvertBlockMacroProcessor.new(name)
18
+ @renderers = Renderers.new(name)
19
+ end
20
+
21
+ def process parent, reader, attributes
22
+ structurizr_attrs = attributes.dup
23
+ structurizr_attrs['format'] = 'txt'
24
+
25
+ renderer_block = @structurizr.process(parent, reader, structurizr_attrs)
26
+ @renderers.get_renderer(BasicSource.new(self, parent, attributes)).process(parent, renderer_block, attributes)
27
+ end
28
+ end
29
+
30
+ class StructurizrConvertBlockMacroProcessor < DiagramBlockMacroProcessor
31
+ use_converter StructurizrConverter
32
+ end
33
+
34
+ class StructurizrBlockMacroProcessor < Asciidoctor::Extensions::BlockMacroProcessor
35
+ DiagramBlockMacroProcessor.inherited(self)
36
+
37
+ def initialize(name = nil, config = nil)
38
+ super
39
+ @structurizr = StructurizrConvertBlockMacroProcessor.new(name)
40
+ @renderers = Renderers.new(name)
41
+ end
42
+
43
+ def process parent, target, attributes
44
+ structurizr_attrs = attributes.dup
45
+ structurizr_attrs['format'] = 'txt'
46
+
47
+ renderer_block = @structurizr.process(parent, target, structurizr_attrs)
48
+ @renderers.get_renderer(BasicSource.new(self, parent, attributes)).process(parent, renderer_block, attributes)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,58 @@
1
+ module Asciidoctor
2
+ module Diagram
3
+ class Renderers
4
+ D2 = 'd2'
5
+ GRAPHVIZ = 'graphviz'
6
+ MERMAID = 'mermaid'
7
+ PLANTUML_C4 = 'plantuml-c4'
8
+ PLANTUML = 'plantuml'
9
+ DEFAULT_RENDERER = PLANTUML_C4
10
+
11
+ def initialize(name)
12
+ @d2 = D2BlockProcessor.new(name)
13
+ @graphviz = GraphvizBlockProcessor.new(name)
14
+ @plantuml = PlantUmlBlockProcessor.new(name)
15
+ @mermaid = MermaidBlockProcessor.new(name)
16
+ end
17
+
18
+ def renderer(renderer_type)
19
+ case renderer_type
20
+ when D2
21
+ @d2
22
+ when GRAPHVIZ
23
+ @graphviz
24
+ when MERMAID
25
+ @mermaid
26
+ when PLANTUML, PLANTUML_C4
27
+ @plantuml
28
+ else
29
+ raise "Unsupported renderer: '#{renderer_type}'"
30
+ end
31
+ end
32
+
33
+ def get_renderer(source)
34
+ renderer(Renderers.get_renderer_type(source))
35
+ end
36
+
37
+ def self.get_renderer_type(source)
38
+ source.attr('renderer', 'plantuml-c4')
39
+ end
40
+ def self.mime_type(renderer_type)
41
+ case renderer_type
42
+ when D2
43
+ 'text/x-d2'
44
+ when GRAPHVIZ
45
+ 'text/vnd.graphviz'
46
+ when MERMAID
47
+ 'text/x-mermaid'
48
+ when PLANTUML
49
+ 'text/x-plantuml'
50
+ when PLANTUML_C4
51
+ 'text/x-plantuml-c4'
52
+ else
53
+ raise "Unsupported renderer: '#{renderer_type}'"
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,7 @@
1
+ require 'asciidoctor/extensions'
2
+ require_relative 'structurizr/extension'
3
+
4
+ Asciidoctor::Extensions.register do
5
+ block Asciidoctor::Diagram::StructurizrBlockProcessor, :structurizr
6
+ block_macro Asciidoctor::Diagram::StructurizrBlockMacroProcessor, :structurizr
7
+ end
@@ -9,6 +9,21 @@ module Asciidoctor
9
9
  include DiagramConverter
10
10
  include CliGenerator
11
11
 
12
+ CLASSPATH_ENV = 'DIAGRAM_JSYNTRAX_CLASSPATH'
13
+ CLI_HOME_ENV = 'DIAGRAM_JSYNTRAX_HOME'
14
+ JSYNTRAX_JARS = if ENV.has_key?(CLASSPATH_ENV)
15
+ ENV[CLASSPATH_ENV].split(File::PATH_SEPARATOR)
16
+ elsif ENV.has_key?(CLI_HOME_ENV)
17
+ lib_dir = File.expand_path('lib', ENV[CLI_HOME_ENV])
18
+ Dir.children(lib_dir).select { |c| c.end_with? '.jar' }.map { |c| File.expand_path(c, lib_dir) }
19
+ else
20
+ nil
21
+ end
22
+
23
+ if JSYNTRAX_JARS
24
+ Java.classpath.concat Dir[File.join(File.dirname(__FILE__), '*.jar')]
25
+ Java.classpath.concat JSYNTRAX_JARS
26
+ end
12
27
 
13
28
  def supported_formats
14
29
  [:png, :svg]
@@ -24,30 +39,62 @@ module Asciidoctor
24
39
  end
25
40
 
26
41
  def convert(source, format, options)
27
- generate_file(source.find_command('syntrax'), 'spec', format.to_s, source.to_s) do |tool_path, input_path, output_path|
28
- args = [tool_path, '-i', Platform.native_path(input_path), '-o', Platform.native_path(output_path)]
42
+ shared_args = []
43
+ title = options[:heading]
44
+ if title
45
+ shared_args << '--title' << title
46
+ end
29
47
 
30
- title = options[:heading]
31
- if title
32
- args << '--title' << title
33
- end
48
+ scale = options[:scale]
49
+ if scale
50
+ shared_args << '--scale' << scale
51
+ end
34
52
 
35
- scale = options[:scale]
36
- if scale
37
- args << '--scale' << scale
38
- end
53
+ transparent = options[:transparent]
54
+ if transparent == 'true'
55
+ shared_args << '--transparent'
56
+ end
57
+ style = options[:style]
58
+ if style
59
+ shared_args << '--style' << style
60
+ end
39
61
 
40
- transparent = options[:transparent]
41
- if transparent == 'true'
42
- args << '--transparent'
62
+ if JSYNTRAX_JARS
63
+ Java.load
64
+
65
+ options_string = shared_args.join(' ')
66
+
67
+ case format
68
+ when :png
69
+ mime_type = 'image/png'
70
+ when :svg
71
+ mime_type = 'image/svg+xml'
72
+ else
73
+ raise "Unsupported format: #{format}"
43
74
  end
44
- style = options[:style]
45
- if style
46
- args << '--style' << style
75
+
76
+ headers = {
77
+ 'Accept' => mime_type,
78
+ 'X-Options' => options_string
79
+ }
80
+
81
+ response = Java.send_request(
82
+ :url => '/syntrax',
83
+ :body => source.to_s,
84
+ :headers => headers
85
+ )
86
+
87
+ unless response[:code] == 200
88
+ raise Java.create_error("JSyntrax code generation failed", response)
47
89
  end
48
90
 
49
- args
91
+ response[:body]
92
+ else
93
+ generate_file(source.find_command('syntrax'), 'spec', format.to_s, source.to_s) do |tool_path, input_path, output_path|
94
+ [tool_path, '-i', Platform.native_path(input_path), '-o', Platform.native_path(output_path)] + shared_args
95
+ end
50
96
  end
97
+
51
98
  end
52
99
 
53
100
  def native_scaling?
@@ -9,8 +9,13 @@ module Asciidoctor
9
9
  require_relative 'java'
10
10
 
11
11
  def self.run(*args)
12
- opts = args.pop.dup if args.last.is_a? Hash
13
- in_data = opts && opts[:stdin_data]
12
+ if args.last.is_a? Hash
13
+ opts = args.pop.dup
14
+ else
15
+ opts = {}
16
+ end
17
+
18
+ in_data = opts[:stdin_data]
14
19
 
15
20
  if Hash === args.first
16
21
  env = args.shift.dup
@@ -19,6 +24,9 @@ module Asciidoctor
19
24
  end
20
25
 
21
26
  pb = java.lang.ProcessBuilder.new(*args)
27
+
28
+ pb.directory(java.io.File.new(opts[:chdir] || Dir.pwd))
29
+
22
30
  env.each_pair do |key, value|
23
31
  pb.environment.put(key, value)
24
32
  end
@@ -81,6 +81,7 @@ module Asciidoctor
81
81
  args = opts[:args]
82
82
  out_file = opts[:out_file]
83
83
  env = opts[:env] || {}
84
+ open3_opts[:chdir] = opts[:chdir] if opts[:chdir]
84
85
  else
85
86
  raise "Block passed to generate_file should return an Array or a Hash"
86
87
  end
@@ -1,5 +1,5 @@
1
1
  module Asciidoctor
2
2
  module Diagram
3
- VERSION = "2.2.7"
3
+ VERSION = "2.2.8"
4
4
  end
5
5
  end
@@ -4,6 +4,7 @@ require_relative 'asciidoctor-diagram/blockdiag'
4
4
  require_relative 'asciidoctor-diagram/bpmn'
5
5
  require_relative 'asciidoctor-diagram/bytefield'
6
6
  require_relative 'asciidoctor-diagram/d2'
7
+ require_relative 'asciidoctor-diagram/dbml'
7
8
  require_relative 'asciidoctor-diagram/diagrams'
8
9
  require_relative 'asciidoctor-diagram/ditaa'
9
10
  require_relative 'asciidoctor-diagram/dpic'
@@ -21,6 +22,7 @@ require_relative 'asciidoctor-diagram/plantuml'
21
22
  require_relative 'asciidoctor-diagram/salt'
22
23
  require_relative 'asciidoctor-diagram/shaape'
23
24
  require_relative 'asciidoctor-diagram/smcat'
25
+ require_relative 'asciidoctor-diagram/structurizr'
24
26
  require_relative 'asciidoctor-diagram/svgbob'
25
27
  require_relative 'asciidoctor-diagram/symbolator'
26
28
  require_relative 'asciidoctor-diagram/syntrax'
data/spec/d2_spec.rb CHANGED
@@ -34,4 +34,27 @@ end
34
34
 
35
35
  describe Asciidoctor::Diagram::D2BlockProcessor, :broken_on_windows do
36
36
  include_examples "block", :d2, D2_CODE, [:svg]
37
+
38
+ it "should support sketch mode" do
39
+ doc = <<-eos
40
+ = Hello, D2!
41
+ Doc Writer <doc@example.com>
42
+
43
+ == First Section
44
+
45
+ [d2, sketch=true]
46
+ ----
47
+ #{D2_CODE}
48
+ ----
49
+ eos
50
+
51
+ d = load_asciidoc doc
52
+ expect(d).to_not be_nil
53
+
54
+ b = d.find { |bl| bl.context == :image }
55
+ expect(b).to_not be_nil
56
+ target = b.attributes['target']
57
+ expect(target).to match(/\.svg$/)
58
+ expect(File.exist?(target)).to be true
59
+ end
37
60
  end
data/spec/dbml_spec.rb ADDED
@@ -0,0 +1,32 @@
1
+ require_relative 'test_helper'
2
+
3
+ DBML_CODE = <<-eos
4
+ Table users {
5
+ id integer
6
+ username varchar
7
+ role varchar
8
+ created_at timestamp
9
+ }
10
+
11
+ Table posts {
12
+ id integer [primary key]
13
+ title varchar
14
+ body text [note: 'Content of the post']
15
+ user_id integer
16
+ created_at timestamp
17
+ }
18
+
19
+ Ref: posts.user_id > users.id
20
+ eos
21
+
22
+ describe Asciidoctor::Diagram::DbmlInlineMacroProcessor, :broken_on_windows do
23
+ include_examples "inline_macro", :dbml, DBML_CODE, [:svg]
24
+ end
25
+
26
+ describe Asciidoctor::Diagram::DbmlBlockMacroProcessor, :broken_on_windows do
27
+ include_examples "block_macro", :dbml, DBML_CODE, [:svg]
28
+ end
29
+
30
+ describe Asciidoctor::Diagram::DbmlBlockProcessor, :broken_on_windows do
31
+ include_examples "block", :dbml, DBML_CODE, [:svg]
32
+ end
@@ -278,7 +278,7 @@ Foo1 -> Foo2 : To boundary
278
278
  expect(File.exist?(target)).to be true
279
279
 
280
280
  svg = File.read(target, :encoding => Encoding::UTF_8)
281
- expect(svg).to match(/<[^<]+ fill=["']url\(#gvl9ibi66ipfc0\)["']/)
281
+ expect(svg).to match(/<[^<]+ stop-color=["']#7C9AB9["']/)
282
282
  end
283
283
 
284
284
  it 'should use plantuml include dir when specified as a document attribute' do
@@ -757,8 +757,8 @@ Doc Writer <doc@example.com>
757
757
  scaled_image = d.find { |bl| bl.context == :image }
758
758
 
759
759
  unless formats[0] == :pdf
760
- expect(scaled_image.attributes['width']).to be_within(1).of(unscaled_image.attributes['width'] * 2)
761
- expect(scaled_image.attributes['height']).to be_within(1).of(unscaled_image.attributes['height'] * 2)
760
+ expect(scaled_image.attributes['width']).to be_within(10).of(unscaled_image.attributes['width'] * 2)
761
+ expect(scaled_image.attributes['height']).to be_within(10).of(unscaled_image.attributes['height'] * 2)
762
762
  end
763
763
  end
764
764
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-diagram
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.7
4
+ version: 2.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pepijn Van Eeckhoudt
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-06 00:00:00.000000000 Z
11
+ date: 2023-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -159,6 +159,9 @@ files:
159
159
  - lib/asciidoctor-diagram/d2.rb
160
160
  - lib/asciidoctor-diagram/d2/converter.rb
161
161
  - lib/asciidoctor-diagram/d2/extension.rb
162
+ - lib/asciidoctor-diagram/dbml.rb
163
+ - lib/asciidoctor-diagram/dbml/converter.rb
164
+ - lib/asciidoctor-diagram/dbml/extension.rb
162
165
  - lib/asciidoctor-diagram/diagram_converter.rb
163
166
  - lib/asciidoctor-diagram/diagram_processor.rb
164
167
  - lib/asciidoctor-diagram/diagram_source.rb
@@ -167,7 +170,7 @@ files:
167
170
  - lib/asciidoctor-diagram/diagrams/extension.rb
168
171
  - lib/asciidoctor-diagram/ditaa.rb
169
172
  - lib/asciidoctor-diagram/ditaa/converter.rb
170
- - lib/asciidoctor-diagram/ditaa/ditaa-1.3.21.jar
173
+ - lib/asciidoctor-diagram/ditaa/ditaa-2.0.0.jar
171
174
  - lib/asciidoctor-diagram/ditaa/extension.rb
172
175
  - lib/asciidoctor-diagram/dpic.rb
173
176
  - lib/asciidoctor-diagram/dpic/converter.rb
@@ -207,7 +210,7 @@ files:
207
210
  - lib/asciidoctor-diagram/plantuml.rb
208
211
  - lib/asciidoctor-diagram/plantuml/converter.rb
209
212
  - lib/asciidoctor-diagram/plantuml/extension.rb
210
- - lib/asciidoctor-diagram/plantuml/plantuml-1.3.24.jar
213
+ - lib/asciidoctor-diagram/plantuml/plantuml-2.0.0.jar
211
214
  - lib/asciidoctor-diagram/salt.rb
212
215
  - lib/asciidoctor-diagram/shaape.rb
213
216
  - lib/asciidoctor-diagram/shaape/converter.rb
@@ -215,6 +218,11 @@ files:
215
218
  - lib/asciidoctor-diagram/smcat.rb
216
219
  - lib/asciidoctor-diagram/smcat/converter.rb
217
220
  - lib/asciidoctor-diagram/smcat/extension.rb
221
+ - lib/asciidoctor-diagram/structurizr.rb
222
+ - lib/asciidoctor-diagram/structurizr/converter.rb
223
+ - lib/asciidoctor-diagram/structurizr/extension.rb
224
+ - lib/asciidoctor-diagram/structurizr/renderers.rb
225
+ - lib/asciidoctor-diagram/structurizr/structurizr-2.0.1.jar
218
226
  - lib/asciidoctor-diagram/svgbob.rb
219
227
  - lib/asciidoctor-diagram/svgbob/converter.rb
220
228
  - lib/asciidoctor-diagram/svgbob/extension.rb
@@ -224,6 +232,7 @@ files:
224
232
  - lib/asciidoctor-diagram/syntrax.rb
225
233
  - lib/asciidoctor-diagram/syntrax/converter.rb
226
234
  - lib/asciidoctor-diagram/syntrax/extension.rb
235
+ - lib/asciidoctor-diagram/syntrax/syntrax-2.0.2.jar
227
236
  - lib/asciidoctor-diagram/tikz.rb
228
237
  - lib/asciidoctor-diagram/tikz/converter.rb
229
238
  - lib/asciidoctor-diagram/tikz/extension.rb
@@ -240,7 +249,7 @@ files:
240
249
  - lib/asciidoctor-diagram/util/pdf.rb
241
250
  - lib/asciidoctor-diagram/util/platform.rb
242
251
  - lib/asciidoctor-diagram/util/png.rb
243
- - lib/asciidoctor-diagram/util/server-1.3.21.jar
252
+ - lib/asciidoctor-diagram/util/server-2.0.0.jar
244
253
  - lib/asciidoctor-diagram/util/svg.rb
245
254
  - lib/asciidoctor-diagram/util/which.rb
246
255
  - lib/asciidoctor-diagram/vega.rb
@@ -256,6 +265,7 @@ files:
256
265
  - spec/bpmn_spec.rb
257
266
  - spec/bytefield_spec.rb
258
267
  - spec/d2_spec.rb
268
+ - spec/dbml_spec.rb
259
269
  - spec/diagrams_spec.rb
260
270
  - spec/ditaa_spec.rb
261
271
  - spec/dpic_spec.rb
@@ -285,8 +295,13 @@ files:
285
295
  homepage: https://github.com/asciidoctor/asciidoctor-diagram
286
296
  licenses:
287
297
  - MIT
288
- metadata: {}
289
- post_install_message:
298
+ metadata:
299
+ bug_tracker_uri: https://github.com/asciidoctor/asciidoctor-diagram/issues
300
+ changelog_uri: https://github.com/asciidoctor/asciidoctor-diagram/blob/master/CHANGELOG.adoc
301
+ documentation_uri: https://docs.asciidoctor.org/diagram-extension/latest/
302
+ homepage_uri: https://github.com/asciidoctor/asciidoctor-diagram
303
+ source_code_uri: https://github.com/asciidoctor/asciidoctor-diagram.git
304
+ post_install_message:
290
305
  rdoc_options: []
291
306
  require_paths:
292
307
  - lib
@@ -301,8 +316,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
301
316
  - !ruby/object:Gem::Version
302
317
  version: '0'
303
318
  requirements: []
304
- rubygems_version: 3.2.22
305
- signing_key:
319
+ rubygems_version: 3.0.3.1
320
+ signing_key:
306
321
  specification_version: 4
307
322
  summary: A family of Asciidoctor extensions that generate images from a broad range
308
323
  of embedded plain text diagram descriptions, including PlantUML, ditaa, Kroki, and
@@ -314,6 +329,7 @@ test_files:
314
329
  - spec/bpmn_spec.rb
315
330
  - spec/bytefield_spec.rb
316
331
  - spec/d2_spec.rb
332
+ - spec/dbml_spec.rb
317
333
  - spec/diagrams_spec.rb
318
334
  - spec/ditaa_spec.rb
319
335
  - spec/dpic_spec.rb