asciidoctor-diagram 1.5.19 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.adoc +71 -0
  3. data/README.adoc +66 -20
  4. data/examples/features.adoc +2 -2
  5. data/lib/asciidoctor-diagram.rb +5 -0
  6. data/lib/asciidoctor-diagram/a2s/converter.rb +59 -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/bytefield.rb +7 -0
  14. data/lib/asciidoctor-diagram/bytefield/converter.rb +26 -0
  15. data/lib/asciidoctor-diagram/bytefield/extension.rb +14 -0
  16. data/lib/asciidoctor-diagram/diagram_converter.rb +23 -0
  17. data/lib/asciidoctor-diagram/diagram_processor.rb +374 -0
  18. data/lib/asciidoctor-diagram/diagram_source.rb +322 -0
  19. data/lib/asciidoctor-diagram/ditaa/converter.rb +90 -0
  20. data/lib/asciidoctor-diagram/ditaa/extension.rb +6 -71
  21. data/lib/asciidoctor-diagram/dpic.rb +7 -0
  22. data/lib/asciidoctor-diagram/dpic/converter.rb +30 -0
  23. data/lib/asciidoctor-diagram/dpic/extension.rb +14 -0
  24. data/lib/asciidoctor-diagram/erd/converter.rb +31 -0
  25. data/lib/asciidoctor-diagram/erd/extension.rb +6 -35
  26. data/lib/asciidoctor-diagram/gnuplot/converter.rb +63 -0
  27. data/lib/asciidoctor-diagram/gnuplot/extension.rb +6 -62
  28. data/lib/asciidoctor-diagram/graphviz/converter.rb +32 -0
  29. data/lib/asciidoctor-diagram/graphviz/extension.rb +6 -35
  30. data/lib/asciidoctor-diagram/http/converter.rb +99 -0
  31. data/lib/asciidoctor-diagram/http/server.rb +132 -0
  32. data/lib/asciidoctor-diagram/lilypond/converter.rb +54 -0
  33. data/lib/asciidoctor-diagram/lilypond/extension.rb +6 -53
  34. data/lib/asciidoctor-diagram/meme/converter.rb +122 -0
  35. data/lib/asciidoctor-diagram/meme/extension.rb +5 -107
  36. data/lib/asciidoctor-diagram/mermaid/converter.rb +192 -0
  37. data/lib/asciidoctor-diagram/mermaid/extension.rb +6 -159
  38. data/lib/asciidoctor-diagram/msc/converter.rb +35 -0
  39. data/lib/asciidoctor-diagram/msc/extension.rb +6 -36
  40. data/lib/asciidoctor-diagram/nomnoml/converter.rb +25 -0
  41. data/lib/asciidoctor-diagram/nomnoml/extension.rb +6 -28
  42. data/lib/asciidoctor-diagram/pikchr.rb +7 -0
  43. data/lib/asciidoctor-diagram/pikchr/converter.rb +26 -0
  44. data/lib/asciidoctor-diagram/pikchr/extension.rb +14 -0
  45. data/lib/asciidoctor-diagram/plantuml/converter.rb +117 -0
  46. data/lib/asciidoctor-diagram/plantuml/extension.rb +10 -119
  47. data/lib/asciidoctor-diagram/shaape/converter.rb +25 -0
  48. data/lib/asciidoctor-diagram/shaape/extension.rb +6 -28
  49. data/lib/asciidoctor-diagram/smcat/converter.rb +44 -0
  50. data/lib/asciidoctor-diagram/smcat/extension.rb +6 -42
  51. data/lib/asciidoctor-diagram/svgbob/converter.rb +49 -0
  52. data/lib/asciidoctor-diagram/svgbob/extension.rb +6 -28
  53. data/lib/asciidoctor-diagram/symbolator.rb +7 -0
  54. data/lib/asciidoctor-diagram/symbolator/converter.rb +23 -0
  55. data/lib/asciidoctor-diagram/symbolator/extension.rb +14 -0
  56. data/lib/asciidoctor-diagram/syntrax/converter.rb +58 -0
  57. data/lib/asciidoctor-diagram/syntrax/extension.rb +6 -51
  58. data/lib/asciidoctor-diagram/tikz/converter.rb +75 -0
  59. data/lib/asciidoctor-diagram/tikz/extension.rb +6 -60
  60. data/lib/asciidoctor-diagram/umlet/converter.rb +33 -0
  61. data/lib/asciidoctor-diagram/umlet/extension.rb +6 -28
  62. data/lib/asciidoctor-diagram/util/cli.rb +14 -3
  63. data/lib/asciidoctor-diagram/util/cli_generator.rb +19 -1
  64. data/lib/asciidoctor-diagram/util/gif.rb +2 -2
  65. data/lib/asciidoctor-diagram/util/java.rb +114 -1
  66. data/lib/asciidoctor-diagram/util/java_socket.rb +8 -120
  67. data/lib/asciidoctor-diagram/util/pdf.rb +2 -2
  68. data/lib/asciidoctor-diagram/util/png.rb +2 -2
  69. data/lib/asciidoctor-diagram/util/svg.rb +46 -19
  70. data/lib/asciidoctor-diagram/util/which.rb +0 -29
  71. data/lib/asciidoctor-diagram/vega/converter.rb +47 -0
  72. data/lib/asciidoctor-diagram/vega/extension.rb +6 -44
  73. data/lib/asciidoctor-diagram/version.rb +1 -1
  74. data/lib/asciidoctor-diagram/wavedrom/converter.rb +50 -0
  75. data/lib/asciidoctor-diagram/wavedrom/extension.rb +6 -54
  76. data/lib/ditaa-1.3.15.jar +0 -0
  77. data/lib/plantuml-1.3.15.jar +0 -0
  78. data/lib/plantuml.jar +0 -0
  79. data/lib/server-1.3.15.jar +0 -0
  80. data/spec/a2s_spec.rb +2 -140
  81. data/spec/blockdiag_spec.rb +2 -200
  82. data/spec/bpmn_spec.rb +56 -0
  83. data/spec/bytefield_spec.rb +92 -0
  84. data/spec/ditaa_spec.rb +37 -143
  85. data/spec/dpic_spec.rb +19 -0
  86. data/spec/erd_spec.rb +2 -199
  87. data/spec/gnuplot_spec.rb +2 -255
  88. data/spec/graphviz_spec.rb +6 -145
  89. data/spec/lilypond_spec.rb +2 -140
  90. data/spec/mermaid_spec.rb +62 -209
  91. data/spec/msc_spec.rb +2 -199
  92. data/spec/nomnoml_spec.rb +4 -142
  93. data/spec/pikchr_spec.rb +51 -0
  94. data/spec/plantuml_spec.rb +24 -507
  95. data/spec/shaape_spec.rb +9 -221
  96. data/spec/shared_examples.rb +603 -0
  97. data/spec/smcat_spec.rb +2 -140
  98. data/spec/svgbob_spec.rb +2 -140
  99. data/spec/symbolator_spec.rb +23 -0
  100. data/spec/syntrax_spec.rb +5 -215
  101. data/spec/test_helper.rb +1 -21
  102. data/spec/tikz_spec.rb +65 -15
  103. data/spec/umlet_spec.rb +2 -58
  104. data/spec/vega_spec.rb +4 -117
  105. data/spec/wavedrom_spec.rb +2 -199
  106. metadata +58 -8
  107. data/lib/asciidoctor-diagram/extensions.rb +0 -568
  108. data/lib/ditaa-1.3.13.jar +0 -0
  109. data/lib/plantuml-1.3.13.jar +0 -0
  110. data/lib/server-1.3.13.jar +0 -0
@@ -25,206 +25,9 @@ msc {
25
25
  eos
26
26
 
27
27
  describe Asciidoctor::Diagram::MscBlockMacroProcessor, :broken_on_windows do
28
- it "should generate PNG images when format is set to 'png'" do
29
- File.write('msc.txt', code)
30
-
31
- doc = <<-eos
32
- = Hello, Msc!
33
- Doc Writer <doc@example.com>
34
-
35
- == First Section
36
-
37
- msc::msc.txt[format="png"]
38
- eos
39
-
40
- d = load_asciidoc doc
41
- expect(d).to_not be_nil
42
-
43
- b = d.find { |bl| bl.context == :image }
44
- expect(b).to_not be_nil
45
-
46
- expect(b.content_model).to eq :empty
47
-
48
- target = b.attributes['target']
49
- expect(target).to_not be_nil
50
- expect(target).to match(/\.png$/)
51
- expect(File.exist?(target)).to be true
52
-
53
- expect(b.attributes['width']).to_not be_nil
54
- expect(b.attributes['height']).to_not be_nil
55
- end
56
-
57
- it "should generate SVG images when format is set to 'svg'" do
58
- File.write('msc.txt', code)
59
-
60
- doc = <<-eos
61
- = Hello, Msc!
62
- Doc Writer <doc@example.com>
63
-
64
- == First Section
65
-
66
- msc::msc.txt[format="svg"]
67
- eos
68
-
69
- d = load_asciidoc doc
70
- expect(d).to_not be_nil
71
-
72
- b = d.find { |bl| bl.context == :image }
73
- expect(b).to_not be_nil
74
-
75
- expect(b.content_model).to eq :empty
76
-
77
- target = b.attributes['target']
78
- expect(target).to_not be_nil
79
- expect(target).to match(/\.svg/)
80
- expect(File.exist?(target)).to be true
81
-
82
- expect(b.attributes['width']).to_not be_nil
83
- expect(b.attributes['height']).to_not be_nil
84
- end
28
+ include_examples "block_macro", :msc, code, [:png, :svg]
85
29
  end
86
30
 
87
31
  describe Asciidoctor::Diagram::MscBlockProcessor, :broken_on_windows do
88
- it "should generate PNG images when format is set to 'png'" do
89
- doc = <<-eos
90
- = Hello, Msc!
91
- Doc Writer <doc@example.com>
92
-
93
- == First Section
94
-
95
- [msc, format="png"]
96
- ----
97
- #{code}
98
- ----
99
- eos
100
-
101
- d = load_asciidoc doc
102
- expect(d).to_not be_nil
103
-
104
- b = d.find { |bl| bl.context == :image }
105
- expect(b).to_not be_nil
106
-
107
- expect(b.content_model).to eq :empty
108
-
109
- target = b.attributes['target']
110
- expect(target).to_not be_nil
111
- expect(target).to match(/\.png$/)
112
- expect(File.exist?(target)).to be true
113
-
114
- expect(b.attributes['width']).to_not be_nil
115
- expect(b.attributes['height']).to_not be_nil
116
- end
117
-
118
- it "should generate SVG images when format is set to 'svg'" do
119
- doc = <<-eos
120
- = Hello, Msc!
121
- Doc Writer <doc@example.com>
122
-
123
- == First Section
124
-
125
- [msc, format="svg"]
126
- ----
127
- #{code}
128
- ----
129
- eos
130
-
131
- d = load_asciidoc doc
132
- expect(d).to_not be_nil
133
-
134
- b = d.find { |bl| bl.context == :image }
135
- expect(b).to_not be_nil
136
-
137
- expect(b.content_model).to eq :empty
138
-
139
- target = b.attributes['target']
140
- expect(target).to_not be_nil
141
- expect(target).to match(/\.svg/)
142
- expect(File.exist?(target)).to be true
143
-
144
- expect(b.attributes['width']).to_not be_nil
145
- expect(b.attributes['height']).to_not be_nil
146
- end
147
-
148
- it "should raise an error when when format is set to an invalid value" do
149
- doc = <<-eos
150
- = Hello, Msc!
151
- Doc Writer <doc@example.com>
152
-
153
- == First Section
154
-
155
- [msc, format="foobar"]
156
- ----
157
- ----
158
- eos
159
-
160
- expect { load_asciidoc doc }.to raise_error(/support.*format/i)
161
- end
162
-
163
- it "should not regenerate images when source has not changed" do
164
- File.write('msc.txt', code)
165
-
166
- doc = <<-eos
167
- = Hello, Msc!
168
- Doc Writer <doc@example.com>
169
-
170
- == First Section
171
-
172
- msc::msc.txt
173
-
174
- [msc, format="png"]
175
- ----
176
- #{code}
177
- ----
178
- eos
179
-
180
- d = load_asciidoc doc
181
- b = d.find { |bl| bl.context == :image }
182
- expect(b).to_not be_nil
183
- target = b.attributes['target']
184
- mtime1 = File.mtime(target)
185
-
186
- sleep 1
187
-
188
- d = load_asciidoc doc
189
-
190
- mtime2 = File.mtime(target)
191
-
192
- expect(mtime2).to eq mtime1
193
- end
194
-
195
- it "should handle two block macros with the same source" do
196
- File.write('msc.txt', code)
197
-
198
- doc = <<-eos
199
- = Hello, Msc!
200
- Doc Writer <doc@example.com>
201
-
202
- == First Section
203
-
204
- msc::msc.txt[]
205
- msc::msc.txt[]
206
- eos
207
-
208
- load_asciidoc doc
209
- expect(File.exist?('msc.png')).to be true
210
- end
211
-
212
- it "should respect target attribute in block macros" do
213
- File.write('msc.txt', code)
214
-
215
- doc = <<-eos
216
- = Hello, Msc!
217
- Doc Writer <doc@example.com>
218
-
219
- == First Section
220
-
221
- msc::msc.txt["foobar"]
222
- msc::msc.txt["foobaz"]
223
- eos
224
-
225
- load_asciidoc doc
226
- expect(File.exist?('foobar.png')).to be true
227
- expect(File.exist?('foobaz.png')).to be true
228
- expect(File.exist?('msc.png')).to be false
229
- end
32
+ include_examples "block", :msc, code, [:png, :svg]
230
33
  end
@@ -1,7 +1,7 @@
1
1
  require_relative 'test_helper'
2
2
 
3
3
  code = <<-eos
4
- [Pirate|eyeCount: Int|raid();pillage()|
4
+ [Pirate
5
5
  [beard]--[parrot]
6
6
  [beard]-:>[foul mouth]
7
7
  ]
@@ -11,7 +11,7 @@ code = <<-eos
11
11
  [jollyness]->[Pirate]
12
12
  [jollyness]->[rum]
13
13
  [jollyness]->[singing]
14
- [Pirate]-> *[rum|tastiness: Int|swig()]
14
+ [Pirate]-> *[rum]
15
15
  [Pirate]->[singing]
16
16
  [singing]<->[rum]
17
17
 
@@ -24,147 +24,9 @@ code = <<-eos
24
24
  eos
25
25
 
26
26
  describe Asciidoctor::Diagram::NomnomlBlockMacroProcessor do
27
- it "should generate SVG images when format is set to 'svg'" do
28
- File.write('nomnoml.txt', code)
29
-
30
- doc = <<-eos
31
- = Hello, Nomnoml!
32
- Doc Writer <doc@example.com>
33
-
34
- == First Section
35
-
36
- nomnoml::nomnoml.txt[format="svg"]
37
- eos
38
-
39
- d = load_asciidoc doc
40
- expect(d).to_not be_nil
41
-
42
- b = d.find { |bl| bl.context == :image }
43
- expect(b).to_not be_nil
44
-
45
- expect(b.content_model).to eq :empty
46
-
47
- target = b.attributes['target']
48
- expect(target).to_not be_nil
49
- expect(target).to match(/\.svg/)
50
- expect(File.exist?(target)).to be true
51
-
52
- expect(b.attributes['width']).to_not be_nil
53
- expect(b.attributes['height']).to_not be_nil
54
- end
27
+ include_examples "block_macro", :nomnoml, code, [:svg]
55
28
  end
56
29
 
57
30
  describe Asciidoctor::Diagram::NomnomlBlockProcessor, :broken_on_windows do
58
- it "should generate SVG images when format is set to 'svg'" do
59
- doc = <<-eos
60
- = Hello, Nomnoml!
61
- Doc Writer <doc@example.com>
62
-
63
- == First Section
64
-
65
- [nomnoml, format="svg"]
66
- ----
67
- #{code}
68
- ----
69
- eos
70
-
71
- d = load_asciidoc doc
72
- expect(d).to_not be_nil
73
-
74
- b = d.find { |bl| bl.context == :image }
75
- expect(b).to_not be_nil
76
-
77
- expect(b.content_model).to eq :empty
78
-
79
- target = b.attributes['target']
80
- expect(target).to_not be_nil
81
- expect(target).to match(/\.svg/)
82
- expect(File.exist?(target)).to be true
83
-
84
- expect(b.attributes['width']).to_not be_nil
85
- expect(b.attributes['height']).to_not be_nil
86
- end
87
-
88
- it "should raise an error when when format is set to an invalid value" do
89
- doc = <<-eos
90
- = Hello, Nomnoml!
91
- Doc Writer <doc@example.com>
92
-
93
- == First Section
94
-
95
- [nomnoml, format="foobar"]
96
- ----
97
- ----
98
- eos
99
-
100
- expect { load_asciidoc doc }.to raise_error(/support.*format/i)
101
- end
102
-
103
- it "should not regenerate images when source has not changed" do
104
- File.write('nomnoml.txt', code)
105
-
106
- doc = <<-eos
107
- = Hello, Nomnoml!
108
- Doc Writer <doc@example.com>
109
-
110
- == First Section
111
-
112
- nomnoml::nomnoml.txt
113
-
114
- [nomnoml, format="svg"]
115
- ----
116
- #{code}
117
- ----
118
- eos
119
-
120
- d = load_asciidoc doc
121
- b = d.find { |bl| bl.context == :image }
122
- expect(b).to_not be_nil
123
- target = b.attributes['target']
124
- mtime1 = File.mtime(target)
125
-
126
- sleep 1
127
-
128
- d = load_asciidoc doc
129
-
130
- mtime2 = File.mtime(target)
131
-
132
- expect(mtime2).to eq mtime1
133
- end
134
-
135
- it "should handle two block macros with the same source" do
136
- File.write('nomnoml.txt', code)
137
-
138
- doc = <<-eos
139
- = Hello, Nomnoml!
140
- Doc Writer <doc@example.com>
141
-
142
- == First Section
143
-
144
- nomnoml::nomnoml.txt[]
145
- nomnoml::nomnoml.txt[]
146
- eos
147
-
148
- load_asciidoc doc
149
- expect(File.exist?('nomnoml.svg')).to be true
150
- end
151
-
152
- it "should respect target attribute in block macros" do
153
- File.write('nomnoml.txt', code)
154
-
155
- doc = <<-eos
156
- = Hello, Nomnoml!
157
- Doc Writer <doc@example.com>
158
-
159
- == First Section
160
-
161
- nomnoml::nomnoml.txt["foobar"]
162
- nomnoml::nomnoml.txt["foobaz"]
163
- eos
164
-
165
- load_asciidoc doc
166
- expect(File.exist?('foobar.svg')).to be true
167
- expect(File.exist?('foobaz.svg')).to be true
168
- expect(File.exist?('nomnoml.svg')).to be false
169
- end
31
+ include_examples "block", :nomnoml, code, [:svg]
170
32
  end
@@ -0,0 +1,51 @@
1
+ require_relative 'test_helper'
2
+
3
+ code = <<-eos
4
+ # Change from the original:
5
+ # * Expand the macro by hand, as Pikchr does not support
6
+ # macros
7
+ #
8
+ #define ndblock {
9
+ # box wid boxwid/2 ht boxht/2
10
+ # down; box same with .t at bottom of last box; box same
11
+ #}
12
+ boxht = .2; boxwid = .3; circlerad = .3; dx = 0.05
13
+ down; box; box; box; box ht 3*boxht "." "." "."
14
+ L: box; box; box invis wid 2*boxwid "hashtab:" with .e at 1st box .w
15
+ right
16
+ Start: box wid .5 with .sw at 1st box.ne + (.4,.2) "..."
17
+ N1: box wid .2 "n1"; D1: box wid .3 "d1"
18
+ N3: box wid .4 "n3"; D3: box wid .3 "d3"
19
+ box wid .4 "..."
20
+ N2: box wid .5 "n2"; D2: box wid .2 "d2"
21
+ arrow right from 2nd box
22
+ #ndblock
23
+ box wid boxwid/2 ht boxht/2
24
+ down; box same with .t at bottom of last box; box same
25
+ spline -> right .2 from 3rd last box then to N1.sw + (dx,0)
26
+ spline -> right .3 from 2nd last box then to D1.sw + (dx,0)
27
+ arrow right from last box
28
+ #ndblock
29
+ box wid boxwid/2 ht boxht/2
30
+ down; box same with .t at bottom of last box; box same
31
+ spline -> right .2 from 3rd last box to N2.sw-(dx,.2) to N2.sw+(dx,0)
32
+ spline -> right .3 from 2nd last box to D2.sw-(dx,.2) to D2.sw+(dx,0)
33
+ arrow right 2*linewid from L
34
+ #ndblock
35
+ box wid boxwid/2 ht boxht/2
36
+ down; box same with .t at bottom of last box; box same
37
+ spline -> right .2 from 3rd last box to N3.sw + (dx,0)
38
+ spline -> right .3 from 2nd last box to D3.sw + (dx,0)
39
+ circlerad = .3
40
+ circle invis "ndblock" at last box.e + (1.2,.2)
41
+ arrow dashed from last circle.w to 5/8<last circle.w,2nd last box> chop
42
+ box invis wid 2*boxwid "ndtable:" with .e at Start.w
43
+ eos
44
+
45
+ describe Asciidoctor::Diagram::PikchrBlockMacroProcessor, :broken_on_travis, :broken_on_windows do
46
+ include_examples "block_macro", :pikchr, code, [:svg]
47
+ end
48
+
49
+ describe Asciidoctor::Diagram::ErdBlockProcessor, :broken_on_travis, :broken_on_windows do
50
+ include_examples "block", :pikchr, code, [:svg]
51
+ end
@@ -1,77 +1,14 @@
1
1
  require_relative 'test_helper'
2
2
 
3
- describe Asciidoctor::Diagram::PlantUmlBlockMacroProcessor do
4
- it "should generate PNG images when format is set to 'png'" do
5
- code = <<-eos
3
+ code = <<-eos
6
4
  User -> (Start)
7
5
  User --> (Use the application) : Label
8
6
 
9
7
  :Main Admin: ---> (Use the application) : Another label
10
- eos
11
-
12
- File.write('plantuml.txt', code)
13
-
14
- doc = <<-eos
15
- = Hello, PlantUML!
16
- Doc Writer <doc@example.com>
17
-
18
- == First Section
19
-
20
- plantuml::plantuml.txt[format="png"]
21
- eos
22
-
23
- d = load_asciidoc doc
24
- expect(d).to_not be_nil
25
-
26
- b = d.find { |bl| bl.context == :image }
27
- expect(b).to_not be_nil
28
-
29
- expect(b.content_model).to eq :empty
30
-
31
- target = b.attributes['target']
32
- expect(target).to_not be_nil
33
- expect(target).to match(/\.png$/)
34
- expect(File.exist?(target)).to be true
35
-
36
- expect(b.attributes['width']).to_not be_nil
37
- expect(b.attributes['height']).to_not be_nil
38
- end
39
-
40
- it "should generate PNG images when format is set to 'png'" do
41
- code = <<-eos
42
- User -> (Start)
43
- User --> (Use the application) : Label
44
-
45
- :Main Admin: ---> (Use the application) : Another label
46
- eos
47
-
48
- File.write('plantuml.txt', code)
49
-
50
- doc = <<-eos
51
- = Hello, PlantUML!
52
- Doc Writer <doc@example.com>
53
-
54
- == First Section
55
-
56
- plantuml::plantuml.txt[format="png"]
57
- eos
58
-
59
- d = load_asciidoc doc
60
- expect(d).to_not be_nil
61
-
62
- b = d.find { |bl| bl.context == :image }
63
- expect(b).to_not be_nil
64
-
65
- expect(b.content_model).to eq :empty
8
+ eos
66
9
 
67
- target = b.attributes['target']
68
- expect(target).to_not be_nil
69
- expect(target).to match(/\.png$/)
70
- expect(File.exist?(target)).to be true
71
-
72
- expect(b.attributes['width']).to_not be_nil
73
- expect(b.attributes['height']).to_not be_nil
74
- end
10
+ describe Asciidoctor::Diagram::PlantUmlBlockMacroProcessor do
11
+ include_examples "block_macro", :plantuml, code, [:png, :svg, :txt]
75
12
 
76
13
  it 'should support substitutions in diagram code' do
77
14
  code = <<-eos
@@ -216,145 +153,10 @@ plantuml::dir/plantuml.txt[format="svg", subs=attributes+]
216
153
  content = File.read(target, :encoding => Encoding::UTF_8)
217
154
  expect(content).to_not include('!include')
218
155
  end
219
-
220
- it 'should generate blocks with figure captions' do
221
- code = <<-eos
222
- User -> (Start)
223
- User --> (Use the application) : Label
224
-
225
- :Main Admin: ---> (Use the application) : Another label
226
- eos
227
-
228
- File.write('plantuml.txt', code)
229
-
230
- doc = <<-eos
231
- = Hello, PlantUML!
232
- Doc Writer <doc@example.com>
233
-
234
- == First Section
235
-
236
- .This is a UML diagram
237
- plantuml::plantuml.txt[format="png"]
238
- eos
239
-
240
- d = load_asciidoc doc
241
- expect(d).to_not be_nil
242
-
243
- b = d.find { |bl| bl.context == :image }
244
- expect(b).to_not be_nil
245
-
246
- expect(b.caption).to match(/Figure \d+/)
247
- end
248
156
  end
249
157
 
250
158
  describe Asciidoctor::Diagram::PlantUmlBlockProcessor do
251
- it "should generate PNG images when format is set to 'png'" do
252
- doc = <<-eos
253
- = Hello, PlantUML!
254
- Doc Writer <doc@example.com>
255
-
256
- == First Section
257
-
258
- [plantuml, format="png"]
259
- ----
260
- User -> (Start)
261
- User --> (Use the application) : Label
262
-
263
- :Main Admin: ---> (Use the application) : Another label
264
- ----
265
- eos
266
-
267
- d = load_asciidoc doc
268
- expect(d).to_not be_nil
269
-
270
- b = d.find { |bl| bl.context == :image }
271
- expect(b).to_not be_nil
272
-
273
- expect(b.content_model).to eq :empty
274
-
275
- target = b.attributes['target']
276
- expect(target).to_not be_nil
277
- expect(target).to match(/\.png$/)
278
- expect(File.exist?(target)).to be true
279
-
280
- expect(b.attributes['width']).to_not be_nil
281
- expect(b.attributes['height']).to_not be_nil
282
- end
283
-
284
- it "should generate SVG images when format is set to 'svg'" do
285
- doc = <<-eos
286
- = Hello, PlantUML!
287
- Doc Writer <doc@example.com>
288
-
289
- == First Section
290
-
291
- [plantuml, format="svg"]
292
- ----
293
- User -> (Start)
294
- User --> (Use the application) : Label
295
-
296
- :Main Admin: ---> (Use the application) : Another label
297
- ----
298
- eos
299
-
300
- d = load_asciidoc doc
301
- expect(d).to_not be_nil
302
-
303
- b = d.find { |bl| bl.context == :image }
304
- expect(b).to_not be_nil
305
-
306
- expect(b.content_model).to eq :empty
307
-
308
- target = b.attributes['target']
309
- expect(target).to_not be_nil
310
- expect(target).to match(/\.svg/)
311
- expect(File.exist?(target)).to be true
312
-
313
- expect(b.attributes['width']).to_not be_nil
314
- expect(b.attributes['height']).to_not be_nil
315
- end
316
-
317
- it "should generate literal blocks when format is set to 'txt'" do
318
- doc = <<-eos
319
- = Hello, PlantUML!
320
- Doc Writer <doc@example.com>
321
-
322
- == First Section
323
-
324
- [plantuml, format="txt"]
325
- ----
326
- User -> (Start)
327
- User --> (Use the application) : Label
328
-
329
- :Main Admin: ---> (Use the application) : Another label
330
- ----
331
- eos
332
-
333
- d = load_asciidoc doc
334
- expect(d).to_not be_nil
335
-
336
- b = d.find { |bl| bl.context == :literal }
337
- expect(b).to_not be_nil
338
-
339
- expect(b.content_model).to eq :verbatim
340
-
341
- expect(b.attributes['target']).to be_nil
342
- end
343
-
344
- it 'should raise an error when when format is set to an invalid value' do
345
- doc = <<-eos
346
- = Hello, PlantUML!
347
- Doc Writer <doc@example.com>
348
-
349
- == First Section
350
-
351
- [plantuml, format="foobar"]
352
- ----
353
- ----
354
- eos
355
-
356
- expect { load_asciidoc doc }.to raise_error(/support.*format/i)
357
- end
159
+ include_examples "block", :plantuml, code, [:png, :svg, :txt]
358
160
 
359
161
  it 'should use plantuml configuration when specified as a document attribute' do
360
162
  doc = <<-eos
@@ -389,275 +191,7 @@ skinparam ArrowColor #DEADBE
389
191
  expect(File.exist?(target)).to be true
390
192
 
391
193
  svg = File.read(target, :encoding => Encoding::UTF_8)
392
- expect(svg).to match(/<path.*fill="#DEADBE"/)
393
- end
394
-
395
- it 'should not regenerate images when source has not changed' do
396
- code = <<-eos
397
- User -> (Start)
398
- User --> (Use the application) : Label
399
-
400
- :Main Admin: ---> (Use the application) : Another label
401
- eos
402
-
403
- File.write('plantuml.txt', code)
404
-
405
- doc = <<-eos
406
- = Hello, PlantUML!
407
- Doc Writer <doc@example.com>
408
-
409
- == First Section
410
-
411
- plantuml::plantuml.txt
412
-
413
- [plantuml, format="png"]
414
- ----
415
- actor Foo1
416
- boundary Foo2
417
- Foo1 -> Foo2 : To boundary
418
- ----
419
- eos
420
-
421
- d = load_asciidoc doc
422
- b = d.find { |bl| bl.context == :image }
423
- target = b.attributes['target']
424
- mtime1 = File.mtime(target)
425
-
426
- sleep 1
427
-
428
- d = load_asciidoc doc
429
-
430
- mtime2 = File.mtime(target)
431
-
432
- expect(mtime2).to eq mtime1
433
- end
434
-
435
- it 'should handle two block macros with the same source' do
436
- code = <<-eos
437
- User -> (Start)
438
- User --> (Use the application) : Label
439
-
440
- :Main Admin: ---> (Use the application) : Another label
441
- eos
442
-
443
- File.write('plantuml.txt', code)
444
-
445
- doc = <<-eos
446
- = Hello, PlantUML!
447
- Doc Writer <doc@example.com>
448
-
449
- == First Section
450
-
451
- plantuml::plantuml.txt[]
452
- plantuml::plantuml.txt[]
453
- eos
454
-
455
- load_asciidoc doc
456
- expect(File.exist?('plantuml.png')).to be true
457
- end
458
-
459
- it 'should respect target attribute in block macros' do
460
- code = <<-eos
461
- User -> (Start)
462
- User --> (Use the application) : Label
463
-
464
- :Main Admin: ---> (Use the application) : Another label
465
- eos
466
-
467
- File.write('plantuml.txt', code)
468
-
469
- doc = <<-eos
470
- = Hello, PlantUML!
471
- Doc Writer <doc@example.com>
472
-
473
- == First Section
474
-
475
- plantuml::plantuml.txt["foobar"]
476
- plantuml::plantuml.txt["foobaz"]
477
- eos
478
-
479
- load_asciidoc doc
480
- expect(File.exist?('foobar.png')).to be true
481
- expect(File.exist?('foobaz.png')).to be true
482
- expect(File.exist?('plantuml.png')).to be false
483
- end
484
-
485
- it 'should respect target attribute values with relative paths in block macros' do
486
- code = <<-eos
487
- User -> (Start)
488
- User --> (Use the application) : Label
489
-
490
- :Main Admin: ---> (Use the application) : Another label
491
- eos
492
-
493
- File.write('plantuml.txt', code)
494
-
495
- doc = <<-eos
496
- = Hello, PlantUML!
497
- Doc Writer <doc@example.com>
498
-
499
- == First Section
500
-
501
- plantuml::plantuml.txt["test/foobar"]
502
- plantuml::plantuml.txt["test2/foobaz"]
503
- eos
504
-
505
- load_asciidoc doc
506
- expect(File.exist?('test/foobar.png')).to be true
507
- expect(File.exist?('test2/foobaz.png')).to be true
508
- expect(File.exist?('plantuml.png')).to be false
509
- end
510
-
511
- it 'should write files to outdir if set' do
512
- doc = <<-eos
513
- = Hello, PlantUML!
514
- Doc Writer <doc@example.com>
515
-
516
- == First Section
517
-
518
- [plantuml, format="svg"]
519
- ----
520
- actor Foo1
521
- boundary Foo2
522
- Foo1 -> Foo2 : To boundary
523
- ----
524
- eos
525
-
526
- d = load_asciidoc doc, {:attributes => {'outdir' => 'foo'}}
527
- b = d.find { |bl| bl.context == :image }
528
-
529
- target = b.attributes['target']
530
- expect(target).to_not be_nil
531
- expect(File.exist?(target)).to be false
532
- expect(File.exist?(File.expand_path(target, 'foo'))).to be true
533
- end
534
-
535
- it 'should write files to to_dir if set' do
536
- doc = <<-eos
537
- = Hello, PlantUML!
538
- Doc Writer <doc@example.com>
539
-
540
- == First Section
541
-
542
- [plantuml, format="svg"]
543
- ----
544
- actor Foo1
545
- boundary Foo2
546
- Foo1 -> Foo2 : To boundary
547
- ----
548
- eos
549
-
550
- d = load_asciidoc doc, {:to_dir => 'foo'}
551
- b = d.find { |bl| bl.context == :image }
552
-
553
- target = b.attributes['target']
554
- expect(target).to_not be_nil
555
- expect(File.exist?(target)).to be false
556
- expect(File.exist?(File.expand_path(target, 'foo'))).to be true
557
- end
558
-
559
- it 'should write files to to_dir if set when embedded in table' do
560
- doc = <<-eos
561
- = Hello, PlantUML!
562
- Doc Writer <doc@example.com>
563
-
564
- == First Section
565
-
566
- |===
567
- |Type | Example
568
-
569
- |graphviz
570
- a|
571
- [plantuml, format="svg"]
572
- ----
573
- actor Foo1
574
- boundary Foo2
575
- Foo1 -> Foo2 : To boundary
576
- ----
577
- |===
578
- eos
579
-
580
- d = load_asciidoc doc, {:to_dir => 'foo'}
581
- b = d.find { |bl| bl.context == :image }
582
-
583
- target = b.attributes['target']
584
- expect(target).to_not be_nil
585
- expect(File.exist?(target)).to be false
586
- expect(File.exist?(File.expand_path(target, 'foo'))).to be true
587
- end
588
-
589
- it 'should write files to imagesoutdir if set' do
590
- doc = <<-eos
591
- = Hello, PlantUML!
592
- Doc Writer <doc@example.com>
593
-
594
- == First Section
595
-
596
- [plantuml, format="svg"]
597
- ----
598
- actor Foo1
599
- boundary Foo2
600
- Foo1 -> Foo2 : To boundary
601
- ----
602
- eos
603
-
604
- d = load_asciidoc doc, {:attributes => {'imagesoutdir' => 'bar', 'outdir' => 'foo'}}
605
- b = d.find { |bl| bl.context == :image }
606
-
607
- target = b.attributes['target']
608
- expect(target).to_not be_nil
609
- expect(File.exist?(target)).to be false
610
- expect(File.exist?(File.expand_path(target, 'bar'))).to be true
611
- expect(File.exist?(File.expand_path(target, 'foo'))).to be false
612
- end
613
-
614
- it 'should omit width/height attributes when generating docbook' do
615
- doc = <<-eos
616
- = Hello, PlantUML!
617
- Doc Writer <doc@example.com>
618
-
619
- == First Section
620
-
621
- [plantuml, format="png"]
622
- ----
623
- User -> (Start)
624
- ----
625
- eos
626
-
627
- d = load_asciidoc doc, :attributes => {'backend' => 'docbook5'}
628
- expect(d).to_not be_nil
629
-
630
- b = d.find { |bl| bl.context == :image }
631
- expect(b).to_not be_nil
632
-
633
- target = b.attributes['target']
634
- expect(File.exist?(target)).to be true
635
-
636
- expect(b.attributes['width']).to be_nil
637
- expect(b.attributes['height']).to be_nil
638
- end
639
-
640
- it 'should generate blocks with figure captions' do
641
- doc = <<-eos
642
- = Hello, PlantUML!
643
- Doc Writer <doc@example.com>
644
-
645
- == First Section
646
-
647
- .Caption for my UML diagram
648
- [plantuml, format="png"]
649
- ----
650
- User -> (Start)
651
- ----
652
- eos
653
-
654
- d = load_asciidoc doc
655
- expect(d).to_not be_nil
656
-
657
- b = d.find { |bl| bl.context == :image }
658
- expect(b).to_not be_nil
659
-
660
- expect(b.caption).to match(/Figure \d+/)
194
+ expect(svg).to match(/<[^<]+ fill=["']#DEADBE["']/)
661
195
  end
662
196
 
663
197
  it 'should support salt diagrams using salt block type' do
@@ -763,41 +297,6 @@ salt
763
297
  expect(b.attributes['height']).to be_nil
764
298
  end
765
299
 
766
- it 'should support scaling diagrams' do
767
- doc = <<-eos
768
- = Hello, PlantUML!
769
- Doc Writer <doc@example.com>
770
-
771
- == First Section
772
-
773
- [plantuml, format="png"]
774
- ----
775
- A -> B
776
- ----
777
- eos
778
-
779
- scaled_doc = <<-eos
780
- = Hello, PlantUML!
781
- Doc Writer <doc@example.com>
782
-
783
- == First Section
784
-
785
- [plantuml, format="png", scale="1.5"]
786
- ----
787
- A -> B
788
- ----
789
- eos
790
-
791
- d = load_asciidoc doc, :attributes => {'backend' => 'html5'}
792
- unscaled_image = d.find { |bl| bl.context == :image }
793
-
794
- d = load_asciidoc scaled_doc, :attributes => {'backend' => 'html5'}
795
- scaled_image = d.find { |bl| bl.context == :image }
796
-
797
- expect(scaled_image.attributes['width']).to be_within(1).of(unscaled_image.attributes['width'] * 1.5)
798
- expect(scaled_image.attributes['height']).to be_within(1).of(unscaled_image.attributes['height'] * 1.5)
799
- end
800
-
801
300
  it 'should handle embedded creole images correctly' do
802
301
  creole_doc = <<-eos
803
302
  = Hello, PlantUML!
@@ -1074,4 +573,22 @@ Doc Writer <doc@example.com>
1074
573
  expect(b.attributes['width']).to_not be_nil
1075
574
  expect(b.attributes['height']).to_not be_nil
1076
575
  end
576
+
577
+ it "should report syntax errors" do
578
+ doc = <<-eos
579
+ = Hello, PlantUML!
580
+ Doc Writer <doc@example.com>
581
+
582
+ == First Section
583
+
584
+ [plantuml,format="svg"]
585
+ ----
586
+ Bob; Alice; foo
587
+ ----
588
+ eos
589
+
590
+ expect {
591
+ load_asciidoc doc
592
+ }.to raise_error(/syntax error/i)
593
+ end
1077
594
  end