asciidoctor-diagram 2.0.2 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +78 -1
  3. data/README.adoc +25 -507
  4. data/Rakefile +1 -1
  5. data/docs/antora.yml +3 -0
  6. data/{images → docs/modules/ROOT/images}/asciidoctor-diagram-classes.png +0 -0
  7. data/docs/modules/ROOT/images/asciidoctor-diagram-process.png +0 -0
  8. data/docs/modules/ROOT/pages/index.adoc +21 -0
  9. data/docs/modules/ROOT/partials/advanced.adoc +319 -0
  10. data/docs/modules/ROOT/partials/create_diagram.adoc +132 -0
  11. data/docs/modules/ROOT/partials/generate.adoc +15 -0
  12. data/docs/modules/ROOT/partials/installation.adoc +19 -0
  13. data/docs/modules/ROOT/partials/uris.adoc +40 -0
  14. data/examples/features.adoc +1 -1
  15. data/lib/asciidoctor-diagram.rb +4 -0
  16. data/lib/asciidoctor-diagram/a2s/converter.rb +10 -6
  17. data/lib/asciidoctor-diagram/blockdiag/converter.rb +1 -1
  18. data/lib/asciidoctor-diagram/bpmn/converter.rb +3 -3
  19. data/lib/asciidoctor-diagram/diagram_converter.rb +9 -1
  20. data/lib/asciidoctor-diagram/diagram_processor.rb +92 -48
  21. data/lib/asciidoctor-diagram/diagram_source.rb +71 -24
  22. data/lib/asciidoctor-diagram/diagrams.rb +7 -0
  23. data/lib/asciidoctor-diagram/diagrams/converter.rb +49 -0
  24. data/lib/asciidoctor-diagram/diagrams/extension.rb +14 -0
  25. data/lib/asciidoctor-diagram/ditaa/converter.rb +20 -7
  26. data/lib/asciidoctor-diagram/ditaa/ditaa-1.3.20.jar +0 -0
  27. data/lib/asciidoctor-diagram/dpic.rb +7 -0
  28. data/lib/asciidoctor-diagram/dpic/converter.rb +30 -0
  29. data/lib/asciidoctor-diagram/dpic/extension.rb +14 -0
  30. data/lib/asciidoctor-diagram/gnuplot/converter.rb +8 -8
  31. data/lib/asciidoctor-diagram/graphviz/converter.rb +2 -2
  32. data/lib/asciidoctor-diagram/http/converter.rb +52 -14
  33. data/lib/asciidoctor-diagram/http/server.rb +11 -6
  34. data/lib/asciidoctor-diagram/lilypond/converter.rb +13 -3
  35. data/lib/asciidoctor-diagram/meme/converter.rb +22 -16
  36. data/lib/asciidoctor-diagram/mermaid/converter.rb +45 -14
  37. data/lib/asciidoctor-diagram/msc/converter.rb +2 -2
  38. data/lib/asciidoctor-diagram/pikchr.rb +7 -0
  39. data/lib/asciidoctor-diagram/pikchr/converter.rb +33 -0
  40. data/lib/asciidoctor-diagram/pikchr/extension.rb +14 -0
  41. data/lib/asciidoctor-diagram/plantuml/converter.rb +68 -43
  42. data/lib/asciidoctor-diagram/plantuml/plantuml-1.3.20.jar +0 -0
  43. data/lib/asciidoctor-diagram/smcat/converter.rb +3 -3
  44. data/lib/asciidoctor-diagram/svgbob/converter.rb +6 -2
  45. data/lib/asciidoctor-diagram/symbolator.rb +7 -0
  46. data/lib/asciidoctor-diagram/symbolator/converter.rb +23 -0
  47. data/lib/asciidoctor-diagram/symbolator/extension.rb +14 -0
  48. data/lib/asciidoctor-diagram/syntrax/converter.rb +9 -6
  49. data/lib/asciidoctor-diagram/tikz/converter.rb +20 -1
  50. data/lib/asciidoctor-diagram/umlet/converter.rb +11 -2
  51. data/lib/asciidoctor-diagram/util/cli.rb +16 -1
  52. data/lib/asciidoctor-diagram/util/cli_generator.rb +30 -8
  53. data/lib/asciidoctor-diagram/util/gif.rb +2 -2
  54. data/lib/asciidoctor-diagram/util/java.rb +118 -3
  55. data/lib/asciidoctor-diagram/util/java_jruby.rb +4 -1
  56. data/lib/asciidoctor-diagram/util/java_socket.rb +8 -109
  57. data/lib/asciidoctor-diagram/util/pdf.rb +2 -2
  58. data/lib/asciidoctor-diagram/util/png.rb +2 -2
  59. data/lib/{server-1.3.15.jar → asciidoctor-diagram/util/server-1.3.20.jar} +0 -0
  60. data/lib/asciidoctor-diagram/util/svg.rb +66 -18
  61. data/lib/asciidoctor-diagram/vega/converter.rb +2 -2
  62. data/lib/asciidoctor-diagram/version.rb +1 -1
  63. data/spec/a2s_spec.rb +6 -144
  64. data/spec/blockdiag_spec.rb +6 -204
  65. data/spec/bpmn_spec.rb +52 -92
  66. data/spec/bytefield_spec.rb +6 -144
  67. data/spec/diagrams_spec.rb +23 -0
  68. data/spec/ditaa_spec.rb +6 -144
  69. data/spec/dpic_spec.rb +19 -0
  70. data/spec/erd_spec.rb +6 -203
  71. data/spec/gnuplot_spec.rb +10 -263
  72. data/spec/graphviz_spec.rb +6 -145
  73. data/spec/lilypond_spec.rb +6 -144
  74. data/spec/mermaid_spec.rb +69 -211
  75. data/spec/msc_spec.rb +6 -203
  76. data/spec/nomnoml_spec.rb +7 -145
  77. data/spec/pikchr_spec.rb +69 -0
  78. data/spec/plantuml_spec.rb +63 -553
  79. data/spec/shaape_spec.rb +12 -224
  80. data/spec/shared_examples.rb +603 -0
  81. data/spec/smcat_spec.rb +6 -144
  82. data/spec/svgbob_spec.rb +6 -144
  83. data/spec/symbolator_spec.rb +23 -0
  84. data/spec/syntrax_spec.rb +7 -217
  85. data/spec/test_helper.rb +4 -29
  86. data/spec/tikz_spec.rb +68 -18
  87. data/spec/umlet_spec.rb +3 -59
  88. data/spec/vega_spec.rb +6 -119
  89. data/spec/wavedrom_spec.rb +3 -200
  90. metadata +82 -18
  91. data/README_zh-CN.adoc +0 -336
  92. data/images/asciidoctor-diagram-process.png +0 -0
  93. data/lib/batik-all-1.10.jar +0 -0
  94. data/lib/ditaa-1.3.15.jar +0 -0
  95. data/lib/ditaamini-0.12.jar +0 -0
  96. data/lib/jlatexmath-minimal-1.0.5.jar +0 -0
  97. data/lib/plantuml-1.3.15.jar +0 -0
  98. data/lib/plantuml.jar +0 -0
  99. data/spec/bpmn-example.xml +0 -44
data/spec/shaape_spec.rb CHANGED
@@ -1,228 +1,16 @@
1
1
  require_relative 'test_helper'
2
2
 
3
- describe Asciidoctor::Diagram::ShaapeBlockMacroProcessor, :broken_on_osx, :broken_on_appveyor do
4
- it "should generate PNG images when format is set to 'png'" do
5
- code = <<-eos
6
- +--------+ +-------------+
7
- | | \\ /
8
- | Hello |---> \\ Goodbye /
9
- | ;) | / \\
10
- | | / \\
11
- +--------+ +-------------+
12
- eos
13
-
14
- File.write('shaape.txt', code)
15
-
16
- doc = <<-eos
17
- = Hello, Shaape!
18
- Doc Writer <doc@example.com>
19
-
20
- == First Section
21
-
22
- shaape::shaape.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
3
+ SHAAPE_CODE = <<-eos
4
+ +-->
5
+ / /\
6
+ >---+---->+ +
7
+ \/
8
+ eos
9
+
10
+ describe Asciidoctor::Diagram::ShaapeBlockMacroProcessor, :broken_on_osx, :broken_on_github, :broken_on_windows do
11
+ include_examples "block_macro", :shaape, SHAAPE_CODE, [:png, :svg]
41
12
  end
42
13
 
43
- describe Asciidoctor::Diagram::ShaapeBlockProcessor, :broken_on_osx, :broken_on_appveyor do
44
- it "should generate PNG images when format is set to 'png'" do
45
- doc = <<-eos
46
- = Hello, Shaape!
47
- Doc Writer <doc@example.com>
48
-
49
- == First Section
50
-
51
- [shaape, format="png"]
52
- ----
53
- +--------+ +-------------+
54
- | | \\ /
55
- | Hello |---> \\ Goodbye /
56
- | ;) | / \\
57
- | | / \\
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, Shaape!
82
- Doc Writer <doc@example.com>
83
-
84
- == First Section
85
-
86
- [shaape, format="svg"]
87
- ----
88
- +--------+ +-------------+
89
- | | \\ /
90
- | Hello |---> \\ Goodbye /
91
- | ;) | / \\
92
- | | / \\
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, Shaape!
117
- Doc Writer <doc@example.com>
118
-
119
- == First Section
120
-
121
- [shaape, 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
- +--------+ +-------------+
132
- | | \\ /
133
- | Hello |---> \\ Goodbye /
134
- | ;) | / \\
135
- | | / \\
136
- +--------+ +-------------+
137
- eos
138
-
139
- File.write('shaape.txt', code)
140
-
141
- doc = <<-eos
142
- = Hello, Shaape!
143
- Doc Writer <doc@example.com>
144
-
145
- == First Section
146
-
147
- shaape::shaape.txt
148
-
149
- [shaape, format="png"]
150
- ----
151
- +--------+
152
- | |
153
- | Hello |
154
- | ;) |
155
- | |
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
- +--------+ +-------------+
178
- | | \\ /
179
- | Hello |---> \\ Goodbye /
180
- | ;) | / \\
181
- | | / \\
182
- +--------+ +-------------+
183
- eos
184
-
185
- File.write('shaape.txt', code)
186
-
187
- doc = <<-eos
188
- = Hello, Shaape!
189
- Doc Writer <doc@example.com>
190
-
191
- == First Section
192
-
193
- shaape::shaape.txt[]
194
- shaape::shaape.txt[]
195
- eos
196
-
197
- load_asciidoc doc
198
- expect(File.exist?('shaape.png')).to be true
199
- end
200
-
201
- it "should respect target attribute in block macros" do
202
- code = <<-eos
203
- +--------+ +-------------+
204
- | | \\ /
205
- | Hello |---> \\ Goodbye /
206
- | ;) | / \\
207
- | | / \\
208
- +--------+ +-------------+
209
- eos
210
-
211
- File.write('shaape.txt', code)
212
-
213
- doc = <<-eos
214
- = Hello, Shaape!
215
- Doc Writer <doc@example.com>
216
-
217
- == First Section
218
-
219
- shaape::shaape.txt["foobar"]
220
- shaape::shaape.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?('shaape.png')).to be false
227
- end
228
- end
14
+ describe Asciidoctor::Diagram::ShaapeBlockProcessor, :broken_on_osx, :broken_on_github, :broken_on_windows do
15
+ include_examples "block", :shaape, SHAAPE_CODE, [:png, :svg]
16
+ end
@@ -0,0 +1,603 @@
1
+ require_relative 'test_helper'
2
+
3
+ RSpec.shared_examples "block_macro" do |name, code, formats|
4
+ formats.each do |format|
5
+ if format == :txt
6
+ it "#{name} should generate literal blocks when format is set to 'txt'" do
7
+ File.write("#{name}.txt", code)
8
+
9
+ doc = <<-eos
10
+ = Hello, #{name}!
11
+ Doc Writer <doc@example.com>
12
+
13
+ == First Section
14
+
15
+ #{name}::#{name}.txt[#{format}]
16
+ eos
17
+
18
+ d = load_asciidoc doc
19
+ expect(d).to_not be_nil
20
+
21
+ b = d.find { |bl| bl.context == :literal }
22
+ expect(b).to_not be_nil
23
+
24
+ expect(b.content_model).to eq :verbatim
25
+
26
+ expect(b.attributes['target']).to be_nil
27
+ end
28
+ else
29
+ it "#{name} should generate image blocks when format is set to '#{format}'" do
30
+ File.write("#{name}.txt", code)
31
+
32
+ doc = <<-eos
33
+ = Hello, #{name}!
34
+ Doc Writer <doc@example.com>
35
+
36
+ == First Section
37
+
38
+ #{name}::#{name}.txt[#{format}]
39
+ eos
40
+
41
+ d = load_asciidoc doc
42
+ expect(d).to_not be_nil
43
+
44
+ b = d.find { |bl| bl.context == :image }
45
+ expect(b).to_not be_nil
46
+
47
+ expect(b.content_model).to eq :empty
48
+
49
+ target = b.attributes['target']
50
+ expect(target).to_not be_nil
51
+ expect(target).to match(/\.#{format}$/)
52
+ expect(File.exist?(target)).to be true
53
+
54
+ unless format == :pdf
55
+ expect(b.attributes['width']).to_not be_nil
56
+ expect(b.attributes['height']).to_not be_nil
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ it 'should support substitutions in the target attribute' do
63
+ File.write("#{name}.txt", code)
64
+
65
+ doc = <<-eos
66
+ = Hello, #{name}!
67
+ Doc Writer <doc@example.com>
68
+ :file: #{name}
69
+
70
+ == First Section
71
+
72
+ #{name}::{file}.txt[subs=attributes+]
73
+ eos
74
+
75
+ d = load_asciidoc doc, :attributes => {'backend' => 'html5'}
76
+ expect(d).to_not be_nil
77
+
78
+ b = d.find { |bl| bl.context == :image }
79
+ expect(b).to_not be_nil
80
+
81
+ target = b.attributes['target']
82
+ expect(File.exist?(target)).to be true
83
+ end
84
+
85
+ it 'should support substitutions in the format attribute' do
86
+ File.write("#{name}.txt", code)
87
+
88
+ doc = <<-eos
89
+ = Hello, #{name}!
90
+ Doc Writer <doc@example.com>
91
+ :file: #{name}
92
+ :outputformat: #{formats[0]}
93
+
94
+ == First Section
95
+
96
+ #{name}::{file}.txt[format="{outputformat}", subs=attributes+]
97
+ eos
98
+
99
+ d = load_asciidoc doc, :attributes => {'backend' => 'html5'}
100
+ expect(d).to_not be_nil
101
+
102
+ b = d.find { |bl| bl.context == :image }
103
+ expect(b).to_not be_nil
104
+
105
+ target = b.attributes['target']
106
+ expect(target).to match(/\.#{formats[0]}$/)
107
+ expect(File.exist?(target)).to be true
108
+
109
+ unless formats[0] == :pdf
110
+ expect(b.attributes['width']).to_not be_nil
111
+ expect(b.attributes['height']).to_not be_nil
112
+ end
113
+ end
114
+
115
+ it 'should generate blocks with figure captions' do
116
+ File.write("#{name}.txt", code)
117
+
118
+ doc = <<-eos
119
+ = Hello, #{name}!
120
+ Doc Writer <doc@example.com>
121
+
122
+ == First Section
123
+
124
+ .This is a diagram
125
+ #{name}::#{name}.txt[]
126
+ eos
127
+
128
+ d = load_asciidoc doc
129
+ expect(d).to_not be_nil
130
+
131
+ b = d.find { |bl| bl.context == :image }
132
+ expect(b).to_not be_nil
133
+
134
+ expect(b.caption).to match(/Figure \d+/)
135
+ end
136
+
137
+ it 'should handle two block macros with the same source' do
138
+ File.write("#{name}.txt", code)
139
+
140
+ doc = <<-eos
141
+ = Hello, #{name}!
142
+ Doc Writer <doc@example.com>
143
+
144
+ == First Section
145
+
146
+ #{name}::#{name}.txt[]
147
+ #{name}::#{name}.txt[]
148
+ eos
149
+
150
+ d = load_asciidoc doc
151
+
152
+ b = d.find { |bl| bl.context == :image }
153
+ expect(b).to_not be_nil
154
+
155
+ target = b.attributes['target']
156
+ expect(File.exist?(target)).to be true
157
+ end
158
+
159
+ it 'should respect target attribute in block macros' do
160
+ File.write("#{name}.txt", code)
161
+
162
+ doc = <<-eos
163
+ = Hello, #{name}!
164
+ Doc Writer <doc@example.com>
165
+
166
+ == First Section
167
+
168
+ #{name}::#{name}.txt[target="foobar"]
169
+ #{name}::#{name}.txt[target="foobaz"]
170
+ eos
171
+
172
+ load_asciidoc doc
173
+ expect(File.exist?("foobar.#{formats[0]}")).to be true
174
+ expect(File.exist?("foobaz.#{formats[0]}")).to be true
175
+ expect(File.exist?("#{name}.#{formats[0]}")).to be false
176
+ end
177
+
178
+ it 'should respect target attribute values with relative paths in block macros' do
179
+ File.write("#{name}.txt", code)
180
+
181
+ doc = <<-eos
182
+ = Hello, #{name}!
183
+ Doc Writer <doc@example.com>
184
+
185
+ == First Section
186
+
187
+ #{name}::#{name}.txt[target="test/foobar"]
188
+ #{name}::#{name}.txt[target="test2/foobaz"]
189
+ eos
190
+
191
+ load_asciidoc doc
192
+ expect(File.exist?("test/foobar.#{formats[0]}")).to be true
193
+ expect(File.exist?("test2/foobaz.#{formats[0]}")).to be true
194
+ expect(File.exist?("#{name}.#{formats[0]}")).to be false
195
+ end
196
+ end
197
+
198
+ RSpec.shared_examples "block" do |name, code, formats|
199
+ formats.each do |format|
200
+ if format == :txt
201
+ it "#{name} should generate literal blocks when format is set to 'txt'" do
202
+ doc = <<-eos
203
+ = Hello, #{name}!
204
+ Doc Writer <doc@example.com>
205
+
206
+ == First Section
207
+
208
+ [#{name}, format="#{format}"]
209
+ ----
210
+ #{code}
211
+ ----
212
+ eos
213
+
214
+ d = load_asciidoc doc
215
+ expect(d).to_not be_nil
216
+
217
+ b = d.find { |bl| bl.context == :literal }
218
+ expect(b).to_not be_nil
219
+
220
+ expect(b.content_model).to eq :verbatim
221
+
222
+ expect(b.attributes['target']).to be_nil
223
+ end
224
+ else
225
+ it "#{name} should generate image blocks when format is set to '#{format}'" do
226
+ doc = <<-eos
227
+ = Hello, #{name}!
228
+ Doc Writer <doc@example.com>
229
+
230
+ == First Section
231
+
232
+ [#{name}, format="#{format}"]
233
+ ----
234
+ #{code}
235
+ ----
236
+ eos
237
+
238
+ d = load_asciidoc doc
239
+ expect(d).to_not be_nil
240
+
241
+ b = d.find { |bl| bl.context == :image }
242
+ expect(b).to_not be_nil
243
+
244
+ expect(b.content_model).to eq :empty
245
+
246
+ target = b.attributes['target']
247
+ expect(target).to_not be_nil
248
+ expect(target).to match(/\.#{format}$/)
249
+ expect(File.exist?(target)).to be true
250
+
251
+ unless format == :pdf
252
+ expect(b.attributes['width']).to_not be_nil
253
+ expect(b.attributes['height']).to_not be_nil
254
+ end
255
+ end
256
+ end
257
+ end
258
+
259
+ if formats.include? :svg
260
+ it "#{name} should respect the svg-type attribute when format is set to 'svg'" do
261
+ doc = <<-eos
262
+ = Hello, #{name}!
263
+ Doc Writer <doc@example.com>
264
+
265
+ == First Section
266
+
267
+ [#{name}, format="svg", svg-type="inline"]
268
+ ----
269
+ #{code}
270
+ ----
271
+ eos
272
+
273
+ d = load_asciidoc doc
274
+ expect(d).to_not be_nil
275
+
276
+ b = d.find { |bl| bl.context == :image }
277
+ expect(b).to_not be_nil
278
+
279
+ expect(b.content_model).to eq :empty
280
+
281
+ target = b.attributes['target']
282
+ expect(target).to_not be_nil
283
+ expect(target).to match(/\.svg/)
284
+ expect(File.exist?(target)).to be true
285
+
286
+ expect(b.option?('inline')).to be_truthy
287
+
288
+ unless formats[0] == :pdf
289
+ expect(b.attributes['width']).to_not be_nil
290
+ expect(b.attributes['height']).to_not be_nil
291
+ end
292
+ end
293
+
294
+ it "#{name} should respect the diagram-svg-type attribute when format is set to 'svg'" do
295
+ doc = <<-eos
296
+ = Hello, #{name}!
297
+ :diagram-svg-type: inline
298
+ Doc Writer <doc@example.com>
299
+
300
+ == First Section
301
+
302
+ [#{name}, format="svg"]
303
+ ----
304
+ #{code}
305
+ ----
306
+ eos
307
+
308
+ d = load_asciidoc doc
309
+ expect(d).to_not be_nil
310
+
311
+ b = d.find { |bl| bl.context == :image }
312
+ expect(b).to_not be_nil
313
+
314
+ expect(b.content_model).to eq :empty
315
+
316
+ target = b.attributes['target']
317
+ expect(target).to_not be_nil
318
+ expect(target).to match(/\.svg/)
319
+ expect(File.exist?(target)).to be true
320
+
321
+ expect(b.option?('inline')).to be_truthy
322
+
323
+ unless formats[0] == :pdf
324
+ expect(b.attributes['width']).to_not be_nil
325
+ expect(b.attributes['height']).to_not be_nil
326
+ end
327
+ end
328
+ end
329
+
330
+ it 'should raise an error when when format is set to an invalid value' do
331
+ doc = <<-eos
332
+ = Hello, #{name}!
333
+ Doc Writer <doc@example.com>
334
+
335
+ == First Section
336
+
337
+ [#{name}, format="foobar"]
338
+ ----
339
+ ----
340
+ eos
341
+
342
+ expect { load_asciidoc doc }.to raise_error(/support.*format/i)
343
+ end
344
+
345
+ it 'should not regenerate images when source has not changed' do
346
+ doc = <<-eos
347
+ = Hello, #{name}!
348
+ Doc Writer <doc@example.com>
349
+
350
+ == First Section
351
+
352
+ [#{name}]
353
+ ----
354
+ #{code}
355
+ ----
356
+ eos
357
+
358
+ d = load_asciidoc doc
359
+ b1 = d.find { |bl| bl.context == :image }
360
+ target1 = b1.attributes['target']
361
+ mtime1 = File.mtime(target1)
362
+
363
+ sleep 1
364
+
365
+ d = load_asciidoc doc
366
+ b2 = d.find { |bl| bl.context == :image }
367
+ target2 = b2.attributes['target']
368
+
369
+ mtime2 = File.mtime(target1)
370
+
371
+ expect(mtime2).to eq mtime1
372
+ end
373
+
374
+ it 'should write files to outdir if set' do
375
+ doc = <<-eos
376
+ = Hello, #{name}!
377
+ Doc Writer <doc@example.com>
378
+
379
+ == First Section
380
+
381
+ [#{name}]
382
+ ----
383
+ #{code}
384
+ ----
385
+ eos
386
+
387
+ d = load_asciidoc doc, {:attributes => {'outdir' => 'foo'}}
388
+ b = d.find { |bl| bl.context == :image }
389
+
390
+ target = b.attributes['target']
391
+ expect(target).to_not be_nil
392
+ expect(File.exist?(target)).to be false
393
+ expect(File.exist?(File.expand_path(target, 'foo'))).to be true
394
+ end
395
+
396
+ it 'should write files to to_dir if set' do
397
+ doc = <<-eos
398
+ = Hello, #{name}!
399
+ Doc Writer <doc@example.com>
400
+
401
+ == First Section
402
+
403
+ [#{name}]
404
+ ----
405
+ #{code}
406
+ ----
407
+ eos
408
+
409
+ d = load_asciidoc doc, {:to_dir => 'foo'}
410
+ b = d.find { |bl| bl.context == :image }
411
+
412
+ target = b.attributes['target']
413
+ expect(target).to_not be_nil
414
+ expect(File.exist?(target)).to be false
415
+ expect(File.exist?(File.expand_path(target, 'foo'))).to be true
416
+ end
417
+
418
+ it 'should write files to to_dir if set in safe mode' do
419
+ doc = <<-eos
420
+ = Hello, #{name}!
421
+ Doc Writer <doc@example.com>
422
+
423
+ == First Section
424
+
425
+ [#{name}]
426
+ ----
427
+ #{code}
428
+ ----
429
+ eos
430
+
431
+ to_dir = File.expand_path('foo')
432
+ d = load_asciidoc doc, {:to_dir => to_dir, :safe => :safe}
433
+ b = d.find { |bl| bl.context == :image }
434
+
435
+ target = b.attributes['target']
436
+ expect(target).to_not be_nil
437
+ expect(File.exist?(target)).to be false
438
+ expect(File.exist?(File.expand_path(target, to_dir))).to be true
439
+ end
440
+
441
+ it 'should write files to to_dir if set when embedded in table' do
442
+ doc = <<-eos
443
+ = Hello, #{name}!
444
+ Doc Writer <doc@example.com>
445
+
446
+ == First Section
447
+
448
+ |===
449
+ |Type | Example
450
+
451
+ |graphviz
452
+ a|
453
+ [#{name}]
454
+ ----
455
+ #{code.gsub('|', '\|')}
456
+ ----
457
+ |===
458
+ eos
459
+
460
+ d = load_asciidoc doc, {:to_dir => 'foo'}
461
+ b = d.find { |bl| bl.context == :image }
462
+
463
+ target = b.attributes['target']
464
+ expect(target).to_not be_nil
465
+ expect(File.exist?(target)).to be false
466
+ expect(File.exist?(File.expand_path(target, 'foo'))).to be true
467
+ end
468
+
469
+ it 'should write files to imagesoutdir if set' do
470
+ doc = <<-eos
471
+ = Hello, #{name}!
472
+ Doc Writer <doc@example.com>
473
+
474
+ == First Section
475
+
476
+ [#{name}]
477
+ ----
478
+ #{code}
479
+ ----
480
+ eos
481
+
482
+ d = load_asciidoc doc, {:attributes => {'imagesoutdir' => 'bar', 'outdir' => 'foo'}}
483
+ b = d.find { |bl| bl.context == :image }
484
+
485
+ target = b.attributes['target']
486
+ expect(target).to_not be_nil
487
+ expect(File.exist?(target)).to be false
488
+ expect(File.exist?(File.expand_path(target, 'bar'))).to be true
489
+ expect(File.exist?(File.expand_path(target, 'foo'))).to be false
490
+ end
491
+
492
+ it 'should write files to imagesoutdir if set in safe mode' do
493
+ doc = <<-eos
494
+ = Hello, #{name}!
495
+ Doc Writer <doc@example.com>
496
+
497
+ == First Section
498
+
499
+ [#{name}]
500
+ ----
501
+ #{code}
502
+ ----
503
+ eos
504
+
505
+ out_dir = File.expand_path('foo')
506
+ images_out_dir = File.expand_path('bar')
507
+
508
+ d = load_asciidoc doc, {:attributes => {'imagesoutdir' => images_out_dir, 'outdir' => out_dir}, :safe => :safe}
509
+ b = d.find { |bl| bl.context == :image }
510
+
511
+ target = b.attributes['target']
512
+ expect(target).to_not be_nil
513
+ expect(File.exist?(target)).to be false
514
+ expect(File.exist?(File.expand_path(target, images_out_dir))).to be true
515
+ expect(File.exist?(File.expand_path(target, out_dir))).to be false
516
+ end
517
+
518
+ it 'should omit width/height attributes when generating docbook' do
519
+ doc = <<-eos
520
+ = Hello, #{name}!
521
+ Doc Writer <doc@example.com>
522
+
523
+ == First Section
524
+
525
+ [#{name}]
526
+ ----
527
+ #{code}
528
+ ----
529
+ eos
530
+
531
+ d = load_asciidoc doc, :attributes => {'backend' => 'docbook5'}
532
+ expect(d).to_not be_nil
533
+
534
+ b = d.find { |bl| bl.context == :image }
535
+ expect(b).to_not be_nil
536
+
537
+ target = b.attributes['target']
538
+ expect(File.exist?(target)).to be true
539
+
540
+ expect(b.attributes['width']).to be_nil
541
+ expect(b.attributes['height']).to be_nil
542
+ end
543
+
544
+ it 'should generate blocks with figure captions' do
545
+ doc = <<-eos
546
+ = Hello, #{name}!
547
+ Doc Writer <doc@example.com>
548
+
549
+ == First Section
550
+
551
+ .Caption for my diagram
552
+ [#{name}]
553
+ ----
554
+ #{code}
555
+ ----
556
+ eos
557
+
558
+ d = load_asciidoc doc
559
+ expect(d).to_not be_nil
560
+
561
+ b = d.find { |bl| bl.context == :image }
562
+ expect(b).to_not be_nil
563
+
564
+ expect(b.caption).to match(/Figure \d+/)
565
+ end
566
+
567
+ it 'should support scaling diagrams' do
568
+ doc = <<-eos
569
+ = Hello, #{name}!
570
+ Doc Writer <doc@example.com>
571
+
572
+ == First Section
573
+
574
+ [#{name}, target="unscaled"]
575
+ ----
576
+ #{code}
577
+ ----
578
+ eos
579
+
580
+ scaled_doc = <<-eos
581
+ = Hello, #{name}!
582
+ Doc Writer <doc@example.com>
583
+
584
+ == First Section
585
+
586
+ [#{name}, scale="2", target="scaled"]
587
+ ----
588
+ #{code}
589
+ ----
590
+ eos
591
+
592
+ d = load_asciidoc doc, :attributes => {'backend' => 'html5'}
593
+ unscaled_image = d.find { |bl| bl.context == :image }
594
+
595
+ d = load_asciidoc scaled_doc, :attributes => {'backend' => 'html5'}
596
+ scaled_image = d.find { |bl| bl.context == :image }
597
+
598
+ unless formats[0] == :pdf
599
+ expect(scaled_image.attributes['width']).to be_within(1).of(unscaled_image.attributes['width'] * 2)
600
+ expect(scaled_image.attributes['height']).to be_within(1).of(unscaled_image.attributes['height'] * 2)
601
+ end
602
+ end
603
+ end