asciidoctor-diagram 2.2.7 → 2.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +20 -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 +8 -0
  13. data/lib/asciidoctor-diagram/diagram_source.rb +10 -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/a2s_spec.rb +1 -1
  31. data/spec/barcode_spec.rb +1 -1
  32. data/spec/blockdiag_spec.rb +1 -1
  33. data/spec/bpmn_spec.rb +1 -1
  34. data/spec/bytefield_spec.rb +1 -1
  35. data/spec/d2_spec.rb +51 -1
  36. data/spec/dbml_spec.rb +32 -0
  37. data/spec/diagrams_spec.rb +1 -1
  38. data/spec/ditaa_spec.rb +1 -1
  39. data/spec/dpic_spec.rb +1 -1
  40. data/spec/erd_spec.rb +1 -1
  41. data/spec/gnuplot_spec.rb +1 -1
  42. data/spec/graphviz_py_spec.rb +1 -1
  43. data/spec/graphviz_spec.rb +1 -1
  44. data/spec/lilypond_spec.rb +1 -1
  45. data/spec/meme_spec.rb +1 -1
  46. data/spec/mermaid_spec.rb +1 -1
  47. data/spec/msc_spec.rb +1 -1
  48. data/spec/nomnoml_spec.rb +1 -1
  49. data/spec/pikchr_spec.rb +1 -1
  50. data/spec/plantuml_spec.rb +2 -2
  51. data/spec/shaape_spec.rb +1 -1
  52. data/spec/shared_examples.rb +5 -3
  53. data/spec/smcat_spec.rb +1 -1
  54. data/spec/structurizr_spec.rb +41 -0
  55. data/spec/svgbob_spec.rb +1 -1
  56. data/spec/symbolator_spec.rb +1 -1
  57. data/spec/syntrax_spec.rb +1 -1
  58. data/spec/{test_helper.rb → test_helper_methods.rb} +2 -0
  59. data/spec/tikz_spec.rb +1 -1
  60. data/spec/umlet_spec.rb +1 -1
  61. data/spec/vega_spec.rb +1 -1
  62. data/spec/wavedrom_spec.rb +1 -1
  63. metadata +27 -9
  64. data/lib/asciidoctor-diagram/ditaa/ditaa-1.3.21.jar +0 -0
  65. data/lib/asciidoctor-diagram/plantuml/plantuml-1.3.24.jar +0 -0
  66. 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: 9f5d112b2ce57cb2380687fce2fac5fe15f2f6d2c6198f722edd5aeaa08d6b7d
4
+ data.tar.gz: 8d45d7df6757adfb72c0c4c4b9ba95bab649fe6a1686418f2a4ffc49fc20facb
5
5
  SHA512:
6
- metadata.gz: d365c1149d8b2d7ce00a0aecdf0d40435518aeda247448adb4bfe81bc7b4c9cefe69477c3c3a6e3cb1fcbd703dc7efe2ad4e519d49aa4f32a10a51ecf523eaab
7
- data.tar.gz: 567f9ba04c8bb97e09e6e2d70bfde26cd51700777257a5dd8a7a683ce101f6b0341f00d6729d12116400b620f38d5f4b3bea1113623641989c9d44a26110c04b
6
+ metadata.gz: 56d0bffc577cd54b56853b02454760767ff5642c935eb57e9909a0aad974ad598897e2d5f312c780471f55318de0789df39e760b917e846ec702ad0ee1640a7f
7
+ data.tar.gz: 67496690a923714ba8b3757781b674862dc318680797bb118ecc00d834125b42d27770465b57db440b47ce0df3e4eebab8658d7a2aec8e5cf610bef886005655
data/CHANGELOG.adoc CHANGED
@@ -1,5 +1,24 @@
1
1
  = Asciidoctor-diagram Changelog
2
2
 
3
+ == 2.2.9
4
+
5
+ Bugfixes::
6
+
7
+ * Issue #409: Second attempt at fixing handling of the D2 `sketch` attribute
8
+ * Issue #415: Resolve NoMethodError when using Structurizr blocks
9
+
10
+ == 2.2.8
11
+
12
+ Enhancements::
13
+
14
+ * Add support for reusing JSyntrax subprocess instances to improve performance when rendering many syntax diagrams (@gitrbond, @inponomarev)
15
+ * Issue #386: Add basic https://structurizr.com[Structurizr] support
16
+
17
+ Bugfixes::
18
+
19
+ * Issue #409: Fix handling of the D2 `sketch` attribute
20
+ * Issue #410: Ensure current directory is always set to document base directory when invoking subprocesses
21
+
3
22
  == 2.2.7
4
23
 
5
24
  Enhancements::
@@ -25,6 +44,7 @@ Enhancements::
25
44
  Enhancements::
26
45
 
27
46
  * Issue #399: Add support for PlantUML theme attribute
47
+ * Add DBML support via https://github.com/softwaretechnik-berlin/dbml-renderer[dbml-renderer]
28
48
 
29
49
  == 2.2.3
30
50
 
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.nil? && 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
@@ -64,6 +64,12 @@ module Asciidoctor
64
64
  location = parent.document.reader.cursor_at_mark
65
65
 
66
66
  normalised_attributes = attributes.inject({}) { |h, (k, v)| h[normalise_attribute_name(k)] = v; h }
67
+ pos_attr_index = config.fetch(:positional_attrs, []).length + 1
68
+ until attributes[pos_attr_index].nil?
69
+ normalised_attributes[attributes[pos_attr_index]] = 'true'
70
+ pos_attr_index = pos_attr_index + 1
71
+ end
72
+
67
73
  converter = config[:converter].new
68
74
 
69
75
  supported_formats = supported_formats(converter)
@@ -356,6 +362,7 @@ module Asciidoctor
356
362
  include DiagramProcessor
357
363
 
358
364
  def self.inherited(subclass)
365
+ subclass.use_dsl
359
366
  subclass.name_positional_attributes ['target', 'format']
360
367
  subclass.contexts [:listing, :literal, :open]
361
368
  subclass.content_model :simple
@@ -374,6 +381,7 @@ module Asciidoctor
374
381
  include DiagramProcessor
375
382
 
376
383
  def self.inherited(subclass)
384
+ subclass.use_dsl
377
385
  subclass.name_positional_attributes ['format']
378
386
  end
379
387
 
@@ -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
@@ -193,6 +193,14 @@ module Asciidoctor
193
193
  name = [name] unless name.is_a?(Enumerable)
194
194
 
195
195
  value = name.lazy.map { |n| @attributes[n] }.reject { |v| v.nil? }.first
196
+ if value.nil?
197
+ attr_position = config[:positional_attrs] || 1
198
+ while value.nil? && !@attributes[attr_position].nil?
199
+ if @attributes[attr_position] == name
200
+ value = true
201
+ end
202
+ end
203
+ end
196
204
 
197
205
  if value.nil? && inherit
198
206
  inherited_values = name.lazy.map do |n|
@@ -262,7 +270,7 @@ module Asciidoctor
262
270
  class FileSource < BasicSource
263
271
  def initialize(block_processor, parent_block, file_name, attributes)
264
272
  super(block_processor, parent_block, attributes)
265
- @file_name = file_name
273
+ @file_name = File.expand_path(file_name)
266
274
  end
267
275
 
268
276
  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[File.join(lib_dir, '*.jar')]
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.code,
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 = StructurizrConvertBlockProcessor.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