asciidoctor-diagram 1.5.18 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +28 -0
  3. data/README.adoc +56 -14
  4. data/examples/features.adoc +2 -2
  5. data/lib/asciidoctor-diagram/a2s/converter.rb +55 -0
  6. data/lib/asciidoctor-diagram/a2s/extension.rb +6 -52
  7. data/lib/asciidoctor-diagram/blockdiag/converter.rb +37 -0
  8. data/lib/asciidoctor-diagram/blockdiag/extension.rb +9 -116
  9. data/lib/asciidoctor-diagram/bpmn/converter.rb +62 -0
  10. data/lib/asciidoctor-diagram/bpmn/extension.rb +14 -0
  11. data/lib/asciidoctor-diagram/bpmn.rb +7 -0
  12. data/lib/asciidoctor-diagram/diagram_converter.rb +19 -0
  13. data/lib/asciidoctor-diagram/diagram_processor.rb +320 -0
  14. data/lib/asciidoctor-diagram/diagram_source.rb +275 -0
  15. data/lib/asciidoctor-diagram/ditaa/converter.rb +86 -0
  16. data/lib/asciidoctor-diagram/ditaa/extension.rb +6 -71
  17. data/lib/asciidoctor-diagram/erd/converter.rb +31 -0
  18. data/lib/asciidoctor-diagram/erd/extension.rb +6 -35
  19. data/lib/asciidoctor-diagram/gnuplot/converter.rb +63 -0
  20. data/lib/asciidoctor-diagram/gnuplot/extension.rb +14 -0
  21. data/lib/asciidoctor-diagram/gnuplot.rb +7 -0
  22. data/lib/asciidoctor-diagram/graphviz/converter.rb +32 -0
  23. data/lib/asciidoctor-diagram/graphviz/extension.rb +6 -35
  24. data/lib/asciidoctor-diagram/http/server.rb +127 -0
  25. data/lib/asciidoctor-diagram/lilypond/converter.rb +54 -0
  26. data/lib/asciidoctor-diagram/lilypond/extension.rb +14 -0
  27. data/lib/asciidoctor-diagram/lilypond.rb +7 -0
  28. data/lib/asciidoctor-diagram/meme/converter.rb +122 -0
  29. data/lib/asciidoctor-diagram/meme/extension.rb +5 -107
  30. data/lib/asciidoctor-diagram/mermaid/converter.rb +178 -0
  31. data/lib/asciidoctor-diagram/mermaid/extension.rb +6 -159
  32. data/lib/asciidoctor-diagram/msc/converter.rb +35 -0
  33. data/lib/asciidoctor-diagram/msc/extension.rb +6 -36
  34. data/lib/asciidoctor-diagram/nomnoml/converter.rb +25 -0
  35. data/lib/asciidoctor-diagram/nomnoml/extension.rb +6 -28
  36. data/lib/asciidoctor-diagram/plantuml/converter.rb +115 -0
  37. data/lib/asciidoctor-diagram/plantuml/extension.rb +10 -119
  38. data/lib/asciidoctor-diagram/shaape/converter.rb +25 -0
  39. data/lib/asciidoctor-diagram/shaape/extension.rb +6 -28
  40. data/lib/asciidoctor-diagram/smcat/converter.rb +44 -0
  41. data/lib/asciidoctor-diagram/smcat/extension.rb +14 -0
  42. data/lib/asciidoctor-diagram/smcat.rb +7 -0
  43. data/lib/asciidoctor-diagram/svgbob/converter.rb +25 -0
  44. data/lib/asciidoctor-diagram/svgbob/extension.rb +6 -28
  45. data/lib/asciidoctor-diagram/syntrax/converter.rb +55 -0
  46. data/lib/asciidoctor-diagram/syntrax/extension.rb +6 -51
  47. data/lib/asciidoctor-diagram/tikz/converter.rb +56 -0
  48. data/lib/asciidoctor-diagram/tikz/extension.rb +6 -60
  49. data/lib/asciidoctor-diagram/umlet/converter.rb +24 -0
  50. data/lib/asciidoctor-diagram/umlet/extension.rb +6 -28
  51. data/lib/asciidoctor-diagram/util/java.rb +1 -1
  52. data/lib/asciidoctor-diagram/util/java_socket.rb +7 -9
  53. data/lib/asciidoctor-diagram/util/which.rb +0 -29
  54. data/lib/asciidoctor-diagram/vega/converter.rb +47 -0
  55. data/lib/asciidoctor-diagram/vega/extension.rb +6 -44
  56. data/lib/asciidoctor-diagram/version.rb +1 -1
  57. data/lib/asciidoctor-diagram/wavedrom/converter.rb +50 -0
  58. data/lib/asciidoctor-diagram/wavedrom/extension.rb +6 -46
  59. data/lib/asciidoctor-diagram.rb +4 -0
  60. data/lib/ditaa-1.3.14.jar +0 -0
  61. data/lib/ditaamini-0.12.jar +0 -0
  62. data/lib/plantuml-1.3.14.jar +0 -0
  63. data/lib/plantuml.jar +0 -0
  64. data/lib/server-1.3.14.jar +0 -0
  65. data/spec/bpmn-example.xml +44 -0
  66. data/spec/bpmn_spec.rb +96 -0
  67. data/spec/gnuplot_spec.rb +478 -0
  68. data/spec/lilypond_spec.rb +151 -0
  69. data/spec/mermaid_spec.rb +33 -1
  70. data/spec/plantuml_spec.rb +89 -0
  71. data/spec/smcat_spec.rb +164 -0
  72. data/spec/test_helper.rb +3 -0
  73. metadata +52 -11
  74. data/lib/asciidoctor-diagram/extensions.rb +0 -568
  75. data/lib/ditaa-1.3.13.jar +0 -0
  76. data/lib/ditaamini-0.11.jar +0 -0
  77. data/lib/plantuml-1.3.13.jar +0 -0
  78. data/lib/server-1.3.13.jar +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8e3c8549b195285f274052e14c6addc52c5900a80fcf88935cb3820432903ac
4
- data.tar.gz: b673dd81b505260bf7fd06e45ef98df1806a22684a4036fb4c4e006317384538
3
+ metadata.gz: d37e7e92d9ff0bcae6607a862a17d8d642a54ad482f896a671c698993c22ad18
4
+ data.tar.gz: 9da43fb78ccd16a79e341c662f0e6dae0fdb2edf4bd9697005f4321c8e518fe0
5
5
  SHA512:
6
- metadata.gz: 193b91c7ddac87a1e0fad1a1c65b6dcb6406888c54443f5a6ae8be8f6ffb3845708e6c29a4a0d5d11438411d7281f60be1b0be79d280bf68a8764daf3a0ed4ea
7
- data.tar.gz: 18e6d118480da5b4010df9bcc0fa58bd852d5cf70bb48960f55b31235bb6bfe58cfa4fe47eab3d750a56262db9f8a76c390b85cb88dffbbfd9df1f8c512d3fd5
6
+ metadata.gz: 5366ef0c9961283fa4df0dd1b59774237dfc78923160e705d739d856f7b8dd64dc0edd4b93bc7cc139e413481dd597a384b952e52483a36a672e3f47eed30e2f
7
+ data.tar.gz: b2828d5e8987b2f27f2c1c55a0bd80eae39b7c2015c09c9899cf5ad1ce0e264cef2af7782a402225ceea81027f65ef12480a8882af90e0dd4571e98fb1571c5c
data/CHANGELOG.adoc CHANGED
@@ -1,5 +1,33 @@
1
1
  = Asciidoctor-diagram Changelog
2
2
 
3
+ == 2.0.0
4
+
5
+ Enhancements::
6
+ * Cleaned up internals of the extension
7
+ * Add support for BPMN (@gtudan)
8
+ * Update PlantUML to v1.2019.12
9
+ * #231 Improve PlantUML error reporting
10
+ * #247 Add support for document-level `diagram-svg-type` and block-level `svg-type` attributes to control SVG interactivity
11
+ * #250 Add support for Mermaid's `puppeteerConfig` option (@ldz-w)
12
+
13
+ == 1.5.19
14
+
15
+ Bug Fixes::
16
+ * Issue #233: Resolve character encoding issues with Ditaa on Windows with Java runtimes that do not use UTF-8 encoding by default
17
+ * Fix generation of SVG output for TikZ diagrams (@joelsmith)
18
+ * Improve TikZ image cropping (@joelsmith)
19
+
20
+ Enhancements::
21
+ * Issue #225: Add support for WaveDrom CLI 2.0.0
22
+ * Issue #234: Add support for State Machine Cat
23
+ * Add support for gnuplot (@MariuszCwikla)
24
+
25
+ == 1.5.18
26
+
27
+ Bug Fixes::
28
+
29
+ * Issue #224: Fix asciidoctor 1.5.x compatibility regression introduced in 1.5.17
30
+
3
31
  == 1.5.17
4
32
 
5
33
  Enhancements::
data/README.adoc CHANGED
@@ -18,9 +18,11 @@ ifndef::env-site[:status:]
18
18
  :uri-asciidoctor-api: http://asciidoctor.org/docs/user-manual/#api
19
19
  :uri-asciidoctor-extensions: http://asciidoctor.org/docs/user-manual/#extension-points
20
20
  :uri-blockdiag: http://blockdiag.com
21
+ :uri-bpmn: https://github.com/gtudan/bpmn-js-cmd
21
22
  :uri-ditaa: http://ditaa.sourceforge.net/
22
23
  :uri-dot: https://graphviz.gitlab.io/_pages/doc/info/lang.html
23
24
  :uri-erd: https://github.com/BurntSushi/erd
25
+ :uri-gnuplot: http://gnuplot.info
24
26
  :uri-graphviz: https://graphviz.gitlab.io
25
27
  :uri-imagemagick: http://www.imagemagick.org
26
28
  :uri-java: http://java.sun.com
@@ -35,6 +37,7 @@ ifndef::env-site[:status:]
35
37
  :uri-rackdiag: http://blockdiag.com/en/nwdiag/index.html
36
38
  :uri-seqdiag: http://blockdiag.com/en/seqdiag/index.html
37
39
  :uri-shaape: https://github.com/christiangoltz/shaape
40
+ :uri-smcat: https://github.com/sverweij/state-machine-cat
38
41
  :uri-svgbob: https://github.com/ivanceras/svgbobrus
39
42
  :uri-syntrax: https://kevinpt.github.io/syntrax/
40
43
  :uri-umlet: http://www.umlet.com/
@@ -46,7 +49,7 @@ ifndef::env-site[:status:]
46
49
 
47
50
  Asciidoctor Diagram is a set of Asciidoctor extensions that enable you to add diagrams, which you describe using plain text, to your AsciiDoc document.
48
51
 
49
- The extensions supports the {uri-a2s}[AsciiToSVG], BlockDiag ({uri-blockdiag}[BlockDiag], {uri-seqdiag}[SeqDiag], {uri-actdiag}[ActDiag], {uri-nwdiag}[NwDiag]), {uri-ditaa}[Ditaa], {uri-erd}[Erd], {uri-dot}[GraphViz], {uri-mermaid}[Mermaid], {uri-mscgen}[Msc], {uri-nomnoml}[Nomnoml], {uri-plantuml}[PlantUML], {uri-shaape}[Shaape], {uri-svgbob}[SvgBob], {uri-syntrax}[Syntrax], {uri-umlet}[UMLet], {uri-vega}[Vega], {uri-vegalite}[Vega-Lite] and {uri-wavedrom}[WaveDrom] syntax.
52
+ The extensions supports the {uri-a2s}[AsciiToSVG], BlockDiag ({uri-blockdiag}[BlockDiag], {uri-seqdiag}[SeqDiag], {uri-actdiag}[ActDiag], {uri-nwdiag}[NwDiag]), {uri-ditaa}[Ditaa], {uri-erd}[Erd], {uri-gnuplot}[Gnuplot], {uri-dot}[GraphViz], {uri-mermaid}[Mermaid], {uri-mscgen}[Msc], {uri-nomnoml}[Nomnoml], {uri-plantuml}[PlantUML], {uri-shaape}[Shaape], {uri-smcat}[State Machine Cat], {uri-svgbob}[SvgBob], {uri-syntrax}[Syntrax], {uri-umlet}[UMLet], {uri-vega}[Vega], {uri-vegalite}[Vega-Lite] and {uri-wavedrom}[WaveDrom] syntax.
50
53
 
51
54
  Each extension runs the diagram processor to generate an SVG, PNG, or TXT file from the input text.
52
55
  The generated file is then inserted into your converted document.
@@ -119,8 +122,10 @@ The following diagram types and output formats are available:
119
122
  |{uri-a2s}[a2s] | | | |{check}|
120
123
  |{uri-actdiag}[actdiag] | |{check}|{check}|{check}|
121
124
  |{uri-blockdiag}[blockdiag] | |{check}|{check}|{check}|
125
+ |{uri-bpmn}[bpmn] | |{check}|{check}|{check}|
122
126
  |{uri-ditaa}[ditaa] | | |{check}|{check}|
123
127
  |{uri-erd}[erd] | | |{check}|{check}|
128
+ |{uri-gnuplot}[gnuplot] |{check}| |{check}|{check}|{check}
124
129
  |{uri-dot}[graphviz] | |{check}|{check}|{check}|
125
130
  |<<meme,meme>> |{check}| |{check}| |
126
131
  |{uri-mermaid}[mermaid] | |{check}|{check}|{check}|
@@ -132,6 +137,7 @@ The following diagram types and output formats are available:
132
137
  |{uri-rackdiag}[rackdiag] | |{check}|{check}|{check}|
133
138
  |{uri-seqdiag}[seqdiag] | |{check}|{check}|{check}|
134
139
  |{uri-shaape}[shaape] | | |{check}|{check}|
140
+ |{uri-smcat}[smcat] | | | |{check}|
135
141
  |{uri-svgbob}[svgbob] | | | |{check}|
136
142
  |{uri-syntrax}[syntrax] | |{check}|{check}|{check}|
137
143
  |{uri-umlet}[umlet] |{check}|{check}|{check}|{check}|
@@ -249,7 +255,7 @@ or load and register each extension individually.
249
255
  require 'asciidoctor-diagram/<extension_name>'
250
256
  ----
251
257
 
252
- `<extension_name>` can be one of `a2s`, `blockdiag`, `ditaa`, `erd`, `graphviz`, `meme`, `mermaid`, `msc`, `plantuml`, `shaape`, `svgbob`, `syntrax`, `umlet`, `vega` or `wavedrom`.
258
+ `<extension_name>` can be one of `a2s`, `blockdiag`, `ditaa`, `erd`, `gnuplot`, `graphviz`, `meme`, `mermaid`, `msc`, `plantuml`, `shaape`, `smcat`, `svgbob`, `syntrax`, `umlet`, `vega` or `wavedrom`.
253
259
 
254
260
  Requiring one or more of these files will automatically register the extensions for all processed documents.
255
261
 
@@ -295,8 +301,10 @@ The following table lists the tools that are required for each diagram type, the
295
301
  |a2s |{uri-a2s}[AsciiToSvg] |`a2s`
296
302
  |actdiag |{uri-actdiag}[ActDiag] |`actdiag`
297
303
  |blockdiag |{uri-blockdiag}[BlockDiag] |`blockdiag`
304
+ |bpmn |{uri-bpmn}[bpmn-js-cmd] |`bpmn`
298
305
  |ditaa |{uri-java}[Java] |`java`
299
306
  |erd |{uri-erd}[Erd] |`erd`
307
+ |gnuplot |{uri-gnuplot}[Gnuplot] |`gnuplot`
300
308
  |graphviz |{uri-graphviz}[GraphViz] |`dot` or `graphvizdot`
301
309
  |meme |{uri-imagemagick}[ImageMagick] |`convert` and `identify`
302
310
  |mermaid |{uri-mermaid}[Mermaid.cli] |`mermaid`
@@ -308,13 +316,14 @@ The following table lists the tools that are required for each diagram type, the
308
316
  |rackdiag |{uri-nwdiag}[NwDiag] |`rackdiag`
309
317
  |seqdiag |{uri-seqdiag}[SeqDiag] |`seqdiag`
310
318
  |shaape |{uri-shaape}[Shaape] |`shaape`
319
+ |smcat |{uri-smcat}[State Machine Cat] |`smcat`
311
320
  |svgbob |{uri-svgbob}[SvgBob] |`svgbob`
312
321
  |syntrax |{uri-syntrax}[Syntrax] |`syntrax`
313
322
  |umlet |{uri-umlet}[Umlet] |`umlet`
314
323
  |vega |{uri-vega}[vg2png] and/or {uri-vega}[vg2png] |`vg2png` and `vg2svg`
315
324
  |vegalite |{uri-vegalite}[vl2vg] and {uri-vega}[vg2png] and/or {uri-vega}[vg2svg]|`vl2vg`, `vg2png` and `vg2svg`
316
325
  .2+|wavedrom |{uri-wavedromeditor}[WaveDrom Editor] |`wavedrom`
317
- |{uri-wavedromcli}[WaveDrom CLI] and {uri-phantomjs}[PhantomJS] |`wavedrom` and `phantomjs`
326
+ |{uri-wavedromcli}[WaveDrom CLI] (and {uri-phantomjs}[PhantomJS] for WaveDrom CLI v1) |`wavedrom` (and `phantomjs`)
318
327
  |===
319
328
 
320
329
  If for instance you installed `actdiag` in `/home/me/actdiag/bin` and this path is not included in the `PATH` you can specify its location on the command line
@@ -328,12 +337,12 @@ The meme extension provides a basic '`Advice Animal`' style image generator.
328
337
  It's usage is easiest to explain with an example.
329
338
 
330
339
  ----
331
- meme::yunoguy.jpg[Doc writers,Y U NO \\ AsciiDoc]
340
+ meme::yunoguy.jpg[Doc writers,Y U NO // AsciiDoc]
332
341
  ----
333
342
 
334
343
  The target of the block macro tells the extension which image to use as background.
335
344
  The first two positional attributes are `top` and `bottom` and are used for the top and bottom label.
336
- Occurrences of `\\` surrounded by whitespace are interpreted as line breaks.
345
+ Occurrences of `//` surrounded by whitespace are interpreted as line breaks.
337
346
 
338
347
  === Diagram Attributes
339
348
 
@@ -377,6 +386,15 @@ The attribute name at the block level should be prefixed with the name of the di
377
386
  |fontpath |unspecified |The path to the font that should be used by blockdiag
378
387
  |===
379
388
 
389
+ ==== BPMN
390
+
391
+ [cols=">,<,<",options="header"]
392
+ |===
393
+ |Name |Default value |Description
394
+ |height |786 |The target height of the diagram. Does not apply for output type `svg`.
395
+ |width |1024 |The target width of the diagram. Does not apply for output type `svg`.
396
+ |===
397
+
380
398
  ==== Ditaa
381
399
 
382
400
  [cols=">,<,<",options="header"]
@@ -394,6 +412,20 @@ The attribute name at the block level should be prefixed with the name of the di
394
412
  |transparent |false |Makes the background of the image transparent instead of using the background color.
395
413
  |===
396
414
 
415
+ ==== Gnuplot
416
+
417
+ [cols=">,<,<",options="header"]
418
+ |===
419
+ |Name |Default value |Description
420
+ |background |unspecified |Background color, e.g. `red`, `#FF0000`. Does not work with `txt`.
421
+ |height |unspecified |The height of the plot. Must be specified together with `width`.
422
+ |width |unspecified |The width of the plot. Must be specified together with `height`.
423
+ |crop |unspecified |Trims blank space from the edges of the completed plot (true/false). Does not work with `svg`, `pdf`.
424
+ |transparent |unspecified |Generate transparent background (true/false). Does not work with `svg`, `pdf`, `txt`.
425
+ |font |unspecified |The font face with optional font size to use for the text, e.g. `font="Arial"`, `font="Arial,11"`. Does not work with `txt`.
426
+ |fontscale |unspecified |Scales all label for given factor. Does not work with `txt`.
427
+ |===
428
+
397
429
  ==== GraphViz
398
430
 
399
431
  [cols=">,<,<",options="header"]
@@ -418,15 +450,16 @@ The attribute name at the block level should be prefixed with the name of the di
418
450
 
419
451
  [cols=">,<,<",options="header"]
420
452
  |===
421
- |Name |Default value |Description
422
- |background |FFFFFF |The background colour of the image. The format should be a six-digit hexadecimal number (as in HTML, FF0000 for red). Pass an eight-digit hex to define transparency.
423
- |css |unspecified |Path to a CSS file to pass to mermaid.
424
- |config |unspecified |Path to a JSON config file to pass to mermaid.
425
- |ganttconfig |unspecified |Path to a gantt config file to pass to mermaid.
426
- |sequenceconfig|unspecified |Path to a sequence config file to pass to mermaid.
427
- |theme |unspecified |Theme of the chart, could be default, forest, dark or neutral.
428
- |width |unspecified |Width of the page.
429
- |height |unspecified |Height of the page.
453
+ |Name |Default value |Description
454
+ |background |FFFFFF |The background colour of the image. The format should be a six-digit hexadecimal number (as in HTML, FF0000 for red). Pass an eight-digit hex to define transparency.
455
+ |css |unspecified |Path to a CSS file to pass to mermaid.
456
+ |config |unspecified |Path to a JSON config file to pass to mermaid.
457
+ |ganttConfig |unspecified |Path to a gantt config file to pass to mermaid.
458
+ |puppeteerConfig |unspecified |Path to a puppeteer config file to pass to mermaid.
459
+ |sequenceConfig |unspecified |Path to a sequence config file to pass to mermaid.
460
+ |theme |unspecified |Theme of the chart, could be default, forest, dark or neutral.
461
+ |width |unspecified |Width of the page.
462
+ |height |unspecified |Height of the page.
430
463
  |===
431
464
 
432
465
  ==== Msc
@@ -445,6 +478,15 @@ The attribute name at the block level should be prefixed with the name of the di
445
478
  |config |unspecified |Path to a config file to pass to PlantUML.
446
479
  |===
447
480
 
481
+ ==== State Machine Cat
482
+
483
+ [cols=">,<,<",options="header"]
484
+ |===
485
+ |Name |Default value |Description
486
+ |direction |unspecifed |The direction of the state machine diagram. One of `top-down`, `bottom-top`, `left-right` or `right-left`.
487
+ |engine |unspecified |The layout engine to use. One of `dot`, `circo`, `fdp`, `neato`, `osage`, or `twopi`
488
+ |===
489
+
448
490
  ==== Syntrax
449
491
 
450
492
  [cols=">,<,<",options="header"]
@@ -160,5 +160,5 @@ Instead the name of the generated image is derived from the target propery of th
160
160
  The previous example in block macro form would look something like this with the text from the block located in a file called `activity_diagram.txt` instead of inline in the document.
161
161
 
162
162
  ----
163
- plantuml:activity_diagram.txt[format="svg", align="center"]
164
- ----
163
+ plantuml::activity_diagram.txt[format="svg", align="center"]
164
+ ----
@@ -0,0 +1,55 @@
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 AsciiToSvgConverter
9
+ include DiagramConverter
10
+ include CliGenerator
11
+
12
+ def supported_formats
13
+ [:svg]
14
+ end
15
+
16
+ def collect_options(source, name)
17
+ options = {}
18
+ options[:sx] = source.attr('scalex', nil, name)
19
+ options[:sy] = source.attr('scaley', nil, name)
20
+ options[:scale] = source.attr('scale', nil, name)
21
+ options[:noblur] = source.attr('noblur', nil, name) == 'true'
22
+ options[:font] = source.attr('fontfamily', nil, name)
23
+ options
24
+ end
25
+
26
+ def convert(source, format, options)
27
+ sx = options[:sx]
28
+ sy = options[:sy]
29
+ scale = options[:scale]
30
+ noblur = options[:noblur]
31
+ font = options[:font]
32
+
33
+ generate_stdin(source.find_command('a2s'), format.to_s, source.to_s) do |tool_path, output_path|
34
+ args = [tool_path, '-o', Platform.native_path(output_path)]
35
+
36
+ if sx && sy
37
+ args << '-s' << "#{sx},#{sy}"
38
+ elsif scale
39
+ args << '-s' << "#{scale},#{scale}"
40
+ end
41
+
42
+ if noblur
43
+ args << '-b'
44
+ end
45
+
46
+ if font
47
+ args << '-f' << font
48
+ end
49
+
50
+ args
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,60 +1,14 @@
1
- require_relative '../extensions'
2
- require_relative '../util/cli_generator'
3
- require_relative '../util/platform'
4
- require_relative '../util/which'
1
+ require_relative 'converter'
2
+ require_relative '../diagram_processor'
5
3
 
6
4
  module Asciidoctor
7
5
  module Diagram
8
- # @private
9
- module AsciiToSvg
10
- include CliGenerator
11
- include Which
12
-
13
- def self.included(mod)
14
- [:svg].each do |f|
15
- mod.register_format(f, :image) do |parent, source|
16
- a2s(parent, source, f)
17
- end
18
- end
19
- end
20
-
21
- def a2s(parent, source, format)
22
- inherit_prefix = name
23
-
24
- sx = source.attr('scalex', nil, inherit_prefix)
25
- sy = source.attr('scaley', nil, inherit_prefix)
26
- scale = source.attr('scale', nil, inherit_prefix)
27
- noblur = source.attr('noblur', 'false', inherit_prefix) == 'true'
28
- font = source.attr('fontfamily', nil, inherit_prefix)
29
-
30
- generate_stdin(which(parent, 'a2s'), format.to_s, source.to_s) do |tool_path, output_path|
31
- args = [tool_path, '-o', Platform.native_path(output_path)]
32
-
33
- if sx && sy
34
- args << '-s' << "#{sx},#{sy}"
35
- elsif scale
36
- args << '-s' << "#{scale},#{scale}"
37
- end
38
-
39
- if noblur
40
- args << '-b'
41
- end
42
-
43
- if font
44
- args << '-f' << font
45
- end
46
-
47
- args
48
- end
49
- end
50
- end
51
-
52
- class AsciiToSvgBlockProcessor < Extensions::DiagramBlockProcessor
53
- include AsciiToSvg
6
+ class AsciiToSvgBlockProcessor < DiagramBlockProcessor
7
+ use_converter AsciiToSvgConverter
54
8
  end
55
9
 
56
- class AsciiToSvgBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
57
- include AsciiToSvg
10
+ class AsciiToSvgBlockMacroProcessor < DiagramBlockMacroProcessor
11
+ use_converter AsciiToSvgConverter
58
12
  end
59
13
  end
60
14
  end
@@ -0,0 +1,37 @@
1
+ require_relative '../diagram_converter'
2
+ require_relative '../util/cli_generator'
3
+ require_relative '../util/platform'
4
+
5
+ module Asciidoctor
6
+ module Diagram
7
+ ['BlockDiag', 'SeqDiag', 'ActDiag', 'NwDiag', 'RackDiag', 'PacketDiag'].each do |name|
8
+ converter = Class.new do
9
+ include DiagramConverter
10
+ include CliGenerator
11
+
12
+ def supported_formats
13
+ [:png, :pdf, :svg]
14
+ end
15
+
16
+ def convert(source, format, options)
17
+ # On Debian based systems the Python 3.x packages python3-(act|block|nw|seq)diag executables with
18
+ # a '3' suffix.
19
+ cmd_name = self.class.const_get(:TOOL)
20
+ alt_cmd_name = "#{cmd_name}3"
21
+
22
+ font_path = source.attr('fontpath', nil, cmd_name)
23
+
24
+ generate_stdin(source.find_command(cmd_name, :alt_cmds => [alt_cmd_name]), format.to_s, source.to_s) do |tool_path, output_path|
25
+ args = [tool_path, '-a', '-o', Platform.native_path(output_path), "-T#{format.to_s}"]
26
+ args << "-f#{Platform.native_path(font_path)}" if font_path
27
+ args << '-'
28
+ args
29
+ end
30
+ end
31
+ end
32
+ converter.const_set(:TOOL, name.downcase)
33
+
34
+ ::Asciidoctor::Diagram.const_set("#{name}Converter", converter)
35
+ end
36
+ end
37
+ end
@@ -1,125 +1,18 @@
1
- require_relative '../extensions'
2
- require_relative '../util/cli_generator'
3
- require_relative '../util/platform'
4
- require_relative '../util/which'
1
+ require_relative '../diagram_processor'
2
+ require_relative 'converter'
5
3
 
6
4
  module Asciidoctor
7
5
  module Diagram
8
- # @!parse
9
- # # Block processor converts blockdiag code into images.
10
- # #
11
- # # Supports PNG and SVG output.
12
- # class BlockDiagBlockProcessor < API::DiagramBlockProcessor; end
13
- #
14
- # # Block macro processor converts blockdiag source files into images.
15
- # #
16
- # # Supports PNG and SVG output.
17
- # class BlockDiagBlockMacroProcessor < DiagramBlockMacroProcessor; end
18
-
19
- # @!parse
20
- # # Block processor converts seqdiag code into images.
21
- # #
22
- # # Supports PNG and SVG output.
23
- # class SeqDiagBlockProcessor < API::DiagramBlockProcessor; end
24
- #
25
- # # Block macro processor converts seqdiag source files into images.
26
- # #
27
- # # Supports PNG and SVG output.
28
- # class SeqDiagBlockMacroProcessor < API::DiagramBlockMacroProcessor; end
29
-
30
- # @!parse
31
- # # Block processor converts actdiag code into images.
32
- # #
33
- # # Supports PNG and SVG output.
34
- # class ActDiagBlockProcessor < API::DiagramBlockProcessor; end
35
- #
36
- # # Block macro processor converts actdiag source files into images.
37
- # #
38
- # # Supports PNG and SVG output.
39
- # class ActDiagBlockMacroProcessor < API::DiagramBlockMacroProcessor; end
40
-
41
- # @!parse
42
- # # Block processor converts nwdiag code into images.
43
- # #
44
- # # Supports PNG and SVG output.
45
- # class NwDiagBlockProcessor < API::DiagramBlockProcessor; end
46
- #
47
- # # Block macro processor converts nwdiag source files into images.
48
- # #
49
- # # Supports PNG and SVG output.
50
- # class NwDiagBlockMacroProcessor < API::DiagramBlockMacroProcessor; end
51
-
52
- # @!parse
53
- # # Block processor converts rackdiag code into images.
54
- # #
55
- # # Supports PNG and SVG output.
56
- # class RackDiagBlockProcessor < API::DiagramBlockProcessor; end
57
- #
58
- # # Block macro processor converts rackdiag source files into images.
59
- # #
60
- # # Supports PNG and SVG output.
61
- # class RackDiagBlockMacroProcessor < API::DiagramBlockMacroProcessor; end
62
-
63
- # @!parse
64
- # # Block processor converts packetdiag code into images.
65
- # #
66
- # # Supports PNG and SVG output.
67
- # class PacketDiagBlockProcessor < API::DiagramBlockProcessor; end
68
- #
69
- # # Block macro processor converts packetdiag source files into images.
70
- # #
71
- # # Supports PNG and SVG output.
72
- # class PacketDiagBlockMacroProcessor < API::DiagramBlockMacroProcessor; end
73
-
74
- # @private
75
- module BlockDiag
76
- def self.define_processors(name)
77
- init = Proc.new do
78
- include ::Asciidoctor::Diagram::BlockDiag
79
-
80
- [:png, :pdf, :svg].each do |f|
81
- register_format(f, :image) do |p, c|
82
- blockdiag(name, p, c, f)
83
- end
84
- end
85
- end
86
-
87
- block = Class.new(Extensions::DiagramBlockProcessor) do
88
- self.instance_eval(&init)
89
- end
90
- ::Asciidoctor::Diagram.const_set("#{name}BlockProcessor", block)
91
-
92
- block_macro = Class.new(Extensions::DiagramBlockMacroProcessor) do
93
- self.instance_eval(&init)
94
- end
95
-
96
- ::Asciidoctor::Diagram.const_set("#{name}BlockMacroProcessor", block_macro)
6
+ ['BlockDiag', 'SeqDiag', 'ActDiag', 'NwDiag', 'RackDiag', 'PacketDiag'].each do |tool|
7
+ block = Class.new(DiagramBlockProcessor) do
8
+ use_converter ::Asciidoctor::Diagram.const_get("#{tool}Converter")
97
9
  end
10
+ ::Asciidoctor::Diagram.const_set("#{tool}BlockProcessor", block)
98
11
 
99
- include CliGenerator
100
- include Which
101
-
102
- def blockdiag(tool, parent, source, format)
103
- inherit_prefix = name
104
- cmd_name = tool.downcase
105
-
106
- # On Debian based systems the Python 3.x packages python3-(act|block|nw|seq)diag executables with
107
- # a '3' suffix.
108
- alt_cmd_name = "#{tool.downcase}3"
109
-
110
- font_path = source.attr('fontpath', nil, inherit_prefix)
111
-
112
- generate_stdin(which(parent, cmd_name, :alt_cmds => [alt_cmd_name]), format.to_s, source.to_s) do |tool_path, output_path|
113
- args = [tool_path, '-a', '-o', Platform.native_path(output_path), "-T#{format.to_s}"]
114
- args << "-f#{Platform.native_path(font_path)}" if font_path
115
- args << '-'
116
- args
117
- end
12
+ block_macro = Class.new(DiagramBlockMacroProcessor) do
13
+ use_converter ::Asciidoctor::Diagram.const_get("#{tool}Converter")
118
14
  end
119
- end
120
-
121
- ['BlockDiag', 'SeqDiag', 'ActDiag', 'NwDiag', 'RackDiag', 'PacketDiag'].each do |tool|
122
- BlockDiag.define_processors(tool)
15
+ ::Asciidoctor::Diagram.const_set("#{tool}BlockMacroProcessor", block_macro)
123
16
  end
124
17
  end
125
18
  end
@@ -0,0 +1,62 @@
1
+ require_relative '../diagram_converter'
2
+ require_relative '../util/cli'
3
+ require_relative '../util/cli_generator'
4
+ require_relative '../util/platform'
5
+
6
+ module Asciidoctor
7
+ module Diagram
8
+ # @private
9
+ class BpmnConverter
10
+ include DiagramConverter
11
+ include CliGenerator
12
+
13
+
14
+ def supported_formats
15
+ [:png, :svg, :pdf, :jpeg]
16
+ end
17
+
18
+ def collect_options(source, name)
19
+ options = {}
20
+
21
+ options[:width] = source.attr('width', nil, name)
22
+ options[:height] = source.attr('height', nil, name)
23
+
24
+ options
25
+ end
26
+
27
+ def convert(source, format, options)
28
+ opts = {}
29
+
30
+ opts[:width] = options[:width]
31
+
32
+ bpmnjs = source.find_command('bpmn-js', :raise_on_error => false)
33
+ opts[:height] = options[:height]
34
+ opts[:theme] = options[:theme]
35
+ config = options[:config]
36
+ if config
37
+ opts[:config] = source.resolve_path(config)
38
+ end
39
+ run_bpmnjs(bpmnjs, source, format, opts)
40
+ end
41
+
42
+ private
43
+
44
+ def run_bpmnjs(bpmnjs, source, format, options = {})
45
+ generate_file(bpmnjs, 'bpmn', format.to_s, source.to_s) do |tool_path, input_path, output_path|
46
+ args = [tool_path, Platform.native_path(input_path), '-o', Platform.native_path(output_path), '-t', format.to_s]
47
+
48
+
49
+ if options[:width]
50
+ args << '--width' << options[:width]
51
+ end
52
+
53
+ if options[:height]
54
+ args << '--height' << options[:height]
55
+ end
56
+
57
+ args
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,14 @@
1
+ require_relative 'converter'
2
+ require_relative '../diagram_processor'
3
+
4
+ module Asciidoctor
5
+ module Diagram
6
+ class BpmnBlockProcessor < DiagramBlockProcessor
7
+ use_converter BpmnConverter
8
+ end
9
+
10
+ class BpmnBlockMacroProcessor < DiagramBlockMacroProcessor
11
+ use_converter BpmnConverter
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ require 'asciidoctor/extensions'
2
+ require_relative 'bpmn/extension'
3
+
4
+ Asciidoctor::Extensions.register do
5
+ block Asciidoctor::Diagram::BpmnBlockProcessor, :bpmn
6
+ block_macro Asciidoctor::Diagram::BpmnBlockMacroProcessor, :bpmn
7
+ end
@@ -0,0 +1,19 @@
1
+ module Asciidoctor
2
+ module Diagram
3
+ # This module describes the duck-typed interface that diagram converters must implement. Implementations
4
+ # may include this module but it is not required.
5
+ module DiagramConverter
6
+ def supported_formats
7
+ raise NotImplementedError.new
8
+ end
9
+
10
+ def collect_options(source, name)
11
+ {}
12
+ end
13
+
14
+ def convert(source, format, options)
15
+ raise NotImplementedError.new
16
+ end
17
+ end
18
+ end
19
+ end