asciidoctor-diagram 1.5.19 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.adoc +10 -0
  3. data/README.adoc +22 -9
  4. data/examples/features.adoc +2 -2
  5. data/lib/asciidoctor-diagram.rb +1 -0
  6. data/lib/asciidoctor-diagram/a2s/converter.rb +55 -0
  7. data/lib/asciidoctor-diagram/a2s/extension.rb +6 -52
  8. data/lib/asciidoctor-diagram/blockdiag/converter.rb +37 -0
  9. data/lib/asciidoctor-diagram/blockdiag/extension.rb +9 -116
  10. data/lib/asciidoctor-diagram/bpmn.rb +7 -0
  11. data/lib/asciidoctor-diagram/bpmn/converter.rb +62 -0
  12. data/lib/asciidoctor-diagram/bpmn/extension.rb +14 -0
  13. data/lib/asciidoctor-diagram/diagram_converter.rb +19 -0
  14. data/lib/asciidoctor-diagram/diagram_processor.rb +320 -0
  15. data/lib/asciidoctor-diagram/diagram_source.rb +275 -0
  16. data/lib/asciidoctor-diagram/ditaa/converter.rb +86 -0
  17. data/lib/asciidoctor-diagram/ditaa/extension.rb +6 -71
  18. data/lib/asciidoctor-diagram/erd/converter.rb +31 -0
  19. data/lib/asciidoctor-diagram/erd/extension.rb +6 -35
  20. data/lib/asciidoctor-diagram/gnuplot/converter.rb +63 -0
  21. data/lib/asciidoctor-diagram/gnuplot/extension.rb +6 -62
  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 +6 -53
  27. data/lib/asciidoctor-diagram/meme/converter.rb +122 -0
  28. data/lib/asciidoctor-diagram/meme/extension.rb +5 -107
  29. data/lib/asciidoctor-diagram/mermaid/converter.rb +178 -0
  30. data/lib/asciidoctor-diagram/mermaid/extension.rb +6 -159
  31. data/lib/asciidoctor-diagram/msc/converter.rb +35 -0
  32. data/lib/asciidoctor-diagram/msc/extension.rb +6 -36
  33. data/lib/asciidoctor-diagram/nomnoml/converter.rb +25 -0
  34. data/lib/asciidoctor-diagram/nomnoml/extension.rb +6 -28
  35. data/lib/asciidoctor-diagram/plantuml/converter.rb +115 -0
  36. data/lib/asciidoctor-diagram/plantuml/extension.rb +10 -119
  37. data/lib/asciidoctor-diagram/shaape/converter.rb +25 -0
  38. data/lib/asciidoctor-diagram/shaape/extension.rb +6 -28
  39. data/lib/asciidoctor-diagram/smcat/converter.rb +44 -0
  40. data/lib/asciidoctor-diagram/smcat/extension.rb +6 -42
  41. data/lib/asciidoctor-diagram/svgbob/converter.rb +25 -0
  42. data/lib/asciidoctor-diagram/svgbob/extension.rb +6 -28
  43. data/lib/asciidoctor-diagram/syntrax/converter.rb +55 -0
  44. data/lib/asciidoctor-diagram/syntrax/extension.rb +6 -51
  45. data/lib/asciidoctor-diagram/tikz/converter.rb +56 -0
  46. data/lib/asciidoctor-diagram/tikz/extension.rb +6 -60
  47. data/lib/asciidoctor-diagram/umlet/converter.rb +24 -0
  48. data/lib/asciidoctor-diagram/umlet/extension.rb +6 -28
  49. data/lib/asciidoctor-diagram/util/java.rb +1 -1
  50. data/lib/asciidoctor-diagram/util/java_socket.rb +7 -9
  51. data/lib/asciidoctor-diagram/util/which.rb +0 -29
  52. data/lib/asciidoctor-diagram/vega/converter.rb +47 -0
  53. data/lib/asciidoctor-diagram/vega/extension.rb +6 -44
  54. data/lib/asciidoctor-diagram/version.rb +1 -1
  55. data/lib/asciidoctor-diagram/wavedrom/converter.rb +50 -0
  56. data/lib/asciidoctor-diagram/wavedrom/extension.rb +6 -54
  57. data/lib/ditaa-1.3.14.jar +0 -0
  58. data/lib/plantuml-1.3.14.jar +0 -0
  59. data/lib/plantuml.jar +0 -0
  60. data/lib/server-1.3.14.jar +0 -0
  61. data/spec/bpmn-example.xml +44 -0
  62. data/spec/bpmn_spec.rb +96 -0
  63. data/spec/mermaid_spec.rb +33 -1
  64. data/spec/plantuml_spec.rb +89 -0
  65. metadata +37 -8
  66. data/lib/asciidoctor-diagram/extensions.rb +0 -568
  67. data/lib/ditaa-1.3.13.jar +0 -0
  68. data/lib/plantuml-1.3.13.jar +0 -0
  69. data/lib/server-1.3.13.jar +0 -0
@@ -15,35 +15,6 @@ module Asciidoctor
15
15
 
16
16
  nil
17
17
  end
18
-
19
- def which(parent_block, cmd, options = {})
20
- attr_names = options[:attrs] || options.fetch(:alt_attrs, []) + [cmd]
21
- cmd_names = [cmd] + options.fetch(:alt_cmds, [])
22
-
23
- cmd_var = 'cmd-' + attr_names[0]
24
-
25
- if config.key? cmd_var
26
- cmd_path = config[cmd_var]
27
- else
28
- cmd_path = attr_names.map { |attr_name| parent_block.attr(attr_name, nil, true) }.find { |attr| !attr.nil? }
29
-
30
- unless cmd_path && File.executable?(cmd_path)
31
- cmd_paths = cmd_names.map do |c|
32
- ::Asciidoctor::Diagram::Which.which(c, :path => options[:path])
33
- end
34
-
35
- cmd_path = cmd_paths.reject { |c| c.nil? }.first
36
- end
37
-
38
- config[cmd_var] = cmd_path
39
-
40
- if cmd_path.nil? && options.fetch(:raise_on_error, true)
41
- raise "Could not find the #{cmd_names.map { |c| "'#{c}'" }.join(', ')} executable in PATH; add it to the PATH or specify its location using the '#{attr_names[0]}' document attribute"
42
- end
43
- end
44
-
45
- cmd_path
46
- end
47
18
  end
48
19
  end
49
20
  end
@@ -0,0 +1,47 @@
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 VegaConverter
9
+ include DiagramConverter
10
+ include CliGenerator
11
+
12
+
13
+ def supported_formats
14
+ [:svg, :png]
15
+ end
16
+
17
+
18
+ def collect_options(source, name)
19
+ {
20
+ :vegalite => name.to_s.include?('lite') || source.attr('vegalite')
21
+ }
22
+ end
23
+
24
+ def convert(source, format, options)
25
+ base_dir = source.base_dir
26
+
27
+ code = source.to_s
28
+
29
+ if code.include?('/schema/vega-lite/') || options[:vegalite]
30
+ vega_code = generate_stdin_stdout(source.find_command("vl2vg"), code)
31
+ else
32
+ vega_code = code
33
+ end
34
+
35
+ generate_file(source.find_command("vg2#{format}"), "json", format.to_s, vega_code) do |tool_path, input_path, output_path|
36
+ args = [tool_path, '--base', Platform.native_path(base_dir)]
37
+ if format == :svg
38
+ args << '--header'
39
+ end
40
+
41
+ args << Platform.native_path(input_path)
42
+ args << Platform.native_path(output_path)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,52 +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 '../diagram_processor'
2
+ require_relative 'converter'
5
3
 
6
4
  module Asciidoctor
7
5
  module Diagram
8
- # @private
9
- module Vega
10
- include CliGenerator
11
- include Which
12
-
13
- def self.included(mod)
14
- [:svg, :png].each do |f|
15
- mod.register_format(f, :image) do |parent, source|
16
- vega(parent, source, f)
17
- end
18
- end
19
- end
20
-
21
- def vega(parent, source, format)
22
- base_dir = source.base_dir
23
-
24
- code = source.to_s
25
-
26
- if code.include?('/schema/vega-lite/') || name.to_s.include?('lite') || source.attr('vegalite')
27
- vega_code = generate_stdin_stdout(which(parent, "vl2vg"), code)
28
- else
29
- vega_code = code
30
- end
31
-
32
- generate_file(which(parent, "vg2#{format}"), "json", format.to_s, vega_code) do |tool_path, input_path, output_path|
33
- args = [tool_path, '--base', Platform.native_path(base_dir)]
34
- if format == :svg
35
- args << '--header'
36
- end
37
-
38
- args << Platform.native_path(input_path)
39
- args << Platform.native_path(output_path)
40
- end
41
- end
42
- end
43
-
44
- class VegaBlockProcessor < Extensions::DiagramBlockProcessor
45
- include Vega
6
+ class VegaBlockProcessor < DiagramBlockProcessor
7
+ use_converter VegaConverter
46
8
  end
47
9
 
48
- class VegaBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
49
- include Vega
10
+ class VegaBlockMacroProcessor < DiagramBlockMacroProcessor
11
+ use_converter VegaConverter
50
12
  end
51
13
  end
52
14
  end
@@ -1,5 +1,5 @@
1
1
  module Asciidoctor
2
2
  module Diagram
3
- VERSION = "1.5.19"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
@@ -0,0 +1,50 @@
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 WavedromConverter
9
+ include DiagramConverter
10
+ include CliGenerator
11
+
12
+
13
+ def supported_formats
14
+ [:png, :svg]
15
+ end
16
+
17
+
18
+ def convert(source, format, options)
19
+ wavedrom_cli = source.find_command('wavedrom-cli', :raise_on_error => false)
20
+ if wavedrom_cli
21
+ generate_file(wavedrom_cli, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
22
+ [Platform.native_path(tool_path), '--input', Platform.native_path(input_path), "--#{format.to_s}", Platform.native_path(output_path)]
23
+ end
24
+ else
25
+ wavedrom_cli = source.find_command('wavedrom', :raise_on_error => false)
26
+ phantomjs = source.find_command('phantomjs', :alt_attrs => ['phantomjs_2'], :raise_on_error => false)
27
+
28
+ if wavedrom_cli && !wavedrom_cli.include?('WaveDromEditor') && phantomjs
29
+ generate_file(wavedrom_cli, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
30
+ [phantomjs, Platform.native_path(tool_path), '-i', Platform.native_path(input_path), "-#{format.to_s[0]}", Platform.native_path(output_path)]
31
+ end
32
+ else
33
+ if ::Asciidoctor::Diagram::Platform.os == :macosx
34
+ wavedrom = source.find_command('WaveDromEditor.app', :alt_cmds => ['wavedrom-editor.app'], :attrs => ['WaveDromEditorApp'], :path => ['/Applications'])
35
+ if wavedrom
36
+ wavedrom = File.join(wavedrom, 'Contents/MacOS/nwjs')
37
+ end
38
+ else
39
+ wavedrom = source.find_command('WaveDromEditor')
40
+ end
41
+
42
+ generate_file(wavedrom, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
43
+ [tool_path, 'source', Platform.native_path(input_path), format.to_s, Platform.native_path(output_path)]
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,62 +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 '../diagram_processor'
2
+ require_relative 'converter'
5
3
 
6
4
  module Asciidoctor
7
5
  module Diagram
8
- # @private
9
- module Wavedrom
10
- include CliGenerator
11
- include Which
12
-
13
- def self.included(mod)
14
- [:png, :svg].each do |f|
15
- mod.register_format(f, :image) do |parent, source|
16
- wavedrom(parent, source, f)
17
- end
18
- end
19
- end
20
-
21
- def wavedrom(parent, source, format)
22
- wavedrom_cli = which(parent, 'wavedrom-cli', :raise_on_error => false)
23
-
24
- if wavedrom_cli
25
- generate_file(wavedrom_cli, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
26
- [Platform.native_path(tool_path), '--input', Platform.native_path(input_path), "--#{format.to_s}", Platform.native_path(output_path)]
27
- end
28
- else
29
- wavedrom_cli = which(parent, 'wavedrom', :raise_on_error => false)
30
- phantomjs = which(parent, 'phantomjs', :alt_attrs => ['phantomjs_2'], :raise_on_error => false)
31
-
32
- if wavedrom_cli && !wavedrom_cli.include?('WaveDromEditor') && phantomjs
33
- generate_file(wavedrom_cli, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
34
- [phantomjs, Platform.native_path(tool_path), '-i', Platform.native_path(input_path), "-#{format.to_s[0]}", Platform.native_path(output_path)]
35
- end
36
- else
37
- if ::Asciidoctor::Diagram::Platform.os == :macosx
38
- wavedrom = which(parent, 'WaveDromEditor.app', :alt_cmds => ['wavedrom-editor.app'], :attrs => ['WaveDromEditorApp'],:path => ['/Applications'])
39
- if wavedrom
40
- wavedrom = File.join(wavedrom, 'Contents/MacOS/nwjs')
41
- end
42
- else
43
- wavedrom = which(parent, 'WaveDromEditor')
44
- end
45
-
46
- generate_file(wavedrom, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
47
- [tool_path, 'source', Platform.native_path(input_path), format.to_s, Platform.native_path(output_path)]
48
- end
49
- end
50
- end
51
- end
52
- end
53
-
54
- class WavedromBlockProcessor < Extensions::DiagramBlockProcessor
55
- include Wavedrom
6
+ class WavedromBlockProcessor < DiagramBlockProcessor
7
+ use_converter WavedromConverter
56
8
  end
57
9
 
58
- class WavedromBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
59
- include Wavedrom
10
+ class WavedromBlockMacroProcessor < DiagramBlockMacroProcessor
11
+ use_converter WavedromConverter
60
12
  end
61
13
  end
62
14
  end
Binary file
Binary file
data/lib/plantuml.jar CHANGED
Binary file
Binary file
@@ -0,0 +1,44 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_0zt4mn9" targetNamespace="http://bpmn.io/schema/bpmn" exporter="bpmn-js (https://demo.bpmn.io)" exporterVersion="5.1.2">
3
+ <bpmn:process id="Process_081h9u7" isExecutable="false">
4
+ <bpmn:startEvent id="StartEvent_00w25dz" name="Start">
5
+ <bpmn:outgoing>SequenceFlow_11u0n1f</bpmn:outgoing>
6
+ </bpmn:startEvent>
7
+ <bpmn:task id="Task_0yx8j7s" name="Task">
8
+ <bpmn:incoming>SequenceFlow_11u0n1f</bpmn:incoming>
9
+ <bpmn:outgoing>SequenceFlow_104th5x</bpmn:outgoing>
10
+ </bpmn:task>
11
+ <bpmn:sequenceFlow id="SequenceFlow_11u0n1f" sourceRef="StartEvent_00w25dz" targetRef="Task_0yx8j7s" />
12
+ <bpmn:endEvent id="EndEvent_0jxehtp" name="End">
13
+ <bpmn:incoming>SequenceFlow_104th5x</bpmn:incoming>
14
+ </bpmn:endEvent>
15
+ <bpmn:sequenceFlow id="SequenceFlow_104th5x" sourceRef="Task_0yx8j7s" targetRef="EndEvent_0jxehtp" />
16
+ </bpmn:process>
17
+ <bpmndi:BPMNDiagram id="BPMNDiagram_1">
18
+ <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_081h9u7">
19
+ <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_00w25dz">
20
+ <dc:Bounds x="156" y="81" width="36" height="36" />
21
+ <bpmndi:BPMNLabel>
22
+ <dc:Bounds x="162" y="124" width="24" height="14" />
23
+ </bpmndi:BPMNLabel>
24
+ </bpmndi:BPMNShape>
25
+ <bpmndi:BPMNShape id="Task_0yx8j7s_di" bpmnElement="Task_0yx8j7s">
26
+ <dc:Bounds x="250" y="59" width="100" height="80" />
27
+ </bpmndi:BPMNShape>
28
+ <bpmndi:BPMNEdge id="SequenceFlow_11u0n1f_di" bpmnElement="SequenceFlow_11u0n1f">
29
+ <di:waypoint x="192" y="99" />
30
+ <di:waypoint x="250" y="99" />
31
+ </bpmndi:BPMNEdge>
32
+ <bpmndi:BPMNShape id="EndEvent_0jxehtp_di" bpmnElement="EndEvent_0jxehtp">
33
+ <dc:Bounds x="412" y="81" width="36" height="36" />
34
+ <bpmndi:BPMNLabel>
35
+ <dc:Bounds x="420" y="124" width="20" height="14" />
36
+ </bpmndi:BPMNLabel>
37
+ </bpmndi:BPMNShape>
38
+ <bpmndi:BPMNEdge id="SequenceFlow_104th5x_di" bpmnElement="SequenceFlow_104th5x">
39
+ <di:waypoint x="350" y="99" />
40
+ <di:waypoint x="412" y="99" />
41
+ </bpmndi:BPMNEdge>
42
+ </bpmndi:BPMNPlane>
43
+ </bpmndi:BPMNDiagram>
44
+ </bpmn:definitions>
data/spec/bpmn_spec.rb ADDED
@@ -0,0 +1,96 @@
1
+ require_relative 'test_helper'
2
+
3
+ describe Asciidoctor::Diagram::BpmnBlockMacroProcessor do
4
+ it "should generate SVG images when format is set to 'svg'" do
5
+ FileUtils.cp(
6
+ File.expand_path('bpmn-example.xml', File.dirname(__FILE__)),
7
+ File.expand_path('bpmn-example.xml', Dir.getwd)
8
+ )
9
+
10
+ doc = <<-eos
11
+ = Hello, BPMN!
12
+ Doc Writer <doc@example.com>
13
+
14
+ == First Section
15
+
16
+ bpmn::bpmn-example.xml[format="svg"]
17
+ eos
18
+
19
+ d = load_asciidoc doc
20
+ expect(d).to_not be_nil
21
+
22
+ b = d.find { |bl| bl.context == :image }
23
+ expect(b).to_not be_nil
24
+
25
+ expect(b.content_model).to eq :empty
26
+
27
+ target = b.attributes['target']
28
+ expect(target).to_not be_nil
29
+ expect(target).to match(/\.svg/)
30
+ expect(File.exist?(target)).to be true
31
+
32
+ expect(b.attributes['width']).to_not be_nil
33
+ expect(b.attributes['height']).to_not be_nil
34
+ end
35
+
36
+ it "should generate PNG images when format is set to 'png'" do
37
+ FileUtils.cp(
38
+ File.expand_path('bpmn-example.xml', File.dirname(__FILE__)),
39
+ File.expand_path('bpmn-example.xml', Dir.getwd)
40
+ )
41
+
42
+ doc = <<-eos
43
+ = Hello, BPMN!
44
+ Doc Writer <doc@example.com>
45
+
46
+ == First Section
47
+
48
+ bpmn::bpmn-example.xml[format="png"]
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
+
57
+ expect(b.content_model).to eq :empty
58
+
59
+ target = b.attributes['target']
60
+ expect(target).to_not be_nil
61
+ expect(target).to match(/\.png$/)
62
+ expect(File.exist?(target)).to be true
63
+
64
+ expect(b.attributes['width']).to_not be_nil
65
+ expect(b.attributes['height']).to_not be_nil
66
+ end
67
+
68
+ it "should generate PDF images when format is set to 'pdf'" do
69
+ FileUtils.cp(
70
+ File.expand_path('bpmn-example.xml', File.dirname(__FILE__)),
71
+ File.expand_path('bpmn-example.xml', Dir.getwd)
72
+ )
73
+
74
+ doc = <<-eos
75
+ = Hello, BPMN!
76
+ Doc Writer <doc@example.com>
77
+
78
+ == First Section
79
+
80
+ bpmn::bpmn-example.xml[format="pdf"]
81
+ eos
82
+
83
+ d = load_asciidoc doc
84
+ expect(d).to_not be_nil
85
+
86
+ b = d.find { |bl| bl.context == :image }
87
+ expect(b).to_not be_nil
88
+
89
+ expect(b.content_model).to eq :empty
90
+
91
+ target = b.attributes['target']
92
+ expect(target).to_not be_nil
93
+ expect(target).to match(/\.pdf$/)
94
+ expect(File.exist?(target)).to be true
95
+ end
96
+ end
data/spec/mermaid_spec.rb CHANGED
@@ -301,4 +301,36 @@ mermaid::mermaid.txt["dark", format="svg", theme="dark"]
301
301
  expect(File.exist?('dark.svg')).to be true
302
302
  expect(File.read('default.svg')).to_not be File.read('dark.svg')
303
303
  end
304
- end
304
+
305
+ it "should respect the puppeteerConfig attribute" do
306
+ seq_diag = <<-eos
307
+ sequenceDiagram
308
+ Alice->>John: Hello John, how are you?
309
+ John-->>Alice: Great!
310
+ eos
311
+
312
+ pptr_config = <<-eos
313
+ {
314
+ "args": ["--no-sandbox"]
315
+ }
316
+ eos
317
+ File.write('pptrconfig.txt', pptr_config)
318
+
319
+ File.write('mermaid.txt', seq_diag)
320
+
321
+ doc = <<-eos
322
+ = Hello, Mermaid!
323
+ Doc Writer <doc@example.com>
324
+
325
+ == First Section
326
+
327
+ mermaid::mermaid.txt["with_config", puppeteerConfig="pptrconfig.txt"]
328
+ mermaid::mermaid.txt["without_config"]
329
+ eos
330
+
331
+ load_asciidoc doc
332
+ expect(File.exist?('with_config.png')).to be true
333
+ expect(File.exist?('without_config.png')).to be true
334
+ expect(File.size('with_config.png')).to be File.size('without_config.png')
335
+ end
336
+ end