asciidoctor-diagram 1.5.18 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +75 -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 +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 +357 -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.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 +132 -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 +58 -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 +46 -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/a2s_spec.rb +2 -140
  85. data/spec/blockdiag_spec.rb +2 -200
  86. data/spec/bpmn_spec.rb +56 -0
  87. data/spec/bytefield_spec.rb +92 -0
  88. data/spec/ditaa_spec.rb +37 -143
  89. data/spec/dpic_spec.rb +19 -0
  90. data/spec/erd_spec.rb +2 -199
  91. data/spec/gnuplot_spec.rb +225 -0
  92. data/spec/graphviz_spec.rb +6 -145
  93. data/spec/lilypond_spec.rb +13 -0
  94. data/spec/mermaid_spec.rb +35 -200
  95. data/spec/msc_spec.rb +2 -199
  96. data/spec/nomnoml_spec.rb +4 -142
  97. data/spec/pikchr_spec.rb +51 -0
  98. data/spec/plantuml_spec.rb +24 -507
  99. data/spec/shaape_spec.rb +9 -221
  100. data/spec/shared_examples.rb +552 -0
  101. data/spec/smcat_spec.rb +26 -0
  102. data/spec/svgbob_spec.rb +2 -140
  103. data/spec/symbolator_spec.rb +23 -0
  104. data/spec/syntrax_spec.rb +5 -215
  105. data/spec/test_helper.rb +1 -18
  106. data/spec/tikz_spec.rb +4 -24
  107. data/spec/umlet_spec.rb +2 -58
  108. data/spec/vega_spec.rb +4 -117
  109. data/spec/wavedrom_spec.rb +2 -199
  110. metadata +73 -11
  111. data/lib/asciidoctor-diagram/extensions.rb +0 -568
  112. data/lib/ditaa-1.3.13.jar +0 -0
  113. data/lib/ditaamini-0.11.jar +0 -0
  114. data/lib/plantuml-1.3.13.jar +0 -0
  115. data/lib/server-1.3.13.jar +0 -0
@@ -1,159 +1,20 @@
1
1
  require_relative 'test_helper'
2
2
 
3
- describe Asciidoctor::Diagram::GraphvizBlockMacroProcessor do
4
- it "should generate PNG images when format is set to 'png'" do
5
- code = <<-eos
3
+ code = <<-eos
6
4
  digraph foo {
7
5
  node [style=rounded]
8
6
  node1 [shape=box]
9
7
  node2 [fillcolor=yellow, style="rounded,filled", shape=diamond]
10
- node3 [shape=record, label="{ a | b | c }"]
8
+ node3 [shape=record, label=" a b c"]
11
9
 
12
10
  node1 -> node2 -> node3
13
11
  }
14
- eos
15
-
16
- File.write('graphviz.txt', code)
17
-
18
- doc = <<-eos
19
- = Hello, graphviz!
20
- Doc Writer <doc@example.com>
21
-
22
- == First Section
23
-
24
- graphviz::graphviz.txt[format="png"]
25
- eos
26
-
27
- d = load_asciidoc doc
28
- expect(d).to_not be_nil
29
-
30
- b = d.find { |bl| bl.context == :image }
31
- expect(b).to_not be_nil
12
+ eos
32
13
 
33
- expect(b.content_model).to eq :empty
34
-
35
- target = b.attributes['target']
36
- expect(target).to_not be_nil
37
- expect(target).to match(/\.png$/)
38
- expect(File.exist?(target)).to be true
39
-
40
- expect(b.attributes['width']).to_not be_nil
41
- expect(b.attributes['height']).to_not be_nil
42
- end
14
+ describe Asciidoctor::Diagram::GraphvizBlockMacroProcessor do
15
+ include_examples "block_macro", :graphviz, code, [:png, :svg]
43
16
  end
44
17
 
45
18
  describe Asciidoctor::Diagram::GraphvizBlockProcessor do
46
- it "should generate PNG images when format is set to 'png'" do
47
- doc = <<-eos
48
- = Hello, graphviz!
49
- Doc Writer <doc@example.com>
50
-
51
- == First Section
52
-
53
- [graphviz, format="png"]
54
- ----
55
- digraph foo {
56
- node [style=rounded]
57
- node1 [shape=box]
58
- node2 [fillcolor=yellow, style="rounded,filled", shape=diamond]
59
- node3 [shape=record, label="{ a | b | c }"]
60
-
61
- node1 -> node2 -> node3
62
- }
63
- ----
64
- eos
65
-
66
- d = load_asciidoc doc
67
- expect(d).to_not be_nil
68
-
69
- b = d.find { |bl| bl.context == :image }
70
- expect(b).to_not be_nil
71
-
72
- expect(b.content_model).to eq :empty
73
-
74
- target = b.attributes['target']
75
- expect(target).to_not be_nil
76
- expect(target).to match(/\.png$/)
77
- expect(File.exist?(target)).to be true
78
-
79
- expect(b.attributes['width']).to_not be_nil
80
- expect(b.attributes['height']).to_not be_nil
81
- end
82
-
83
- it "should generate SVG images when format is set to 'svg'" do
84
- doc = <<-eos
85
- = Hello, graphviz!
86
- Doc Writer <doc@example.com>
87
-
88
- == First Section
89
-
90
- [graphviz, format="svg"]
91
- ----
92
- digraph foo {
93
- node [style=rounded]
94
- node1 [shape=box]
95
- node2 [fillcolor=yellow, style="rounded,filled", shape=diamond]
96
- node3 [shape=record, label="{ a | b | c }"]
97
-
98
- node1 -> node2 -> node3
99
- }
100
- ----
101
- eos
102
-
103
- d = load_asciidoc doc
104
- expect(d).to_not be_nil
105
-
106
- b = d.find { |bl| bl.context == :image }
107
- expect(b).to_not be_nil
108
-
109
- expect(b.content_model).to eq :empty
110
-
111
- target = b.attributes['target']
112
- expect(target).to_not be_nil
113
- expect(target).to match(/\.svg$/)
114
- expect(File.exist?(target)).to be true
115
-
116
- expect(b.attributes['width']).to_not be_nil
117
- expect(b.attributes['height']).to_not be_nil
118
- end
119
-
120
- it "should raise an error when when format is set to an invalid value" do
121
- doc = <<-eos
122
- = Hello, graphviz!
123
- Doc Writer <doc@example.com>
124
-
125
- == First Section
126
-
127
- [graphviz, format="foobar"]
128
- ----
129
- ----
130
- eos
131
-
132
- expect { load_asciidoc doc }.to raise_error(/support.*format/i)
133
- end
134
-
135
- it "should support neato layout engine" do
136
- doc = <<-eos
137
- = Hello, graphviz!
138
- Doc Writer <doc@example.com>
139
-
140
- == First Section
141
-
142
- [graphviz, layout=neato]
143
- ----
144
- digraph g { rankdir=LR; Text->Graphviz->Image }
145
- ----
146
- eos
147
-
148
- d = load_asciidoc doc
149
- expect(d).to_not be_nil
150
-
151
- b = d.find { |bl| bl.context == :image }
152
- expect(b).to_not be_nil
153
-
154
- expect(b.content_model).to eq :empty
155
-
156
- target = b.attributes['target']
157
- expect(File.exist?(target)).to be true
158
- end
19
+ include_examples "block", :graphviz, code, [:png, :svg]
159
20
  end
@@ -0,0 +1,13 @@
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
+ include_examples "block_macro", :lilypond, code, [:png]
9
+ end
10
+
11
+ describe Asciidoctor::Diagram::LilypondBlockProcessor, :broken_on_windows do
12
+ include_examples "block", :lilypond, code, [:png]
13
+ end
@@ -9,208 +9,11 @@ graph LR
9
9
  eos
10
10
 
11
11
  describe Asciidoctor::Diagram::MermaidBlockMacroProcessor do
12
- it "should generate PNG images when format is set to 'png'" do
13
- File.write('mermaid.txt', code)
14
-
15
- doc = <<-eos
16
- = Hello, Mermaid!
17
- Doc Writer <doc@example.com>
18
-
19
- == First Section
20
-
21
- mermaid::mermaid.txt[format="png"]
22
- eos
23
-
24
- d = load_asciidoc doc
25
- expect(d).to_not be_nil
26
-
27
- b = d.find { |bl| bl.context == :image }
28
- expect(b).to_not be_nil
29
-
30
- expect(b.content_model).to eq :empty
31
-
32
- target = b.attributes['target']
33
- expect(target).to_not be_nil
34
- expect(target).to match(/\.png$/)
35
- expect(File.exist?(target)).to be true
36
-
37
- expect(b.attributes['width']).to_not be_nil
38
- expect(b.attributes['height']).to_not be_nil
39
- end
40
-
41
- it "should generate SVG images when format is set to 'svg'" do
42
- File.write('mermaid.txt', code)
43
-
44
- doc = <<-eos
45
- = Hello, Mermaid!
46
- Doc Writer <doc@example.com>
47
-
48
- == First Section
49
-
50
- mermaid::mermaid.txt[format="svg"]
51
- eos
52
-
53
- d = load_asciidoc doc
54
- expect(d).to_not be_nil
55
-
56
- b = d.find { |bl| bl.context == :image }
57
- expect(b).to_not be_nil
58
-
59
- expect(b.content_model).to eq :empty
60
-
61
- target = b.attributes['target']
62
- expect(target).to_not be_nil
63
- expect(target).to match(/\.svg/)
64
- expect(File.exist?(target)).to be true
65
-
66
- expect(b.attributes['width']).to_not be_nil
67
- expect(b.attributes['height']).to_not be_nil
68
- end
12
+ include_examples "block_macro", :mermaid, code, [:png, :svg]
69
13
  end
70
14
 
71
15
  describe Asciidoctor::Diagram::MermaidBlockProcessor do
72
- it "should generate PNG images when format is set to 'png'" do
73
- doc = <<-eos
74
- = Hello, Mermaid!
75
- Doc Writer <doc@example.com>
76
-
77
- == First Section
78
-
79
- [mermaid, format="png"]
80
- ----
81
- #{code}
82
- ----
83
- eos
84
-
85
- d = load_asciidoc doc
86
- expect(d).to_not be_nil
87
-
88
- b = d.find { |bl| bl.context == :image }
89
- expect(b).to_not be_nil
90
-
91
- expect(b.content_model).to eq :empty
92
-
93
- target = b.attributes['target']
94
- expect(target).to_not be_nil
95
- expect(target).to match(/\.png$/)
96
- expect(File.exist?(target)).to be true
97
-
98
- expect(b.attributes['width']).to_not be_nil
99
- expect(b.attributes['height']).to_not be_nil
100
- end
101
-
102
- it "should generate SVG images when format is set to 'svg'" do
103
- doc = <<-eos
104
- = Hello, Mermaid!
105
- Doc Writer <doc@example.com>
106
-
107
- == First Section
108
-
109
- [mermaid, format="svg"]
110
- ----
111
- #{code}
112
- ----
113
- eos
114
-
115
- d = load_asciidoc doc
116
- expect(d).to_not be_nil
117
-
118
- b = d.find { |bl| bl.context == :image }
119
- expect(b).to_not be_nil
120
-
121
- expect(b.content_model).to eq :empty
122
-
123
- target = b.attributes['target']
124
- expect(target).to_not be_nil
125
- expect(target).to match(/\.svg/)
126
- expect(File.exist?(target)).to be true
127
-
128
- expect(b.attributes['width']).to_not be_nil
129
- expect(b.attributes['height']).to_not be_nil
130
- end
131
-
132
- it "should raise an error when when format is set to an invalid value" do
133
- doc = <<-eos
134
- = Hello, Mermaid!
135
- Doc Writer <doc@example.com>
136
-
137
- == First Section
138
-
139
- [mermaid, format="foobar"]
140
- ----
141
- ----
142
- eos
143
-
144
- expect { load_asciidoc doc }.to raise_error(/support.*format/i)
145
- end
146
-
147
- it "should not regenerate images when source has not changed" do
148
- File.write('mermaid.txt', code)
149
-
150
- doc = <<-eos
151
- = Hello, Mermaid!
152
- Doc Writer <doc@example.com>
153
-
154
- == First Section
155
-
156
- mermaid::mermaid.txt
157
-
158
- [mermaid, format="png"]
159
- ----
160
- #{code}
161
- ----
162
- eos
163
-
164
- d = load_asciidoc doc
165
- b = d.find { |bl| bl.context == :image }
166
- expect(b).to_not be_nil
167
- target = b.attributes['target']
168
- mtime1 = File.mtime(target)
169
-
170
- sleep 1
171
-
172
- d = load_asciidoc doc
173
-
174
- mtime2 = File.mtime(target)
175
-
176
- expect(mtime2).to eq mtime1
177
- end
178
-
179
- it "should handle two block macros with the same source" do
180
- File.write('mermaid.txt', code)
181
-
182
- doc = <<-eos
183
- = Hello, Mermaid!
184
- Doc Writer <doc@example.com>
185
-
186
- == First Section
187
-
188
- mermaid::mermaid.txt[]
189
- mermaid::mermaid.txt[]
190
- eos
191
-
192
- load_asciidoc doc
193
- expect(File.exist?('mermaid.png')).to be true
194
- end
195
-
196
- it "should respect target attribute in block macros" do
197
- File.write('mermaid.txt', code)
198
-
199
- doc = <<-eos
200
- = Hello, Mermaid!
201
- Doc Writer <doc@example.com>
202
-
203
- == First Section
204
-
205
- mermaid::mermaid.txt["foobar"]
206
- mermaid::mermaid.txt["foobaz"]
207
- eos
208
-
209
- load_asciidoc doc
210
- expect(File.exist?('foobar.png')).to be true
211
- expect(File.exist?('foobaz.png')).to be true
212
- expect(File.exist?('mermaid.png')).to be false
213
- end
16
+ include_examples "block", :mermaid, code, [:png, :svg]
214
17
 
215
18
  it "should respect the sequenceConfig attribute" do
216
19
  seq_diag = <<-eos
@@ -301,4 +104,36 @@ mermaid::mermaid.txt["dark", format="svg", theme="dark"]
301
104
  expect(File.exist?('dark.svg')).to be true
302
105
  expect(File.read('default.svg')).to_not be File.read('dark.svg')
303
106
  end
304
- end
107
+
108
+ it "should respect the puppeteerConfig attribute" do
109
+ seq_diag = <<-eos
110
+ sequenceDiagram
111
+ Alice->>John: Hello John, how are you?
112
+ John-->>Alice: Great!
113
+ eos
114
+
115
+ pptr_config = <<-eos
116
+ {
117
+ "args": ["--no-sandbox"]
118
+ }
119
+ eos
120
+ File.write('pptrconfig.txt', pptr_config)
121
+
122
+ File.write('mermaid.txt', seq_diag)
123
+
124
+ doc = <<-eos
125
+ = Hello, Mermaid!
126
+ Doc Writer <doc@example.com>
127
+
128
+ == First Section
129
+
130
+ mermaid::mermaid.txt["with_config", puppeteerConfig="pptrconfig.txt"]
131
+ mermaid::mermaid.txt["without_config"]
132
+ eos
133
+
134
+ load_asciidoc doc
135
+ expect(File.exist?('with_config.png')).to be true
136
+ expect(File.exist?('without_config.png')).to be true
137
+ expect(File.size('with_config.png')).to be File.size('without_config.png')
138
+ end
139
+ end
@@ -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