asciidoctor-diagram 1.5.18 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of asciidoctor-diagram might be problematic. Click here for more details.

Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +66 -0
  3. data/README.adoc +98 -23
  4. data/examples/features.adoc +2 -2
  5. data/lib/asciidoctor-diagram.rb +8 -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/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 +19 -0
  17. data/lib/asciidoctor-diagram/diagram_processor.rb +345 -0
  18. data/lib/asciidoctor-diagram/diagram_source.rb +306 -0
  19. data/lib/asciidoctor-diagram/ditaa/converter.rb +86 -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.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/graphviz/converter.rb +32 -0
  30. data/lib/asciidoctor-diagram/graphviz/extension.rb +6 -35
  31. data/lib/asciidoctor-diagram/http/converter.rb +99 -0
  32. data/lib/asciidoctor-diagram/http/server.rb +127 -0
  33. data/lib/asciidoctor-diagram/lilypond.rb +7 -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/meme/converter.rb +122 -0
  37. data/lib/asciidoctor-diagram/meme/extension.rb +5 -107
  38. data/lib/asciidoctor-diagram/mermaid/converter.rb +179 -0
  39. data/lib/asciidoctor-diagram/mermaid/extension.rb +6 -159
  40. data/lib/asciidoctor-diagram/msc/converter.rb +35 -0
  41. data/lib/asciidoctor-diagram/msc/extension.rb +6 -36
  42. data/lib/asciidoctor-diagram/nomnoml/converter.rb +25 -0
  43. data/lib/asciidoctor-diagram/nomnoml/extension.rb +6 -28
  44. data/lib/asciidoctor-diagram/pikchr.rb +7 -0
  45. data/lib/asciidoctor-diagram/pikchr/converter.rb +26 -0
  46. data/lib/asciidoctor-diagram/pikchr/extension.rb +14 -0
  47. data/lib/asciidoctor-diagram/plantuml/converter.rb +117 -0
  48. data/lib/asciidoctor-diagram/plantuml/extension.rb +10 -119
  49. data/lib/asciidoctor-diagram/shaape/converter.rb +25 -0
  50. data/lib/asciidoctor-diagram/shaape/extension.rb +6 -28
  51. data/lib/asciidoctor-diagram/smcat.rb +7 -0
  52. data/lib/asciidoctor-diagram/smcat/converter.rb +44 -0
  53. data/lib/asciidoctor-diagram/smcat/extension.rb +14 -0
  54. data/lib/asciidoctor-diagram/svgbob/converter.rb +49 -0
  55. data/lib/asciidoctor-diagram/svgbob/extension.rb +6 -28
  56. data/lib/asciidoctor-diagram/symbolator.rb +7 -0
  57. data/lib/asciidoctor-diagram/symbolator/converter.rb +23 -0
  58. data/lib/asciidoctor-diagram/symbolator/extension.rb +14 -0
  59. data/lib/asciidoctor-diagram/syntrax/converter.rb +55 -0
  60. data/lib/asciidoctor-diagram/syntrax/extension.rb +6 -51
  61. data/lib/asciidoctor-diagram/tikz/converter.rb +56 -0
  62. data/lib/asciidoctor-diagram/tikz/extension.rb +6 -60
  63. data/lib/asciidoctor-diagram/umlet/converter.rb +24 -0
  64. data/lib/asciidoctor-diagram/umlet/extension.rb +6 -28
  65. data/lib/asciidoctor-diagram/util/cli.rb +14 -3
  66. data/lib/asciidoctor-diagram/util/cli_generator.rb +19 -1
  67. data/lib/asciidoctor-diagram/util/gif.rb +2 -2
  68. data/lib/asciidoctor-diagram/util/java.rb +1 -1
  69. data/lib/asciidoctor-diagram/util/java_socket.rb +7 -9
  70. data/lib/asciidoctor-diagram/util/pdf.rb +2 -2
  71. data/lib/asciidoctor-diagram/util/png.rb +2 -2
  72. data/lib/asciidoctor-diagram/util/svg.rb +38 -19
  73. data/lib/asciidoctor-diagram/util/which.rb +0 -29
  74. data/lib/asciidoctor-diagram/vega/converter.rb +47 -0
  75. data/lib/asciidoctor-diagram/vega/extension.rb +6 -44
  76. data/lib/asciidoctor-diagram/version.rb +1 -1
  77. data/lib/asciidoctor-diagram/wavedrom/converter.rb +50 -0
  78. data/lib/asciidoctor-diagram/wavedrom/extension.rb +6 -46
  79. data/lib/ditaa-1.3.15.jar +0 -0
  80. data/lib/ditaamini-0.12.jar +0 -0
  81. data/lib/plantuml-1.3.15.jar +0 -0
  82. data/lib/plantuml.jar +0 -0
  83. data/lib/server-1.3.15.jar +0 -0
  84. data/spec/bpmn-example.xml +44 -0
  85. data/spec/bpmn_spec.rb +96 -0
  86. data/spec/bytefield_spec.rb +230 -0
  87. data/spec/ditaa_spec.rb +32 -0
  88. data/spec/dpic_spec.rb +74 -0
  89. data/spec/gnuplot_spec.rb +478 -0
  90. data/spec/lilypond_spec.rb +151 -0
  91. data/spec/mermaid_spec.rb +33 -1
  92. data/spec/pikchr_spec.rb +106 -0
  93. data/spec/plantuml_spec.rb +90 -1
  94. data/spec/smcat_spec.rb +164 -0
  95. data/spec/symbolator_spec.rb +200 -0
  96. data/spec/test_helper.rb +0 -18
  97. metadata +73 -11
  98. data/lib/asciidoctor-diagram/extensions.rb +0 -568
  99. data/lib/ditaa-1.3.13.jar +0 -0
  100. data/lib/ditaamini-0.11.jar +0 -0
  101. data/lib/plantuml-1.3.13.jar +0 -0
  102. data/lib/server-1.3.13.jar +0 -0
@@ -0,0 +1,151 @@
1
+ require_relative 'test_helper'
2
+
3
+ code = <<-eos
4
+ \\relative c' { f d f a d f e d cis a cis e a g f e }
5
+ eos
6
+
7
+ describe Asciidoctor::Diagram::LilypondBlockMacroProcessor, :broken_on_windows do
8
+ it "should generate PNG images when format is set to 'png'" do
9
+ File.write('lilypond.txt', code)
10
+
11
+ doc = <<-eos
12
+ = Hello, Lilypond!
13
+ Doc Writer <doc@example.com>
14
+
15
+ == First Section
16
+
17
+ lilypond::lilypond.txt[format="png"]
18
+ eos
19
+
20
+ d = load_asciidoc doc
21
+ expect(d).to_not be_nil
22
+
23
+ b = d.find { |bl| bl.context == :image }
24
+ expect(b).to_not be_nil
25
+
26
+ expect(b.content_model).to eq :empty
27
+
28
+ target = b.attributes['target']
29
+ expect(target).to_not be_nil
30
+ expect(target).to match(/\.png/)
31
+ expect(File.exist?(target)).to be true
32
+
33
+ expect(b.attributes['width']).to_not be_nil
34
+ expect(b.attributes['height']).to_not be_nil
35
+ end
36
+ end
37
+
38
+ describe Asciidoctor::Diagram::LilypondBlockProcessor, :broken_on_windows do
39
+ it "should generate PNG images when format is set to 'png'" do
40
+ doc = <<-eos
41
+ = Hello, Lilypond!
42
+ Doc Writer <doc@example.com>
43
+
44
+ == First Section
45
+
46
+ [lilypond, format="png"]
47
+ ----
48
+ #{code}
49
+ ----
50
+ eos
51
+
52
+ d = load_asciidoc doc
53
+ expect(d).to_not be_nil
54
+
55
+ b = d.find { |bl| bl.context == :image }
56
+ expect(b).to_not be_nil
57
+
58
+ expect(b.content_model).to eq :empty
59
+
60
+ target = b.attributes['target']
61
+ expect(target).to_not be_nil
62
+ expect(target).to match(/\.png/)
63
+ expect(File.exist?(target)).to be true
64
+
65
+ expect(b.attributes['width']).to_not be_nil
66
+ expect(b.attributes['height']).to_not be_nil
67
+ end
68
+
69
+ it "should raise an error when when format is set to an invalid value" do
70
+ doc = <<-eos
71
+ = Hello, Lilypond!
72
+ Doc Writer <doc@example.com>
73
+
74
+ == First Section
75
+
76
+ [lilypond, format="foobar"]
77
+ ----
78
+ ----
79
+ eos
80
+
81
+ expect { load_asciidoc doc }.to raise_error(/support.*format/i)
82
+ end
83
+
84
+ it "should not regenerate images when source has not changed" do
85
+ File.write('lilypond.txt', code)
86
+
87
+ doc = <<-eos
88
+ = Hello, Lilypond!
89
+ Doc Writer <doc@example.com>
90
+
91
+ == First Section
92
+
93
+ lilypond::lilypond.txt
94
+
95
+ [lilypond, format="png"]
96
+ ----
97
+ #{code}
98
+ ----
99
+ eos
100
+
101
+ d = load_asciidoc doc
102
+ b = d.find { |bl| bl.context == :image }
103
+ expect(b).to_not be_nil
104
+ target = b.attributes['target']
105
+ mtime1 = File.mtime(target)
106
+
107
+ sleep 1
108
+
109
+ d = load_asciidoc doc
110
+
111
+ mtime2 = File.mtime(target)
112
+
113
+ expect(mtime2).to eq mtime1
114
+ end
115
+
116
+ it "should handle two block macros with the same source" do
117
+ File.write('lilypond.txt', code)
118
+
119
+ doc = <<-eos
120
+ = Hello, Lilypond!
121
+ Doc Writer <doc@example.com>
122
+
123
+ == First Section
124
+
125
+ lilypond::lilypond.txt[]
126
+ lilypond::lilypond.txt[]
127
+ eos
128
+
129
+ load_asciidoc doc
130
+ expect(File.exist?('lilypond.png')).to be true
131
+ end
132
+
133
+ it "should respect target attribute in block macros" do
134
+ File.write('lilypond.txt', code)
135
+
136
+ doc = <<-eos
137
+ = Hello, Lilypond!
138
+ Doc Writer <doc@example.com>
139
+
140
+ == First Section
141
+
142
+ lilypond::lilypond.txt["foobar"]
143
+ lilypond::lilypond.txt["foobaz"]
144
+ eos
145
+
146
+ load_asciidoc doc
147
+ expect(File.exist?('foobar.png')).to be true
148
+ expect(File.exist?('foobaz.png')).to be true
149
+ expect(File.exist?('lilypond.png')).to be false
150
+ end
151
+ end
@@ -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
@@ -0,0 +1,106 @@
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
+ it "should generate SVG images when format is set to 'svg'" do
47
+ File.write('pikchr.txt', code)
48
+
49
+ doc = <<-eos
50
+ = Hello, Pikchr!
51
+ Doc Writer <doc@example.com>
52
+
53
+ == First Section
54
+
55
+ pikchr::pikchr.txt[format="svg"]
56
+ eos
57
+
58
+ d = load_asciidoc doc
59
+ expect(d).to_not be_nil
60
+
61
+ b = d.find { |bl| bl.context == :image }
62
+ expect(b).to_not be_nil
63
+
64
+ expect(b.content_model).to eq :empty
65
+
66
+ target = b.attributes['target']
67
+ expect(target).to_not be_nil
68
+ expect(target).to match(/\.svg/)
69
+ expect(File.exist?(target)).to be true
70
+
71
+ expect(b.attributes['width']).to_not be_nil
72
+ expect(b.attributes['height']).to_not be_nil
73
+ end
74
+ end
75
+
76
+ describe Asciidoctor::Diagram::ErdBlockProcessor, :broken_on_travis, :broken_on_windows do
77
+ it "should generate SVG images when format is set to 'svg'" do
78
+ doc = <<-eos
79
+ = Hello, Pikchr!
80
+ Doc Writer <doc@example.com>
81
+
82
+ == First Section
83
+
84
+ [pikchr, format="svg"]
85
+ ----
86
+ #{code}
87
+ ----
88
+ eos
89
+
90
+ d = load_asciidoc doc
91
+ expect(d).to_not be_nil
92
+
93
+ b = d.find { |bl| bl.context == :image }
94
+ expect(b).to_not be_nil
95
+
96
+ expect(b.content_model).to eq :empty
97
+
98
+ target = b.attributes['target']
99
+ expect(target).to_not be_nil
100
+ expect(target).to match(/\.svg/)
101
+ expect(File.exist?(target)).to be true
102
+
103
+ expect(b.attributes['width']).to_not be_nil
104
+ expect(b.attributes['height']).to_not be_nil
105
+ end
106
+ end
@@ -314,6 +314,77 @@ User --> (Use the application) : Label
314
314
  expect(b.attributes['height']).to_not be_nil
315
315
  end
316
316
 
317
+ it "should respect the svg-type attribute when format is set to 'svg'" do
318
+ doc = <<-eos
319
+ = Hello, PlantUML!
320
+ Doc Writer <doc@example.com>
321
+
322
+ == First Section
323
+
324
+ [plantuml, format="svg", svg-type="inline"]
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 == :image }
337
+ expect(b).to_not be_nil
338
+
339
+ expect(b.content_model).to eq :empty
340
+
341
+ target = b.attributes['target']
342
+ expect(target).to_not be_nil
343
+ expect(target).to match(/\.svg/)
344
+ expect(File.exist?(target)).to be true
345
+
346
+ expect(b.option?('inline')).to be_truthy
347
+
348
+ expect(b.attributes['width']).to_not be_nil
349
+ expect(b.attributes['height']).to_not be_nil
350
+ end
351
+
352
+ it "should respect the diagram-svg-type attribute when format is set to 'svg'" do
353
+ doc = <<-eos
354
+ = Hello, PlantUML!
355
+ :diagram-svg-type: inline
356
+ Doc Writer <doc@example.com>
357
+
358
+ == First Section
359
+
360
+ [plantuml, format="svg"]
361
+ ----
362
+ User -> (Start)
363
+ User --> (Use the application) : Label
364
+
365
+ :Main Admin: ---> (Use the application) : Another label
366
+ ----
367
+ eos
368
+
369
+ d = load_asciidoc doc
370
+ expect(d).to_not be_nil
371
+
372
+ b = d.find { |bl| bl.context == :image }
373
+ expect(b).to_not be_nil
374
+
375
+ expect(b.content_model).to eq :empty
376
+
377
+ target = b.attributes['target']
378
+ expect(target).to_not be_nil
379
+ expect(target).to match(/\.svg/)
380
+ expect(File.exist?(target)).to be true
381
+
382
+ expect(b.option?('inline')).to be_truthy
383
+
384
+ expect(b.attributes['width']).to_not be_nil
385
+ expect(b.attributes['height']).to_not be_nil
386
+ end
387
+
317
388
  it "should generate literal blocks when format is set to 'txt'" do
318
389
  doc = <<-eos
319
390
  = Hello, PlantUML!
@@ -389,7 +460,7 @@ skinparam ArrowColor #DEADBE
389
460
  expect(File.exist?(target)).to be true
390
461
 
391
462
  svg = File.read(target, :encoding => Encoding::UTF_8)
392
- expect(svg).to match(/<path.*fill="#DEADBE"/)
463
+ expect(svg).to match(/<[^<]+ fill=["']#DEADBE["']/)
393
464
  end
394
465
 
395
466
  it 'should not regenerate images when source has not changed' do
@@ -1074,4 +1145,22 @@ Doc Writer <doc@example.com>
1074
1145
  expect(b.attributes['width']).to_not be_nil
1075
1146
  expect(b.attributes['height']).to_not be_nil
1076
1147
  end
1148
+
1149
+ it "should report syntax errors" do
1150
+ doc = <<-eos
1151
+ = Hello, PlantUML!
1152
+ Doc Writer <doc@example.com>
1153
+
1154
+ == First Section
1155
+
1156
+ [plantuml,format="svg"]
1157
+ ----
1158
+ Bob; Alice; foo
1159
+ ----
1160
+ eos
1161
+
1162
+ expect {
1163
+ load_asciidoc doc
1164
+ }.to raise_error(/syntax error/i)
1165
+ end
1077
1166
  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