asciidoctor-diagram 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.adoc +262 -7
  3. data/README.adoc +463 -40
  4. data/README_zh-CN.adoc +336 -0
  5. data/Rakefile +3 -7
  6. data/examples/features.adoc +2 -2
  7. data/images/asciidoctor-diagram-classes.png +0 -0
  8. data/images/asciidoctor-diagram-process.png +0 -0
  9. data/lib/asciidoctor-diagram/a2s/converter.rb +55 -0
  10. data/lib/asciidoctor-diagram/a2s/extension.rb +14 -0
  11. data/lib/asciidoctor-diagram/a2s.rb +7 -0
  12. data/lib/asciidoctor-diagram/blockdiag/converter.rb +37 -0
  13. data/lib/asciidoctor-diagram/blockdiag/extension.rb +11 -11
  14. data/lib/asciidoctor-diagram/blockdiag.rb +5 -4
  15. data/lib/asciidoctor-diagram/bpmn/converter.rb +62 -0
  16. data/lib/asciidoctor-diagram/bpmn/extension.rb +14 -0
  17. data/lib/asciidoctor-diagram/bpmn.rb +7 -0
  18. data/lib/asciidoctor-diagram/diagram_converter.rb +19 -0
  19. data/lib/asciidoctor-diagram/diagram_processor.rb +320 -0
  20. data/lib/asciidoctor-diagram/diagram_source.rb +275 -0
  21. data/lib/asciidoctor-diagram/ditaa/converter.rb +86 -0
  22. data/lib/asciidoctor-diagram/ditaa/extension.rb +6 -28
  23. data/lib/asciidoctor-diagram/ditaa.rb +3 -4
  24. data/lib/asciidoctor-diagram/erd/converter.rb +31 -0
  25. data/lib/asciidoctor-diagram/erd/extension.rb +14 -0
  26. data/lib/asciidoctor-diagram/erd.rb +7 -0
  27. data/lib/asciidoctor-diagram/gnuplot/converter.rb +63 -0
  28. data/lib/asciidoctor-diagram/gnuplot/extension.rb +14 -0
  29. data/lib/asciidoctor-diagram/gnuplot.rb +7 -0
  30. data/lib/asciidoctor-diagram/graphviz/converter.rb +32 -0
  31. data/lib/asciidoctor-diagram/graphviz/extension.rb +8 -10
  32. data/lib/asciidoctor-diagram/graphviz.rb +3 -4
  33. data/lib/asciidoctor-diagram/http/server.rb +127 -0
  34. data/lib/asciidoctor-diagram/lilypond/converter.rb +54 -0
  35. data/lib/asciidoctor-diagram/lilypond/extension.rb +14 -0
  36. data/lib/asciidoctor-diagram/lilypond.rb +7 -0
  37. data/lib/asciidoctor-diagram/meme/converter.rb +122 -0
  38. data/lib/asciidoctor-diagram/meme/extension.rb +28 -0
  39. data/lib/asciidoctor-diagram/meme.rb +6 -0
  40. data/lib/asciidoctor-diagram/mermaid/converter.rb +178 -0
  41. data/lib/asciidoctor-diagram/mermaid/extension.rb +14 -0
  42. data/lib/asciidoctor-diagram/mermaid.rb +7 -0
  43. data/lib/asciidoctor-diagram/msc/converter.rb +35 -0
  44. data/lib/asciidoctor-diagram/msc/extension.rb +14 -0
  45. data/lib/asciidoctor-diagram/msc.rb +7 -0
  46. data/lib/asciidoctor-diagram/nomnoml/converter.rb +25 -0
  47. data/lib/asciidoctor-diagram/nomnoml/extension.rb +14 -0
  48. data/lib/asciidoctor-diagram/nomnoml.rb +7 -0
  49. data/lib/asciidoctor-diagram/plantuml/converter.rb +115 -0
  50. data/lib/asciidoctor-diagram/plantuml/extension.rb +14 -20
  51. data/lib/asciidoctor-diagram/plantuml.rb +3 -5
  52. data/lib/asciidoctor-diagram/salt.rb +7 -0
  53. data/lib/asciidoctor-diagram/shaape/converter.rb +25 -0
  54. data/lib/asciidoctor-diagram/shaape/extension.rb +9 -11
  55. data/lib/asciidoctor-diagram/shaape.rb +3 -5
  56. data/lib/asciidoctor-diagram/smcat/converter.rb +44 -0
  57. data/lib/asciidoctor-diagram/smcat/extension.rb +14 -0
  58. data/lib/asciidoctor-diagram/smcat.rb +7 -0
  59. data/lib/asciidoctor-diagram/svgbob/converter.rb +25 -0
  60. data/lib/asciidoctor-diagram/svgbob/extension.rb +14 -0
  61. data/lib/asciidoctor-diagram/svgbob.rb +7 -0
  62. data/lib/asciidoctor-diagram/syntrax/converter.rb +55 -0
  63. data/lib/asciidoctor-diagram/syntrax/extension.rb +14 -0
  64. data/lib/asciidoctor-diagram/syntrax.rb +7 -0
  65. data/lib/asciidoctor-diagram/tikz/converter.rb +56 -0
  66. data/lib/asciidoctor-diagram/tikz/extension.rb +14 -0
  67. data/lib/asciidoctor-diagram/tikz.rb +7 -0
  68. data/lib/asciidoctor-diagram/umlet/converter.rb +24 -0
  69. data/lib/asciidoctor-diagram/umlet/extension.rb +14 -0
  70. data/lib/asciidoctor-diagram/umlet.rb +7 -0
  71. data/lib/asciidoctor-diagram/util/binaryio.rb +20 -0
  72. data/lib/asciidoctor-diagram/util/cli.rb +81 -0
  73. data/lib/asciidoctor-diagram/util/cli_generator.rb +73 -22
  74. data/lib/asciidoctor-diagram/util/gif.rb +21 -0
  75. data/lib/asciidoctor-diagram/util/java.rb +95 -1
  76. data/lib/asciidoctor-diagram/util/java_jruby.rb +14 -20
  77. data/lib/asciidoctor-diagram/util/java_socket.rb +175 -0
  78. data/lib/asciidoctor-diagram/util/pdf.rb +10 -0
  79. data/lib/asciidoctor-diagram/util/platform.rb +97 -0
  80. data/lib/asciidoctor-diagram/util/png.rb +1 -0
  81. data/lib/asciidoctor-diagram/util/svg.rb +4 -3
  82. data/lib/asciidoctor-diagram/util/which.rb +15 -9
  83. data/lib/asciidoctor-diagram/vega/converter.rb +47 -0
  84. data/lib/asciidoctor-diagram/vega/extension.rb +14 -0
  85. data/lib/asciidoctor-diagram/vega.rb +10 -0
  86. data/lib/asciidoctor-diagram/version.rb +1 -1
  87. data/lib/asciidoctor-diagram/wavedrom/converter.rb +50 -0
  88. data/lib/asciidoctor-diagram/wavedrom/extension.rb +14 -0
  89. data/lib/asciidoctor-diagram/wavedrom.rb +7 -0
  90. data/lib/asciidoctor-diagram.rb +22 -5
  91. data/lib/batik-all-1.10.jar +0 -0
  92. data/lib/ditaa-1.3.14.jar +0 -0
  93. data/lib/ditaamini-0.12.jar +0 -0
  94. data/lib/jlatexmath-minimal-1.0.5.jar +0 -0
  95. data/lib/plantuml-1.3.14.jar +0 -0
  96. data/lib/plantuml.jar +0 -0
  97. data/lib/server-1.3.14.jar +0 -0
  98. data/spec/a2s_spec.rb +167 -0
  99. data/spec/blockdiag_spec.rb +55 -24
  100. data/spec/bpmn-example.xml +44 -0
  101. data/spec/bpmn_spec.rb +96 -0
  102. data/spec/ditaa_spec.rb +150 -15
  103. data/spec/erd_spec.rb +289 -0
  104. data/spec/gnuplot_spec.rb +478 -0
  105. data/spec/graphviz_spec.rb +20 -20
  106. data/spec/lilypond_spec.rb +151 -0
  107. data/spec/man.jpg +0 -0
  108. data/spec/meme_spec.rb +67 -0
  109. data/spec/mermaid_spec.rb +336 -0
  110. data/spec/msc_spec.rb +230 -0
  111. data/spec/nomnoml_spec.rb +170 -0
  112. data/spec/plantuml_spec.rb +895 -54
  113. data/spec/shaape_spec.rb +25 -24
  114. data/spec/smcat_spec.rb +164 -0
  115. data/spec/svgbob_spec.rb +167 -0
  116. data/spec/syntrax_spec.rb +228 -0
  117. data/spec/test_helper.rb +88 -9
  118. data/spec/tikz_spec.rb +127 -0
  119. data/spec/umlet_spec.rb +85 -0
  120. data/spec/vega_spec.rb +241 -0
  121. data/spec/wavedrom_spec.rb +214 -0
  122. metadata +130 -35
  123. data/lib/asciidoctor-diagram/plantuml/generator.rb +0 -46
  124. data/lib/asciidoctor-diagram/util/diagram.rb +0 -220
  125. data/lib/asciidoctor-diagram/util/java_rjb.rb +0 -90
  126. data/lib/ditaamini0_9.jar +0 -0
data/spec/shaape_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require_relative 'test_helper'
2
2
 
3
- describe Asciidoctor::Diagram::ShaapeBlockMacro do
3
+ describe Asciidoctor::Diagram::ShaapeBlockMacroProcessor, :broken_on_osx, :broken_on_appveyor do
4
4
  it "should generate PNG images when format is set to 'png'" do
5
5
  code = <<-eos
6
6
  +--------+ +-------------+
@@ -22,25 +22,25 @@ Doc Writer <doc@example.com>
22
22
  shaape::shaape.txt[format="png"]
23
23
  eos
24
24
 
25
- d = Asciidoctor.load StringIO.new(doc)
25
+ d = load_asciidoc doc
26
26
  expect(d).to_not be_nil
27
27
 
28
- b = d.find { |b| b.context == :image }
28
+ b = d.find { |bl| bl.context == :image }
29
29
  expect(b).to_not be_nil
30
30
 
31
31
  expect(b.content_model).to eq :empty
32
32
 
33
33
  target = b.attributes['target']
34
34
  expect(target).to_not be_nil
35
- expect(target).to match /\.png$/
36
- expect(File.exists?(target)).to be true
35
+ expect(target).to match(/\.png$/)
36
+ expect(File.exist?(target)).to be true
37
37
 
38
38
  expect(b.attributes['width']).to_not be_nil
39
39
  expect(b.attributes['height']).to_not be_nil
40
40
  end
41
41
  end
42
42
 
43
- describe Asciidoctor::Diagram::ShaapeBlock do
43
+ describe Asciidoctor::Diagram::ShaapeBlockProcessor, :broken_on_osx, :broken_on_appveyor do
44
44
  it "should generate PNG images when format is set to 'png'" do
45
45
  doc = <<-eos
46
46
  = Hello, Shaape!
@@ -59,18 +59,18 @@ Doc Writer <doc@example.com>
59
59
  ----
60
60
  eos
61
61
 
62
- d = Asciidoctor.load StringIO.new(doc)
62
+ d = load_asciidoc doc
63
63
  expect(d).to_not be_nil
64
64
 
65
- b = d.find { |b| b.context == :image }
65
+ b = d.find { |bl| bl.context == :image }
66
66
  expect(b).to_not be_nil
67
67
 
68
68
  expect(b.content_model).to eq :empty
69
69
 
70
70
  target = b.attributes['target']
71
71
  expect(target).to_not be_nil
72
- expect(target).to match /\.png$/
73
- expect(File.exists?(target)).to be true
72
+ expect(target).to match(/\.png$/)
73
+ expect(File.exist?(target)).to be true
74
74
 
75
75
  expect(b.attributes['width']).to_not be_nil
76
76
  expect(b.attributes['height']).to_not be_nil
@@ -94,18 +94,18 @@ Doc Writer <doc@example.com>
94
94
  ----
95
95
  eos
96
96
 
97
- d = Asciidoctor.load StringIO.new(doc)
97
+ d = load_asciidoc doc
98
98
  expect(d).to_not be_nil
99
99
 
100
- b = d.find { |b| b.context == :image }
100
+ b = d.find { |bl| bl.context == :image }
101
101
  expect(b).to_not be_nil
102
102
 
103
103
  expect(b.content_model).to eq :empty
104
104
 
105
105
  target = b.attributes['target']
106
106
  expect(target).to_not be_nil
107
- expect(target).to match /\.svg/
108
- expect(File.exists?(target)).to be true
107
+ expect(target).to match(/\.svg/)
108
+ expect(File.exist?(target)).to be true
109
109
 
110
110
  expect(b.attributes['width']).to_not be_nil
111
111
  expect(b.attributes['height']).to_not be_nil
@@ -123,7 +123,7 @@ Doc Writer <doc@example.com>
123
123
  ----
124
124
  eos
125
125
 
126
- expect { Asciidoctor.load StringIO.new(doc) }.to raise_error /support.*format/i
126
+ expect { load_asciidoc doc }.to raise_error(/support.*format/i)
127
127
  end
128
128
 
129
129
  it "should not regenerate images when source has not changed" do
@@ -157,14 +157,15 @@ shaape::shaape.txt
157
157
  ----
158
158
  eos
159
159
 
160
- d = Asciidoctor.load StringIO.new(doc)
161
- b = d.find { |b| b.context == :image }
160
+ d = load_asciidoc doc
161
+ b = d.find { |bl| bl.context == :image }
162
+ expect(b).to_not be_nil
162
163
  target = b.attributes['target']
163
164
  mtime1 = File.mtime(target)
164
165
 
165
166
  sleep 1
166
167
 
167
- d = Asciidoctor.load StringIO.new(doc)
168
+ d = load_asciidoc doc
168
169
 
169
170
  mtime2 = File.mtime(target)
170
171
 
@@ -193,8 +194,8 @@ shaape::shaape.txt[]
193
194
  shaape::shaape.txt[]
194
195
  eos
195
196
 
196
- Asciidoctor.load StringIO.new(doc)
197
- expect(File.exists?('shaape.png')).to be true
197
+ load_asciidoc doc
198
+ expect(File.exist?('shaape.png')).to be true
198
199
  end
199
200
 
200
201
  it "should respect target attribute in block macros" do
@@ -219,9 +220,9 @@ shaape::shaape.txt["foobar"]
219
220
  shaape::shaape.txt["foobaz"]
220
221
  eos
221
222
 
222
- Asciidoctor.load StringIO.new(doc)
223
- expect(File.exists?('foobar.png')).to be true
224
- expect(File.exists?('foobaz.png')).to be true
225
- expect(File.exists?('shaape.png')).to be false
223
+ load_asciidoc doc
224
+ expect(File.exist?('foobar.png')).to be true
225
+ expect(File.exist?('foobaz.png')).to be true
226
+ expect(File.exist?('shaape.png')).to be false
226
227
  end
227
228
  end
@@ -0,0 +1,164 @@
1
+ require_relative 'test_helper'
2
+
3
+ code = <<-eos
4
+ initial,
5
+ doing: entry/ write unit test
6
+ do/ write code
7
+ exit/ ...,
8
+ # smcat recognizes initial
9
+ # and final states by name
10
+ # and renders them appropriately
11
+ final;
12
+
13
+ initial => "on backlog" : item adds most value;
14
+ "on backlog" => doing : working on it;
15
+ doing => testing : built & unit tested;
16
+ testing => "on backlog" : test not ok;
17
+ testing => final : test ok;
18
+ eos
19
+
20
+ describe Asciidoctor::Diagram::SmcatBlockMacroProcessor, :broken_on_windows do
21
+ it "should generate SVG images when format is set to 'svg'" do
22
+ File.write('smcat.txt', code)
23
+
24
+ doc = <<-eos
25
+ = Hello, Smcat!
26
+ Doc Writer <doc@example.com>
27
+
28
+ == First Section
29
+
30
+ smcat::smcat.txt[format="svg"]
31
+ eos
32
+
33
+ d = load_asciidoc doc
34
+ expect(d).to_not be_nil
35
+
36
+ b = d.find { |bl| bl.context == :image }
37
+ expect(b).to_not be_nil
38
+
39
+ expect(b.content_model).to eq :empty
40
+
41
+ target = b.attributes['target']
42
+ expect(target).to_not be_nil
43
+ expect(target).to match(/\.svg/)
44
+ expect(File.exist?(target)).to be true
45
+
46
+ expect(b.attributes['width']).to_not be_nil
47
+ expect(b.attributes['height']).to_not be_nil
48
+ end
49
+ end
50
+
51
+ describe Asciidoctor::Diagram::SmcatBlockProcessor, :broken_on_windows do
52
+ it "should generate SVG images when format is set to 'svg'" do
53
+ doc = <<-eos
54
+ = Hello, Smcat!
55
+ Doc Writer <doc@example.com>
56
+
57
+ == First Section
58
+
59
+ [smcat, format="svg"]
60
+ ----
61
+ #{code}
62
+ ----
63
+ eos
64
+
65
+ d = load_asciidoc doc
66
+ expect(d).to_not be_nil
67
+
68
+ b = d.find { |bl| bl.context == :image }
69
+ expect(b).to_not be_nil
70
+
71
+ expect(b.content_model).to eq :empty
72
+
73
+ target = b.attributes['target']
74
+ expect(target).to_not be_nil
75
+ expect(target).to match(/\.svg/)
76
+ expect(File.exist?(target)).to be true
77
+
78
+ expect(b.attributes['width']).to_not be_nil
79
+ expect(b.attributes['height']).to_not be_nil
80
+ end
81
+
82
+ it "should raise an error when when format is set to an invalid value" do
83
+ doc = <<-eos
84
+ = Hello, Smcat!
85
+ Doc Writer <doc@example.com>
86
+
87
+ == First Section
88
+
89
+ [smcat, format="foobar"]
90
+ ----
91
+ ----
92
+ eos
93
+
94
+ expect { load_asciidoc doc }.to raise_error(/support.*format/i)
95
+ end
96
+
97
+ it "should not regenerate images when source has not changed" do
98
+ File.write('smcat.txt', code)
99
+
100
+ doc = <<-eos
101
+ = Hello, Smcat!
102
+ Doc Writer <doc@example.com>
103
+
104
+ == First Section
105
+
106
+ smcat::smcat.txt
107
+
108
+ [smcat, format="svg"]
109
+ ----
110
+ #{code}
111
+ ----
112
+ eos
113
+
114
+ d = load_asciidoc doc
115
+ b = d.find { |bl| bl.context == :image }
116
+ expect(b).to_not be_nil
117
+ target = b.attributes['target']
118
+ mtime1 = File.mtime(target)
119
+
120
+ sleep 1
121
+
122
+ d = load_asciidoc doc
123
+
124
+ mtime2 = File.mtime(target)
125
+
126
+ expect(mtime2).to eq mtime1
127
+ end
128
+
129
+ it "should handle two block macros with the same source" do
130
+ File.write('smcat.txt', code)
131
+
132
+ doc = <<-eos
133
+ = Hello, Smcat!
134
+ Doc Writer <doc@example.com>
135
+
136
+ == First Section
137
+
138
+ smcat::smcat.txt[]
139
+ smcat::smcat.txt[]
140
+ eos
141
+
142
+ load_asciidoc doc
143
+ expect(File.exist?('smcat.svg')).to be true
144
+ end
145
+
146
+ it "should respect target attribute in block macros" do
147
+ File.write('smcat.txt', code)
148
+
149
+ doc = <<-eos
150
+ = Hello, Smcat!
151
+ Doc Writer <doc@example.com>
152
+
153
+ == First Section
154
+
155
+ smcat::smcat.txt["foobar"]
156
+ smcat::smcat.txt["foobaz"]
157
+ eos
158
+
159
+ load_asciidoc doc
160
+ expect(File.exist?('foobar.svg')).to be true
161
+ expect(File.exist?('foobaz.svg')).to be true
162
+ expect(File.exist?('smcat.svg')).to be false
163
+ end
164
+ end
@@ -0,0 +1,167 @@
1
+ require_relative 'test_helper'
2
+
3
+ code = <<-eos
4
+ .--. .---. .---. .---. .---. .---. .---.
5
+ | | OS API '---' '---' '---' '---' '---' '---'
6
+ v | | | | | | |
7
+ .-. .-. .-. | v v | v | v
8
+ .-->'-' '-' '-' | .------------. | .-----------. | .-----.
9
+ | \\ | / | | Filesystem | | | Scheduler | | | MMU |
10
+ | v . v | '------------' | '-----------' | '-----'
11
+ '_______/ \\_____| | | | |
12
+ \\ / v | | v
13
+ | ____ .----. | | .---------.
14
+ '--> /___/ | IO |<----' | | Network |
15
+ '----' | '---------'
16
+ | | |
17
+ v v v
18
+ .---------------------------------------.
19
+ | HAL |
20
+ '---------------------------------------'
21
+ eos
22
+
23
+ describe Asciidoctor::Diagram::SvgBobBlockMacroProcessor, :broken_on_travis, :broken_on_windows do
24
+ it "should generate SVG images when format is set to 'svg'" do
25
+ File.write('svgbob.txt', code)
26
+
27
+ doc = <<-eos
28
+ = Hello, SvgBob!
29
+ Doc Writer <doc@example.com>
30
+
31
+ == First Section
32
+
33
+ svgbob::svgbob.txt[format="svg"]
34
+ eos
35
+
36
+ d = load_asciidoc doc
37
+ expect(d).to_not be_nil
38
+
39
+ b = d.find { |bl| bl.context == :image }
40
+ expect(b).to_not be_nil
41
+
42
+ expect(b.content_model).to eq :empty
43
+
44
+ target = b.attributes['target']
45
+ expect(target).to_not be_nil
46
+ expect(target).to match(/\.svg/)
47
+ expect(File.exist?(target)).to be true
48
+
49
+ expect(b.attributes['width']).to_not be_nil
50
+ expect(b.attributes['height']).to_not be_nil
51
+ end
52
+ end
53
+
54
+ describe Asciidoctor::Diagram::SvgBobBlockProcessor, :broken_on_travis, :broken_on_windows do
55
+ it "should generate SVG images when format is set to 'svg'" do
56
+ doc = <<-eos
57
+ = Hello, SvgBob!
58
+ Doc Writer <doc@example.com>
59
+
60
+ == First Section
61
+
62
+ [svgbob, format="svg"]
63
+ ----
64
+ #{code}
65
+ ----
66
+ eos
67
+
68
+ d = load_asciidoc doc
69
+ expect(d).to_not be_nil
70
+
71
+ b = d.find { |bl| bl.context == :image }
72
+ expect(b).to_not be_nil
73
+
74
+ expect(b.content_model).to eq :empty
75
+
76
+ target = b.attributes['target']
77
+ expect(target).to_not be_nil
78
+ expect(target).to match(/\.svg/)
79
+ expect(File.exist?(target)).to be true
80
+
81
+ expect(b.attributes['width']).to_not be_nil
82
+ expect(b.attributes['height']).to_not be_nil
83
+ end
84
+
85
+ it "should raise an error when when format is set to an invalid value" do
86
+ doc = <<-eos
87
+ = Hello, SvgBob!
88
+ Doc Writer <doc@example.com>
89
+
90
+ == First Section
91
+
92
+ [svgbob, format="foobar"]
93
+ ----
94
+ ----
95
+ eos
96
+
97
+ expect { load_asciidoc doc }.to raise_error(/support.*format/i)
98
+ end
99
+
100
+ it "should not regenerate images when source has not changed" do
101
+ File.write('svgbob.txt', code)
102
+
103
+ doc = <<-eos
104
+ = Hello, SvgBob!
105
+ Doc Writer <doc@example.com>
106
+
107
+ == First Section
108
+
109
+ svgbob::svgbob.txt
110
+
111
+ [svgbob]
112
+ ----
113
+ #{code}
114
+ ----
115
+ eos
116
+
117
+ d = load_asciidoc doc
118
+ b = d.find { |bl| bl.context == :image }
119
+ expect(b).to_not be_nil
120
+ target = b.attributes['target']
121
+ mtime1 = File.mtime(target)
122
+
123
+ sleep 1
124
+
125
+ d = load_asciidoc doc
126
+
127
+ mtime2 = File.mtime(target)
128
+
129
+ expect(mtime2).to eq mtime1
130
+ end
131
+
132
+ it "should handle two block macros with the same source" do
133
+ File.write('svgbob.txt', code)
134
+
135
+ doc = <<-eos
136
+ = Hello, SvgBob!
137
+ Doc Writer <doc@example.com>
138
+
139
+ == First Section
140
+
141
+ svgbob::svgbob.txt[]
142
+ svgbob::svgbob.txt[]
143
+ eos
144
+
145
+ load_asciidoc doc
146
+ expect(File.exist?('svgbob.svg')).to be true
147
+ end
148
+
149
+ it "should respect target attribute in block macros" do
150
+ File.write('svgbob.txt', code)
151
+
152
+ doc = <<-eos
153
+ = Hello, SvgBob!
154
+ Doc Writer <doc@example.com>
155
+
156
+ == First Section
157
+
158
+ svgbob::svgbob.txt["foobar"]
159
+ svgbob::svgbob.txt["foobaz"]
160
+ eos
161
+
162
+ load_asciidoc doc
163
+ expect(File.exist?('foobar.svg')).to be true
164
+ expect(File.exist?('foobaz.svg')).to be true
165
+ expect(File.exist?('svgbob.svg')).to be false
166
+ end
167
+ end
@@ -0,0 +1,228 @@
1
+ require_relative 'test_helper'
2
+
3
+ describe Asciidoctor::Diagram::SyntraxBlockMacroProcessor, :broken_on_appveyor do
4
+ it "should generate PNG images when format is set to 'png'" do
5
+ code = <<-eos
6
+ indentstack(10,
7
+ line(opt('-'), choice('0', line('1-9', loop(None, '0-9'))),
8
+ opt('.', loop('0-9', None))),
9
+
10
+ line(opt(choice('e', 'E'), choice(None, '+', '-'), loop('0-9', None)))
11
+ )
12
+ eos
13
+
14
+ File.write('syntrax.txt', code)
15
+
16
+ doc = <<-eos
17
+ = Hello, Syntrax!
18
+ Doc Writer <doc@example.com>
19
+
20
+ == First Section
21
+
22
+ syntrax::syntrax.txt[format="png"]
23
+ eos
24
+
25
+ d = load_asciidoc doc
26
+ expect(d).to_not be_nil
27
+
28
+ b = d.find { |bl| bl.context == :image }
29
+ expect(b).to_not be_nil
30
+
31
+ expect(b.content_model).to eq :empty
32
+
33
+ target = b.attributes['target']
34
+ expect(target).to_not be_nil
35
+ expect(target).to match(/\.png$/)
36
+ expect(File.exist?(target)).to be true
37
+
38
+ expect(b.attributes['width']).to_not be_nil
39
+ expect(b.attributes['height']).to_not be_nil
40
+ end
41
+ end
42
+
43
+ describe Asciidoctor::Diagram::SyntraxBlockProcessor, :broken_on_appveyor do
44
+ it "should generate PNG images when format is set to 'png'" do
45
+ doc = <<-eos
46
+ = Hello, Syntrax!
47
+ Doc Writer <doc@example.com>
48
+
49
+ == First Section
50
+
51
+ [syntrax, format="png"]
52
+ ----
53
+ indentstack(10,
54
+ line(opt('-'), choice('0', line('1-9', loop(None, '0-9'))),
55
+ opt('.', loop('0-9', None))),
56
+
57
+ line(opt(choice('e', 'E'), choice(None, '+', '-'), loop('0-9', None)))
58
+ )
59
+ ----
60
+ eos
61
+
62
+ d = load_asciidoc doc
63
+ expect(d).to_not be_nil
64
+
65
+ b = d.find { |bl| bl.context == :image }
66
+ expect(b).to_not be_nil
67
+
68
+ expect(b.content_model).to eq :empty
69
+
70
+ target = b.attributes['target']
71
+ expect(target).to_not be_nil
72
+ expect(target).to match(/\.png$/)
73
+ expect(File.exist?(target)).to be true
74
+
75
+ expect(b.attributes['width']).to_not be_nil
76
+ expect(b.attributes['height']).to_not be_nil
77
+ end
78
+
79
+ it "should generate SVG images when format is set to 'svg'" do
80
+ doc = <<-eos
81
+ = Hello, Syntrax!
82
+ Doc Writer <doc@example.com>
83
+
84
+ == First Section
85
+
86
+ [syntrax, format="svg"]
87
+ ----
88
+ indentstack(10,
89
+ line(opt('-'), choice('0', line('1-9', loop(None, '0-9'))),
90
+ opt('.', loop('0-9', None))),
91
+
92
+ line(opt(choice('e', 'E'), choice(None, '+', '-'), loop('0-9', None)))
93
+ )
94
+ ----
95
+ eos
96
+
97
+ d = load_asciidoc doc
98
+ expect(d).to_not be_nil
99
+
100
+ b = d.find { |bl| bl.context == :image }
101
+ expect(b).to_not be_nil
102
+
103
+ expect(b.content_model).to eq :empty
104
+
105
+ target = b.attributes['target']
106
+ expect(target).to_not be_nil
107
+ expect(target).to match(/\.svg/)
108
+ expect(File.exist?(target)).to be true
109
+
110
+ expect(b.attributes['width']).to_not be_nil
111
+ expect(b.attributes['height']).to_not be_nil
112
+ end
113
+
114
+ it "should raise an error when when format is set to an invalid value" do
115
+ doc = <<-eos
116
+ = Hello, Syntrax!
117
+ Doc Writer <doc@example.com>
118
+
119
+ == First Section
120
+
121
+ [syntrax, format="foobar"]
122
+ ----
123
+ ----
124
+ eos
125
+
126
+ expect { load_asciidoc doc }.to raise_error(/support.*format/i)
127
+ end
128
+
129
+ it "should not regenerate images when source has not changed" do
130
+ code = <<-eos
131
+ indentstack(10,
132
+ line(opt('-'), choice('0', line('1-9', loop(None, '0-9'))),
133
+ opt('.', loop('0-9', None))),
134
+
135
+ line(opt(choice('e', 'E'), choice(None, '+', '-'), loop('0-9', None)))
136
+ )
137
+ eos
138
+
139
+ File.write('syntrax.txt', code)
140
+
141
+ doc = <<-eos
142
+ = Hello, Syntrax!
143
+ Doc Writer <doc@example.com>
144
+
145
+ == First Section
146
+
147
+ syntrax::syntrax.txt
148
+
149
+ [syntrax, format="png"]
150
+ ----
151
+ indentstack(10,
152
+ line(opt('-'), choice('0', line('1-9', loop(None, '0-9'))),
153
+ opt('.', loop('0-9', None))),
154
+
155
+ line(opt(choice('e', 'E'), choice(None, '+', '-'), loop('0-9', None)))
156
+ )
157
+ ----
158
+ eos
159
+
160
+ d = load_asciidoc doc
161
+ b = d.find { |bl| bl.context == :image }
162
+ expect(b).to_not be_nil
163
+ target = b.attributes['target']
164
+ mtime1 = File.mtime(target)
165
+
166
+ sleep 1
167
+
168
+ d = load_asciidoc doc
169
+
170
+ mtime2 = File.mtime(target)
171
+
172
+ expect(mtime2).to eq mtime1
173
+ end
174
+
175
+ it "should handle two block macros with the same source" do
176
+ code = <<-eos
177
+ indentstack(10,
178
+ line(opt('-'), choice('0', line('1-9', loop(None, '0-9'))),
179
+ opt('.', loop('0-9', None))),
180
+
181
+ line(opt(choice('e', 'E'), choice(None, '+', '-'), loop('0-9', None)))
182
+ )
183
+ eos
184
+
185
+ File.write('syntrax.txt', code)
186
+
187
+ doc = <<-eos
188
+ = Hello, Syntrax!
189
+ Doc Writer <doc@example.com>
190
+
191
+ == First Section
192
+
193
+ syntrax::syntrax.txt[]
194
+ syntrax::syntrax.txt[]
195
+ eos
196
+
197
+ load_asciidoc doc
198
+ expect(File.exist?('syntrax.png')).to be true
199
+ end
200
+
201
+ it "should respect target attribute in block macros" do
202
+ code = <<-eos
203
+ indentstack(10,
204
+ line(opt('-'), choice('0', line('1-9', loop(None, '0-9'))),
205
+ opt('.', loop('0-9', None))),
206
+
207
+ line(opt(choice('e', 'E'), choice(None, '+', '-'), loop('0-9', None)))
208
+ )
209
+ eos
210
+
211
+ File.write('syntrax.txt', code)
212
+
213
+ doc = <<-eos
214
+ = Hello, Syntrax!
215
+ Doc Writer <doc@example.com>
216
+
217
+ == First Section
218
+
219
+ syntrax::syntrax.txt["foobar"]
220
+ syntrax::syntrax.txt["foobaz"]
221
+ eos
222
+
223
+ load_asciidoc doc
224
+ expect(File.exist?('foobar.png')).to be true
225
+ expect(File.exist?('foobaz.png')).to be true
226
+ expect(File.exist?('syntrax.png')).to be false
227
+ end
228
+ end