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.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +66 -0
- data/README.adoc +98 -23
- data/examples/features.adoc +2 -2
- data/lib/asciidoctor-diagram.rb +8 -0
- data/lib/asciidoctor-diagram/a2s/converter.rb +55 -0
- data/lib/asciidoctor-diagram/a2s/extension.rb +6 -52
- data/lib/asciidoctor-diagram/blockdiag/converter.rb +37 -0
- data/lib/asciidoctor-diagram/blockdiag/extension.rb +9 -116
- data/lib/asciidoctor-diagram/bpmn.rb +7 -0
- data/lib/asciidoctor-diagram/bpmn/converter.rb +62 -0
- data/lib/asciidoctor-diagram/bpmn/extension.rb +14 -0
- data/lib/asciidoctor-diagram/bytefield.rb +7 -0
- data/lib/asciidoctor-diagram/bytefield/converter.rb +26 -0
- data/lib/asciidoctor-diagram/bytefield/extension.rb +14 -0
- data/lib/asciidoctor-diagram/diagram_converter.rb +19 -0
- data/lib/asciidoctor-diagram/diagram_processor.rb +345 -0
- data/lib/asciidoctor-diagram/diagram_source.rb +306 -0
- data/lib/asciidoctor-diagram/ditaa/converter.rb +86 -0
- data/lib/asciidoctor-diagram/ditaa/extension.rb +6 -71
- data/lib/asciidoctor-diagram/dpic.rb +7 -0
- data/lib/asciidoctor-diagram/dpic/converter.rb +30 -0
- data/lib/asciidoctor-diagram/dpic/extension.rb +14 -0
- data/lib/asciidoctor-diagram/erd/converter.rb +31 -0
- data/lib/asciidoctor-diagram/erd/extension.rb +6 -35
- data/lib/asciidoctor-diagram/gnuplot.rb +7 -0
- data/lib/asciidoctor-diagram/gnuplot/converter.rb +63 -0
- data/lib/asciidoctor-diagram/gnuplot/extension.rb +14 -0
- data/lib/asciidoctor-diagram/graphviz/converter.rb +32 -0
- data/lib/asciidoctor-diagram/graphviz/extension.rb +6 -35
- data/lib/asciidoctor-diagram/http/converter.rb +99 -0
- data/lib/asciidoctor-diagram/http/server.rb +127 -0
- data/lib/asciidoctor-diagram/lilypond.rb +7 -0
- data/lib/asciidoctor-diagram/lilypond/converter.rb +54 -0
- data/lib/asciidoctor-diagram/lilypond/extension.rb +14 -0
- data/lib/asciidoctor-diagram/meme/converter.rb +122 -0
- data/lib/asciidoctor-diagram/meme/extension.rb +5 -107
- data/lib/asciidoctor-diagram/mermaid/converter.rb +179 -0
- data/lib/asciidoctor-diagram/mermaid/extension.rb +6 -159
- data/lib/asciidoctor-diagram/msc/converter.rb +35 -0
- data/lib/asciidoctor-diagram/msc/extension.rb +6 -36
- data/lib/asciidoctor-diagram/nomnoml/converter.rb +25 -0
- data/lib/asciidoctor-diagram/nomnoml/extension.rb +6 -28
- data/lib/asciidoctor-diagram/pikchr.rb +7 -0
- data/lib/asciidoctor-diagram/pikchr/converter.rb +26 -0
- data/lib/asciidoctor-diagram/pikchr/extension.rb +14 -0
- data/lib/asciidoctor-diagram/plantuml/converter.rb +117 -0
- data/lib/asciidoctor-diagram/plantuml/extension.rb +10 -119
- data/lib/asciidoctor-diagram/shaape/converter.rb +25 -0
- data/lib/asciidoctor-diagram/shaape/extension.rb +6 -28
- data/lib/asciidoctor-diagram/smcat.rb +7 -0
- data/lib/asciidoctor-diagram/smcat/converter.rb +44 -0
- data/lib/asciidoctor-diagram/smcat/extension.rb +14 -0
- data/lib/asciidoctor-diagram/svgbob/converter.rb +49 -0
- data/lib/asciidoctor-diagram/svgbob/extension.rb +6 -28
- data/lib/asciidoctor-diagram/symbolator.rb +7 -0
- data/lib/asciidoctor-diagram/symbolator/converter.rb +23 -0
- data/lib/asciidoctor-diagram/symbolator/extension.rb +14 -0
- data/lib/asciidoctor-diagram/syntrax/converter.rb +55 -0
- data/lib/asciidoctor-diagram/syntrax/extension.rb +6 -51
- data/lib/asciidoctor-diagram/tikz/converter.rb +56 -0
- data/lib/asciidoctor-diagram/tikz/extension.rb +6 -60
- data/lib/asciidoctor-diagram/umlet/converter.rb +24 -0
- data/lib/asciidoctor-diagram/umlet/extension.rb +6 -28
- data/lib/asciidoctor-diagram/util/cli.rb +14 -3
- data/lib/asciidoctor-diagram/util/cli_generator.rb +19 -1
- data/lib/asciidoctor-diagram/util/gif.rb +2 -2
- data/lib/asciidoctor-diagram/util/java.rb +1 -1
- data/lib/asciidoctor-diagram/util/java_socket.rb +7 -9
- data/lib/asciidoctor-diagram/util/pdf.rb +2 -2
- data/lib/asciidoctor-diagram/util/png.rb +2 -2
- data/lib/asciidoctor-diagram/util/svg.rb +38 -19
- data/lib/asciidoctor-diagram/util/which.rb +0 -29
- data/lib/asciidoctor-diagram/vega/converter.rb +47 -0
- data/lib/asciidoctor-diagram/vega/extension.rb +6 -44
- data/lib/asciidoctor-diagram/version.rb +1 -1
- data/lib/asciidoctor-diagram/wavedrom/converter.rb +50 -0
- data/lib/asciidoctor-diagram/wavedrom/extension.rb +6 -46
- data/lib/ditaa-1.3.15.jar +0 -0
- data/lib/ditaamini-0.12.jar +0 -0
- data/lib/plantuml-1.3.15.jar +0 -0
- data/lib/plantuml.jar +0 -0
- data/lib/server-1.3.15.jar +0 -0
- data/spec/bpmn-example.xml +44 -0
- data/spec/bpmn_spec.rb +96 -0
- data/spec/bytefield_spec.rb +230 -0
- data/spec/ditaa_spec.rb +32 -0
- data/spec/dpic_spec.rb +74 -0
- data/spec/gnuplot_spec.rb +478 -0
- data/spec/lilypond_spec.rb +151 -0
- data/spec/mermaid_spec.rb +33 -1
- data/spec/pikchr_spec.rb +106 -0
- data/spec/plantuml_spec.rb +90 -1
- data/spec/smcat_spec.rb +164 -0
- data/spec/symbolator_spec.rb +200 -0
- data/spec/test_helper.rb +0 -18
- metadata +73 -11
- data/lib/asciidoctor-diagram/extensions.rb +0 -568
- data/lib/ditaa-1.3.13.jar +0 -0
- data/lib/ditaamini-0.11.jar +0 -0
- data/lib/plantuml-1.3.13.jar +0 -0
- data/lib/server-1.3.13.jar +0 -0
@@ -0,0 +1,230 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
code = <<-eos
|
4
|
+
;; This the source for the sample diagram illustrated in the project Read Me.
|
5
|
+
|
6
|
+
;; Some nice default background colors, used to distinguish header sections.
|
7
|
+
(defattrs :bg-green {:fill "#a0ffa0"})
|
8
|
+
(defattrs :bg-yellow {:fill "#ffffa0"})
|
9
|
+
(defattrs :bg-pink {:fill "#ffb0a0"})
|
10
|
+
(defattrs :bg-cyan {:fill "#a0fafa"})
|
11
|
+
(defattrs :bg-purple {:fill "#e4b5f7"})
|
12
|
+
|
13
|
+
(defn draw-group-label-header
|
14
|
+
"Creates a small borderless box used to draw the textual label headers
|
15
|
+
used below the byte labels for remotedb message diagrams.
|
16
|
+
Arguments are the number of colums to span and the text of the
|
17
|
+
label."
|
18
|
+
[span label]
|
19
|
+
(draw-box (text label [:math {:font-size 12}]) {:span span
|
20
|
+
:borders \#{}
|
21
|
+
:height 14}))
|
22
|
+
|
23
|
+
(defn draw-remotedb-header
|
24
|
+
"Generates the byte and field labels and standard header fields of a
|
25
|
+
request or response message for the remotedb database server with
|
26
|
+
the specified kind and args values."
|
27
|
+
[kind args]
|
28
|
+
(draw-column-headers)
|
29
|
+
(draw-group-label-header 5 "start")
|
30
|
+
(draw-group-label-header 5 "TxID")
|
31
|
+
(draw-group-label-header 3 "type")
|
32
|
+
(draw-group-label-header 2 "args")
|
33
|
+
(draw-group-label-header 1 "tags")
|
34
|
+
(next-row 18)
|
35
|
+
|
36
|
+
(draw-box 0x11 :bg-green)
|
37
|
+
(draw-box 0x872349ae [{:span 4} :bg-green])
|
38
|
+
(draw-box 0x11 :bg-yellow)
|
39
|
+
(draw-box (text "TxID" :math) [{:span 4} :bg-yellow])
|
40
|
+
(draw-box 0x10 :bg-pink)
|
41
|
+
(draw-box (hex-text kind 4 :bold) [{:span 2} :bg-pink])
|
42
|
+
(draw-box 0x0f :bg-cyan)
|
43
|
+
(draw-box (hex-text args 2 :bold) :bg-cyan)
|
44
|
+
(draw-box 0x14 :bg-purple)
|
45
|
+
|
46
|
+
(draw-box (text "0000000c" :hex [[:plain {:font-weight "light" :font-size 16}] " (12)"])
|
47
|
+
[{:span 4} :bg-purple])
|
48
|
+
(draw-box (hex-text 6 2 :bold) [:box-first :bg-purple])
|
49
|
+
(doseq [val [6 6 3 6 6 6 6 3]]
|
50
|
+
(draw-box (hex-text val 2 :bold) [:box-related :bg-purple]))
|
51
|
+
(doseq [val [0 0]]
|
52
|
+
(draw-box val [:box-related :bg-purple]))
|
53
|
+
(draw-box 0 [:box-last :bg-purple]))
|
54
|
+
|
55
|
+
;; Figure 48: Cue point response message.
|
56
|
+
|
57
|
+
(draw-remotedb-header 0x4702 9)
|
58
|
+
|
59
|
+
(draw-box 0x11)
|
60
|
+
(draw-box 0x2104 {:span 4})
|
61
|
+
(draw-box 0x11)
|
62
|
+
(draw-box 0 {:span 4})
|
63
|
+
(draw-box 0x11)
|
64
|
+
(draw-box (text "length" [:math] [:sub 1]) {:span 4})
|
65
|
+
(draw-box 0x14)
|
66
|
+
|
67
|
+
(draw-box (text "length" [:math] [:sub 1]) {:span 4})
|
68
|
+
(draw-gap "Cue and loop point bytes")
|
69
|
+
|
70
|
+
(draw-box nil :box-below)
|
71
|
+
(draw-box 0x11)
|
72
|
+
(draw-box 0x36 {:span 4})
|
73
|
+
(draw-box 0x11)
|
74
|
+
(draw-box (text "num" [:math] [:sub "hot"]) {:span 4})
|
75
|
+
(draw-box 0x11)
|
76
|
+
(draw-box (text "num" [:math] [:sub "cue"]) {:span 4})
|
77
|
+
|
78
|
+
(draw-box 0x11)
|
79
|
+
(draw-box (text "length" [:math] [:sub 2]) {:span 4})
|
80
|
+
(draw-box 0x14)
|
81
|
+
(draw-box (text "length" [:math] [:sub 2]) {:span 4})
|
82
|
+
(draw-gap "Unknown bytes" {:min-label-columns 6})
|
83
|
+
(draw-bottom)
|
84
|
+
eos
|
85
|
+
|
86
|
+
describe Asciidoctor::Diagram::BytefieldBlockMacroProcessor, :broken_on_travis, :broken_on_windows do
|
87
|
+
it "should generate SVG images when format is set to 'svg'" do
|
88
|
+
File.write('bytefield.txt', code)
|
89
|
+
|
90
|
+
doc = <<-eos
|
91
|
+
= Hello, Bytefield!
|
92
|
+
Doc Writer <doc@example.com>
|
93
|
+
|
94
|
+
== First Section
|
95
|
+
|
96
|
+
bytefield::bytefield.txt[format="svg"]
|
97
|
+
eos
|
98
|
+
|
99
|
+
d = load_asciidoc doc
|
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
|
+
expect(b.content_model).to eq :empty
|
106
|
+
|
107
|
+
target = b.attributes['target']
|
108
|
+
expect(target).to_not be_nil
|
109
|
+
expect(target).to match(/\.svg/)
|
110
|
+
expect(File.exist?(target)).to be true
|
111
|
+
|
112
|
+
expect(b.attributes['width']).to_not be_nil
|
113
|
+
expect(b.attributes['height']).to_not be_nil
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe Asciidoctor::Diagram::BytefieldBlockProcessor, :broken_on_travis, :broken_on_windows do
|
118
|
+
it "should generate SVG images when format is set to 'svg'" do
|
119
|
+
doc = <<-eos
|
120
|
+
= Hello, Bytefield!
|
121
|
+
Doc Writer <doc@example.com>
|
122
|
+
|
123
|
+
== First Section
|
124
|
+
|
125
|
+
[bytefield, 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, Bytefield!
|
151
|
+
Doc Writer <doc@example.com>
|
152
|
+
|
153
|
+
== First Section
|
154
|
+
|
155
|
+
[bytefield, 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('bytefield.txt', code)
|
165
|
+
|
166
|
+
doc = <<-eos
|
167
|
+
= Hello, Bytefield!
|
168
|
+
Doc Writer <doc@example.com>
|
169
|
+
|
170
|
+
== First Section
|
171
|
+
|
172
|
+
bytefield::bytefield.txt
|
173
|
+
|
174
|
+
[bytefield, format="svg"]
|
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('bytefield.txt', code)
|
197
|
+
|
198
|
+
doc = <<-eos
|
199
|
+
= Hello, Bytefield!
|
200
|
+
Doc Writer <doc@example.com>
|
201
|
+
|
202
|
+
== First Section
|
203
|
+
|
204
|
+
bytefield::bytefield.txt[]
|
205
|
+
bytefield::bytefield.txt[]
|
206
|
+
eos
|
207
|
+
|
208
|
+
load_asciidoc doc
|
209
|
+
expect(File.exist?('bytefield.svg')).to be true
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should respect target attribute in block macros" do
|
213
|
+
File.write('bytefield.txt', code)
|
214
|
+
|
215
|
+
doc = <<-eos
|
216
|
+
= Hello, Bytefield!
|
217
|
+
Doc Writer <doc@example.com>
|
218
|
+
|
219
|
+
== First Section
|
220
|
+
|
221
|
+
bytefield::bytefield.txt["foobar"]
|
222
|
+
bytefield::bytefield.txt["foobaz"]
|
223
|
+
eos
|
224
|
+
|
225
|
+
load_asciidoc doc
|
226
|
+
expect(File.exist?('foobar.svg')).to be true
|
227
|
+
expect(File.exist?('foobaz.svg')).to be true
|
228
|
+
expect(File.exist?('bytefield.svg')).to be false
|
229
|
+
end
|
230
|
+
end
|
data/spec/ditaa_spec.rb
CHANGED
@@ -253,4 +253,36 @@ Doc Writer <doc@example.com>
|
|
253
253
|
expect(b.attributes['width']).to_not be_nil
|
254
254
|
expect(b.attributes['height']).to_not be_nil
|
255
255
|
end
|
256
|
+
|
257
|
+
it "should report syntax errors" do
|
258
|
+
doc = <<-eos
|
259
|
+
= Hello, Ditaa!
|
260
|
+
Doc Writer <doc@example.com>
|
261
|
+
|
262
|
+
== First Section
|
263
|
+
|
264
|
+
[ditaa,format="svg"]
|
265
|
+
----
|
266
|
+
This should cause a bug.
|
267
|
+
|
268
|
+
// TODO:
|
269
|
+
// - don't make bugs
|
270
|
+
// - oops I wrote a comment here
|
271
|
+
|
272
|
+
+--------+ +-------+ +-------+
|
273
|
+
| | --+ ditaa +--> | |
|
274
|
+
| Text | +-------+ |diagram|
|
275
|
+
|Document| |!magic!| | |
|
276
|
+
| {d}| | | | |
|
277
|
+
+---+----+ +-------+ +-------+
|
278
|
+
: ^
|
279
|
+
| Lots of work |
|
280
|
+
+-------------------------+
|
281
|
+
----
|
282
|
+
eos
|
283
|
+
|
284
|
+
expect {
|
285
|
+
load_asciidoc doc
|
286
|
+
}.to raise_error(/Cannot follow cell/i)
|
287
|
+
end
|
256
288
|
end
|
data/spec/dpic_spec.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
code = <<-eos
|
4
|
+
arrow "$u$" above
|
5
|
+
S: circle rad 10/72.27 # 10 pt
|
6
|
+
line right 0.35
|
7
|
+
G: box "$G(s)$"
|
8
|
+
arrow "$y$" above
|
9
|
+
line -> down G.ht from last arrow then left last arrow.c.x-S.x then to S.s
|
10
|
+
"$-\;$" below rjust
|
11
|
+
eos
|
12
|
+
|
13
|
+
describe Asciidoctor::Diagram::DpicBlockMacroProcessor, :broken_on_travis, :broken_on_windows do
|
14
|
+
it "should generate SVG images when format is set to 'svg'" do
|
15
|
+
File.write('dpic.txt', code)
|
16
|
+
|
17
|
+
doc = <<-eos
|
18
|
+
= Hello, Dpic!
|
19
|
+
Doc Writer <doc@example.com>
|
20
|
+
|
21
|
+
== First Section
|
22
|
+
|
23
|
+
dpic::dpic.txt[format="svg"]
|
24
|
+
eos
|
25
|
+
|
26
|
+
d = load_asciidoc doc
|
27
|
+
expect(d).to_not be_nil
|
28
|
+
|
29
|
+
b = d.find { |bl| bl.context == :image }
|
30
|
+
expect(b).to_not be_nil
|
31
|
+
|
32
|
+
expect(b.content_model).to eq :empty
|
33
|
+
|
34
|
+
target = b.attributes['target']
|
35
|
+
expect(target).to_not be_nil
|
36
|
+
expect(target).to match(/\.svg/)
|
37
|
+
expect(File.exist?(target)).to be true
|
38
|
+
|
39
|
+
expect(b.attributes['width']).to_not be_nil
|
40
|
+
expect(b.attributes['height']).to_not be_nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe Asciidoctor::Diagram::DpicBlockProcessor, :broken_on_travis, :broken_on_windows do
|
45
|
+
it "should generate SVG images when format is set to 'svg'" do
|
46
|
+
doc = <<-eos
|
47
|
+
= Hello, Dpic!
|
48
|
+
Doc Writer <doc@example.com>
|
49
|
+
|
50
|
+
== First Section
|
51
|
+
|
52
|
+
[dpic, format="svg"]
|
53
|
+
----
|
54
|
+
#{code}
|
55
|
+
----
|
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
|
@@ -0,0 +1,478 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
code = <<-eos
|
4
|
+
plot [0:5][0:20] x**2 title 'O(n^2)'
|
5
|
+
eos
|
6
|
+
|
7
|
+
describe Asciidoctor::Diagram::GnuplotBlockMacroProcessor do
|
8
|
+
it "should generate PNG images when format is set to 'png'" do
|
9
|
+
File.write('gnuplot.txt', code)
|
10
|
+
|
11
|
+
doc = <<-eos
|
12
|
+
= Hello, Gnuplot!
|
13
|
+
Doc Writer <doc@example.com>
|
14
|
+
|
15
|
+
== First Section
|
16
|
+
|
17
|
+
gnuplot::gnuplot.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
|
+
|
37
|
+
|
38
|
+
it "should generate SVG images when format is set to 'svg'" do
|
39
|
+
File.write('gnuplot.txt', code)
|
40
|
+
|
41
|
+
doc = <<-eos
|
42
|
+
= Hello, Gnuplot!
|
43
|
+
Doc Writer <doc@example.com>
|
44
|
+
|
45
|
+
== First Section
|
46
|
+
|
47
|
+
gnuplot::gnuplot.txt[format="svg"]
|
48
|
+
eos
|
49
|
+
|
50
|
+
d = load_asciidoc doc
|
51
|
+
expect(d).to_not be_nil
|
52
|
+
|
53
|
+
b = d.find { |bl| bl.context == :image }
|
54
|
+
expect(b).to_not be_nil
|
55
|
+
|
56
|
+
expect(b.content_model).to eq :empty
|
57
|
+
|
58
|
+
target = b.attributes['target']
|
59
|
+
expect(target).to_not be_nil
|
60
|
+
expect(target).to match(/\.svg/)
|
61
|
+
expect(File.exist?(target)).to be true
|
62
|
+
|
63
|
+
expect(b.attributes['width']).to_not be_nil
|
64
|
+
expect(b.attributes['height']).to_not be_nil
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should generate GIF images when format is set to 'gif'" do
|
68
|
+
File.write('gnuplot.txt', code)
|
69
|
+
|
70
|
+
doc = <<-eos
|
71
|
+
= Hello, Gnuplot!
|
72
|
+
Doc Writer <doc@example.com>
|
73
|
+
|
74
|
+
== First Section
|
75
|
+
|
76
|
+
gnuplot::gnuplot.txt[format="gif"]
|
77
|
+
eos
|
78
|
+
|
79
|
+
d = load_asciidoc doc
|
80
|
+
expect(d).to_not be_nil
|
81
|
+
|
82
|
+
b = d.find { |bl| bl.context == :image }
|
83
|
+
expect(b).to_not be_nil
|
84
|
+
|
85
|
+
expect(b.content_model).to eq :empty
|
86
|
+
|
87
|
+
target = b.attributes['target']
|
88
|
+
expect(target).to_not be_nil
|
89
|
+
expect(target).to match(/\.gif$/)
|
90
|
+
expect(File.exist?(target)).to be true
|
91
|
+
|
92
|
+
expect(b.attributes['width']).to_not be_nil
|
93
|
+
expect(b.attributes['height']).to_not be_nil
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
it "should generate literal blocks when format is set to 'txt'" do
|
98
|
+
doc = <<-eos
|
99
|
+
= Hello, Gnuplot!
|
100
|
+
Doc Writer <doc@example.com>
|
101
|
+
|
102
|
+
== First Section
|
103
|
+
|
104
|
+
[gnuplot, format="txt"]
|
105
|
+
----
|
106
|
+
#{code}
|
107
|
+
----
|
108
|
+
eos
|
109
|
+
|
110
|
+
d = load_asciidoc doc
|
111
|
+
expect(d).to_not be_nil
|
112
|
+
|
113
|
+
b = d.find { |bl| bl.context == :literal }
|
114
|
+
expect(b).to_not be_nil
|
115
|
+
|
116
|
+
expect(b.content_model).to eq :verbatim
|
117
|
+
|
118
|
+
expect(b.attributes['target']).to be_nil
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
describe Asciidoctor::Diagram::GnuplotBlockProcessor do
|
125
|
+
it "should generate PNG images when format is set to 'png'" do
|
126
|
+
doc = <<-eos
|
127
|
+
= Hello, Gnuplot!
|
128
|
+
Doc Writer <doc@example.com>
|
129
|
+
|
130
|
+
== First Section
|
131
|
+
|
132
|
+
[gnuplot, format="png"]
|
133
|
+
----
|
134
|
+
#{code}
|
135
|
+
----
|
136
|
+
eos
|
137
|
+
|
138
|
+
d = load_asciidoc doc
|
139
|
+
expect(d).to_not be_nil
|
140
|
+
|
141
|
+
b = d.find { |bl| bl.context == :image }
|
142
|
+
expect(b).to_not be_nil
|
143
|
+
|
144
|
+
expect(b.content_model).to eq :empty
|
145
|
+
|
146
|
+
target = b.attributes['target']
|
147
|
+
expect(target).to_not be_nil
|
148
|
+
expect(target).to match(/\.png$/)
|
149
|
+
expect(File.exist?(target)).to be true
|
150
|
+
|
151
|
+
expect(b.attributes['width']).to_not be_nil
|
152
|
+
expect(b.attributes['height']).to_not be_nil
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should generate SVG images when format is set to 'svg'" do
|
156
|
+
doc = <<-eos
|
157
|
+
= Hello, Gnuplot!
|
158
|
+
Doc Writer <doc@example.com>
|
159
|
+
|
160
|
+
== First Section
|
161
|
+
|
162
|
+
[gnuplot, format="svg"]
|
163
|
+
----
|
164
|
+
#{code}
|
165
|
+
----
|
166
|
+
eos
|
167
|
+
|
168
|
+
d = load_asciidoc doc
|
169
|
+
expect(d).to_not be_nil
|
170
|
+
|
171
|
+
b = d.find { |bl| bl.context == :image }
|
172
|
+
expect(b).to_not be_nil
|
173
|
+
|
174
|
+
expect(b.content_model).to eq :empty
|
175
|
+
|
176
|
+
target = b.attributes['target']
|
177
|
+
expect(target).to_not be_nil
|
178
|
+
expect(target).to match(/\.svg/)
|
179
|
+
expect(File.exist?(target)).to be true
|
180
|
+
|
181
|
+
expect(b.attributes['width']).to_not be_nil
|
182
|
+
expect(b.attributes['height']).to_not be_nil
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should raise an error when when format is set to an invalid value" do
|
186
|
+
doc = <<-eos
|
187
|
+
= Hello, Gnuplot!
|
188
|
+
Doc Writer <doc@example.com>
|
189
|
+
|
190
|
+
== First Section
|
191
|
+
|
192
|
+
[gnuplot, format="foobar"]
|
193
|
+
----
|
194
|
+
----
|
195
|
+
eos
|
196
|
+
|
197
|
+
expect { load_asciidoc doc }.to raise_error(/support.*format/i)
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should not regenerate images when source has not changed" do
|
201
|
+
File.write('gnuplot.txt', code)
|
202
|
+
|
203
|
+
doc = <<-eos
|
204
|
+
= Hello, Gnuplot!
|
205
|
+
Doc Writer <doc@example.com>
|
206
|
+
|
207
|
+
== First Section
|
208
|
+
|
209
|
+
gnuplot::gnuplot.txt
|
210
|
+
|
211
|
+
[gnuplot, format="png"]
|
212
|
+
----
|
213
|
+
#{code}
|
214
|
+
----
|
215
|
+
eos
|
216
|
+
|
217
|
+
d = load_asciidoc doc
|
218
|
+
b = d.find { |bl| bl.context == :image }
|
219
|
+
expect(b).to_not be_nil
|
220
|
+
target = b.attributes['target']
|
221
|
+
mtime1 = File.mtime(target)
|
222
|
+
|
223
|
+
sleep 1
|
224
|
+
|
225
|
+
d = load_asciidoc doc
|
226
|
+
|
227
|
+
mtime2 = File.mtime(target)
|
228
|
+
|
229
|
+
expect(mtime2).to eq mtime1
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should handle two block macros with the same source" do
|
233
|
+
File.write('gnuplot.txt', code)
|
234
|
+
|
235
|
+
doc = <<-eos
|
236
|
+
= Hello, Gnuplot!
|
237
|
+
Doc Writer <doc@example.com>
|
238
|
+
|
239
|
+
== First Section
|
240
|
+
|
241
|
+
gnuplot::gnuplot.txt[]
|
242
|
+
gnuplot::gnuplot.txt[]
|
243
|
+
eos
|
244
|
+
|
245
|
+
load_asciidoc doc
|
246
|
+
expect(File.exist?('gnuplot.png')).to be true
|
247
|
+
end
|
248
|
+
|
249
|
+
it "should respect target attribute in block macros" do
|
250
|
+
File.write('gnuplot.txt', code)
|
251
|
+
|
252
|
+
doc = <<-eos
|
253
|
+
= Hello, Gnuplot!
|
254
|
+
Doc Writer <doc@example.com>
|
255
|
+
|
256
|
+
== First Section
|
257
|
+
|
258
|
+
gnuplot::gnuplot.txt["foobar"]
|
259
|
+
gnuplot::gnuplot.txt["foobaz"]
|
260
|
+
eos
|
261
|
+
|
262
|
+
load_asciidoc doc
|
263
|
+
expect(File.exist?('foobar.png')).to be true
|
264
|
+
expect(File.exist?('foobaz.png')).to be true
|
265
|
+
expect(File.exist?('gnuplot.png')).to be false
|
266
|
+
end
|
267
|
+
it "should generate images with user defined size" do
|
268
|
+
doc = <<-eos
|
269
|
+
= Hello, Gnuplot!
|
270
|
+
Doc Writer <doc@example.com>
|
271
|
+
|
272
|
+
== First Section
|
273
|
+
|
274
|
+
[gnuplot, format="png",width="800", height="600"]
|
275
|
+
----
|
276
|
+
#{code}
|
277
|
+
----
|
278
|
+
eos
|
279
|
+
|
280
|
+
d = load_asciidoc doc
|
281
|
+
expect(d).to_not be_nil
|
282
|
+
|
283
|
+
b = d.find { |bl| bl.context == :image }
|
284
|
+
expect(b).to_not be_nil
|
285
|
+
|
286
|
+
expect(b.content_model).to eq :empty
|
287
|
+
|
288
|
+
target = b.attributes['target']
|
289
|
+
expect(target).to_not be_nil
|
290
|
+
expect(target).to match(/\.png$/)
|
291
|
+
expect(File.exist?(target)).to be true
|
292
|
+
|
293
|
+
expect(b.attributes['width']).to_not be_nil
|
294
|
+
expect(b.attributes['height']).to_not be_nil
|
295
|
+
end
|
296
|
+
|
297
|
+
it "should generate nocrop/notrasparent images" do
|
298
|
+
doc = <<-eos
|
299
|
+
= Hello, Gnuplot!
|
300
|
+
Doc Writer <doc@example.com>
|
301
|
+
|
302
|
+
== First Section
|
303
|
+
|
304
|
+
[gnuplot, format="png", crop=false, transparent=false]
|
305
|
+
----
|
306
|
+
#{code}
|
307
|
+
----
|
308
|
+
eos
|
309
|
+
|
310
|
+
d = load_asciidoc doc
|
311
|
+
expect(d).to_not be_nil
|
312
|
+
|
313
|
+
b = d.find { |bl| bl.context == :image }
|
314
|
+
expect(b).to_not be_nil
|
315
|
+
|
316
|
+
expect(b.content_model).to eq :empty
|
317
|
+
|
318
|
+
target = b.attributes['target']
|
319
|
+
expect(target).to_not be_nil
|
320
|
+
expect(target).to match(/\.png$/)
|
321
|
+
expect(File.exist?(target)).to be true
|
322
|
+
|
323
|
+
expect(b.attributes['width']).to_not be_nil
|
324
|
+
expect(b.attributes['height']).to_not be_nil
|
325
|
+
end
|
326
|
+
|
327
|
+
it "should generate crop/trasparent images" do
|
328
|
+
doc = <<-eos
|
329
|
+
= Hello, Gnuplot!
|
330
|
+
Doc Writer <doc@example.com>
|
331
|
+
|
332
|
+
== First Section
|
333
|
+
|
334
|
+
[gnuplot, format="png", crop=true, transparent=true]
|
335
|
+
----
|
336
|
+
#{code}
|
337
|
+
----
|
338
|
+
eos
|
339
|
+
|
340
|
+
d = load_asciidoc doc
|
341
|
+
expect(d).to_not be_nil
|
342
|
+
|
343
|
+
b = d.find { |bl| bl.context == :image }
|
344
|
+
expect(b).to_not be_nil
|
345
|
+
|
346
|
+
expect(b.content_model).to eq :empty
|
347
|
+
|
348
|
+
target = b.attributes['target']
|
349
|
+
expect(target).to_not be_nil
|
350
|
+
expect(target).to match(/\.png$/)
|
351
|
+
expect(File.exist?(target)).to be true
|
352
|
+
|
353
|
+
expect(b.attributes['width']).to_not be_nil
|
354
|
+
expect(b.attributes['height']).to_not be_nil
|
355
|
+
end
|
356
|
+
|
357
|
+
it "should generate image with font name" do
|
358
|
+
doc = <<-eos
|
359
|
+
= Hello, Gnuplot!
|
360
|
+
Doc Writer <doc@example.com>
|
361
|
+
|
362
|
+
== First Section
|
363
|
+
|
364
|
+
[gnuplot, format="png", font="Arial"]
|
365
|
+
----
|
366
|
+
#{code}
|
367
|
+
----
|
368
|
+
eos
|
369
|
+
|
370
|
+
d = load_asciidoc doc
|
371
|
+
expect(d).to_not be_nil
|
372
|
+
|
373
|
+
b = d.find { |bl| bl.context == :image }
|
374
|
+
expect(b).to_not be_nil
|
375
|
+
|
376
|
+
expect(b.content_model).to eq :empty
|
377
|
+
|
378
|
+
target = b.attributes['target']
|
379
|
+
expect(target).to_not be_nil
|
380
|
+
expect(target).to match(/\.png$/)
|
381
|
+
expect(File.exist?(target)).to be true
|
382
|
+
|
383
|
+
expect(b.attributes['width']).to_not be_nil
|
384
|
+
expect(b.attributes['height']).to_not be_nil
|
385
|
+
end
|
386
|
+
|
387
|
+
it "should generate image with font name and size" do
|
388
|
+
doc = <<-eos
|
389
|
+
= Hello, Gnuplot!
|
390
|
+
Doc Writer <doc@example.com>
|
391
|
+
|
392
|
+
== First Section
|
393
|
+
|
394
|
+
[gnuplot, format="png", font="Arial,11"]
|
395
|
+
----
|
396
|
+
#{code}
|
397
|
+
----
|
398
|
+
eos
|
399
|
+
|
400
|
+
d = load_asciidoc doc
|
401
|
+
expect(d).to_not be_nil
|
402
|
+
|
403
|
+
b = d.find { |bl| bl.context == :image }
|
404
|
+
expect(b).to_not be_nil
|
405
|
+
|
406
|
+
expect(b.content_model).to eq :empty
|
407
|
+
|
408
|
+
target = b.attributes['target']
|
409
|
+
expect(target).to_not be_nil
|
410
|
+
expect(target).to match(/\.png$/)
|
411
|
+
expect(File.exist?(target)).to be true
|
412
|
+
|
413
|
+
expect(b.attributes['width']).to_not be_nil
|
414
|
+
expect(b.attributes['height']).to_not be_nil
|
415
|
+
end
|
416
|
+
|
417
|
+
it "should generate image with font name and scale" do
|
418
|
+
doc = <<-eos
|
419
|
+
= Hello, Gnuplot!
|
420
|
+
Doc Writer <doc@example.com>
|
421
|
+
|
422
|
+
== First Section
|
423
|
+
|
424
|
+
[gnuplot, format="png", font="Arial", scale="0.5"]
|
425
|
+
----
|
426
|
+
#{code}
|
427
|
+
----
|
428
|
+
eos
|
429
|
+
|
430
|
+
d = load_asciidoc doc
|
431
|
+
expect(d).to_not be_nil
|
432
|
+
|
433
|
+
b = d.find { |bl| bl.context == :image }
|
434
|
+
expect(b).to_not be_nil
|
435
|
+
|
436
|
+
expect(b.content_model).to eq :empty
|
437
|
+
|
438
|
+
target = b.attributes['target']
|
439
|
+
expect(target).to_not be_nil
|
440
|
+
expect(target).to match(/\.png$/)
|
441
|
+
expect(File.exist?(target)).to be true
|
442
|
+
|
443
|
+
expect(b.attributes['width']).to_not be_nil
|
444
|
+
expect(b.attributes['height']).to_not be_nil
|
445
|
+
end
|
446
|
+
|
447
|
+
it %(should generate image with font background="red") do
|
448
|
+
doc = <<-eos
|
449
|
+
= Hello, Gnuplot!
|
450
|
+
Doc Writer <doc@example.com>
|
451
|
+
|
452
|
+
== First Section
|
453
|
+
|
454
|
+
[gnuplot, format="png", background="red"]
|
455
|
+
----
|
456
|
+
#{code}
|
457
|
+
----
|
458
|
+
eos
|
459
|
+
|
460
|
+
d = load_asciidoc doc
|
461
|
+
expect(d).to_not be_nil
|
462
|
+
|
463
|
+
b = d.find { |bl| bl.context == :image }
|
464
|
+
expect(b).to_not be_nil
|
465
|
+
|
466
|
+
expect(b.content_model).to eq :empty
|
467
|
+
|
468
|
+
target = b.attributes['target']
|
469
|
+
expect(target).to_not be_nil
|
470
|
+
expect(target).to match(/\.png$/)
|
471
|
+
expect(File.exist?(target)).to be true
|
472
|
+
|
473
|
+
expect(b.attributes['width']).to_not be_nil
|
474
|
+
expect(b.attributes['height']).to_not be_nil
|
475
|
+
end
|
476
|
+
|
477
|
+
|
478
|
+
end
|