asciidoctor-diagram 1.2.0.preview.5-java → 1.2.1-java
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.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +17 -0
- data/lib/asciidoctor-diagram.rb +3 -1
- data/lib/asciidoctor-diagram/blockdiag.rb +15 -0
- data/lib/asciidoctor-diagram/blockdiag/extension.rb +18 -0
- data/lib/asciidoctor-diagram/ditaa/extension.rb +21 -23
- data/lib/asciidoctor-diagram/graphviz/extension.rb +7 -32
- data/lib/asciidoctor-diagram/plantuml/extension.rb +15 -31
- data/lib/asciidoctor-diagram/plantuml/generator.rb +3 -13
- data/lib/asciidoctor-diagram/shaape.rb +9 -0
- data/lib/asciidoctor-diagram/shaape/extension.rb +16 -0
- data/lib/asciidoctor-diagram/util/cli_generator.rb +40 -0
- data/lib/asciidoctor-diagram/util/diagram.rb +67 -50
- data/lib/asciidoctor-diagram/util/svg.rb +19 -23
- data/lib/asciidoctor-diagram/util/which.rb +14 -0
- data/lib/asciidoctor-diagram/version.rb +1 -1
- data/lib/plantuml.jar +0 -0
- data/spec/blockdiag_spec.rb +183 -0
- data/spec/ditaa_spec.rb +3 -3
- data/spec/graphviz_spec.rb +28 -3
- data/spec/plantuml_spec.rb +11 -11
- data/spec/shaape_spec.rb +227 -0
- data/spec/test_helper.rb +2 -0
- metadata +26 -17
- data/lib/asciidoctor-diagram/ditaa/generator.rb +0 -31
@@ -4,34 +4,30 @@ module Asciidoctor
|
|
4
4
|
module Diagram
|
5
5
|
module SVG
|
6
6
|
def self.get_image_size(data)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
if m = START_TAG_REGEX.match(data)
|
8
|
+
start_tag = m[0]
|
9
|
+
if (w = WIDTH_REGEX.match(start_tag)) && (h = HEIGHT_REGEX.match(start_tag))
|
10
|
+
width = w[:value].to_i * to_px_factor(w[:unit])
|
11
|
+
height = h[:value].to_i * to_px_factor(h[:unit])
|
12
|
+
return [width.to_i, height.to_i]
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
nil
|
15
|
+
if v = VIEWBOX_REGEX.match(start_tag)
|
16
|
+
width = v[:width]
|
17
|
+
height = v[:height]
|
18
|
+
return [width.to_i, height.to_i]
|
19
|
+
end
|
20
20
|
end
|
21
|
+
|
22
|
+
nil
|
21
23
|
end
|
22
24
|
|
23
|
-
|
25
|
+
private
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
height = match_data[:height].to_i * to_px_factor(match_data[:height_unit])
|
30
|
-
[width.to_i, height.to_i]
|
31
|
-
else
|
32
|
-
nil
|
33
|
-
end
|
34
|
-
end
|
27
|
+
START_TAG_REGEX = /<svg[^>]*>/
|
28
|
+
WIDTH_REGEX = /width="(?<value>\d+)(?<unit>[a-zA-Z]+)"/
|
29
|
+
HEIGHT_REGEX = /height="(?<value>\d+)(?<unit>[a-zA-Z]+)"/
|
30
|
+
VIEWBOX_REGEX = /viewBox="\d+ \d+ (?<width>\d+) (?<height>\d+)"/
|
35
31
|
|
36
32
|
def self.to_px_factor(unit)
|
37
33
|
case unit
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Asciidoctor
|
2
|
+
module Diagram
|
3
|
+
def self.which(cmd)
|
4
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
5
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
6
|
+
exts.each { |ext|
|
7
|
+
exe = File.join(path, "#{cmd}#{ext}")
|
8
|
+
return exe if File.executable? exe
|
9
|
+
}
|
10
|
+
end
|
11
|
+
nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/plantuml.jar
CHANGED
Binary file
|
@@ -0,0 +1,183 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
code = <<-eos
|
4
|
+
blockdiag {
|
5
|
+
A -> B -> C -> D;
|
6
|
+
A -> E -> F -> G;
|
7
|
+
}
|
8
|
+
eos
|
9
|
+
|
10
|
+
describe Asciidoctor::Diagram::BlockDiagBlockMacro do
|
11
|
+
it "should generate PNG images when format is set to 'png'" do
|
12
|
+
File.write('blockdiag.txt', code)
|
13
|
+
|
14
|
+
doc = <<-eos
|
15
|
+
= Hello, BlockDiag!
|
16
|
+
Doc Writer <doc@example.com>
|
17
|
+
|
18
|
+
== First Section
|
19
|
+
|
20
|
+
blockdiag::blockdiag.txt[format="png"]
|
21
|
+
eos
|
22
|
+
|
23
|
+
d = Asciidoctor.load StringIO.new(doc)
|
24
|
+
expect(d).to_not be_nil
|
25
|
+
|
26
|
+
b = d.find { |b| b.context == :image }
|
27
|
+
expect(b).to_not be_nil
|
28
|
+
|
29
|
+
expect(b.content_model).to eq :empty
|
30
|
+
|
31
|
+
target = b.attributes['target']
|
32
|
+
expect(target).to_not be_nil
|
33
|
+
expect(target).to match /\.png$/
|
34
|
+
expect(File.exists?(target)).to be true
|
35
|
+
|
36
|
+
expect(b.attributes['width']).to_not be_nil
|
37
|
+
expect(b.attributes['height']).to_not be_nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe Asciidoctor::Diagram::BlockDiagBlock do
|
42
|
+
it "should generate PNG images when format is set to 'png'" do
|
43
|
+
doc = <<-eos
|
44
|
+
= Hello, BlockDiag!
|
45
|
+
Doc Writer <doc@example.com>
|
46
|
+
|
47
|
+
== First Section
|
48
|
+
|
49
|
+
[blockdiag, format="png"]
|
50
|
+
----
|
51
|
+
#{code}
|
52
|
+
----
|
53
|
+
eos
|
54
|
+
|
55
|
+
d = Asciidoctor.load StringIO.new(doc)
|
56
|
+
expect(d).to_not be_nil
|
57
|
+
|
58
|
+
b = d.find { |b| b.context == :image }
|
59
|
+
expect(b).to_not be_nil
|
60
|
+
|
61
|
+
expect(b.content_model).to eq :empty
|
62
|
+
|
63
|
+
target = b.attributes['target']
|
64
|
+
expect(target).to_not be_nil
|
65
|
+
expect(target).to match /\.png$/
|
66
|
+
expect(File.exists?(target)).to be true
|
67
|
+
|
68
|
+
expect(b.attributes['width']).to_not be_nil
|
69
|
+
expect(b.attributes['height']).to_not be_nil
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should generate SVG images when format is set to 'svg'" do
|
73
|
+
doc = <<-eos
|
74
|
+
= Hello, BlockDiag!
|
75
|
+
Doc Writer <doc@example.com>
|
76
|
+
|
77
|
+
== First Section
|
78
|
+
|
79
|
+
[blockdiag, format="svg"]
|
80
|
+
----
|
81
|
+
#{code}
|
82
|
+
----
|
83
|
+
eos
|
84
|
+
|
85
|
+
d = Asciidoctor.load StringIO.new(doc)
|
86
|
+
expect(d).to_not be_nil
|
87
|
+
|
88
|
+
b = d.find { |b| b.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 /\.svg/
|
96
|
+
expect(File.exists?(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 raise an error when when format is set to an invalid value" do
|
103
|
+
doc = <<-eos
|
104
|
+
= Hello, BlockDiag!
|
105
|
+
Doc Writer <doc@example.com>
|
106
|
+
|
107
|
+
== First Section
|
108
|
+
|
109
|
+
[blockdiag, format="foobar"]
|
110
|
+
----
|
111
|
+
----
|
112
|
+
eos
|
113
|
+
|
114
|
+
expect { Asciidoctor.load StringIO.new(doc) }.to raise_error /support.*format/i
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should not regenerate images when source has not changed" do
|
118
|
+
File.write('blockdiag.txt', code)
|
119
|
+
|
120
|
+
doc = <<-eos
|
121
|
+
= Hello, BlockDiag!
|
122
|
+
Doc Writer <doc@example.com>
|
123
|
+
|
124
|
+
== First Section
|
125
|
+
|
126
|
+
blockdiag::blockdiag.txt
|
127
|
+
|
128
|
+
[blockdiag, format="png"]
|
129
|
+
----
|
130
|
+
#{code}
|
131
|
+
----
|
132
|
+
eos
|
133
|
+
|
134
|
+
d = Asciidoctor.load StringIO.new(doc)
|
135
|
+
b = d.find { |b| b.context == :image }
|
136
|
+
target = b.attributes['target']
|
137
|
+
mtime1 = File.mtime(target)
|
138
|
+
|
139
|
+
sleep 1
|
140
|
+
|
141
|
+
d = Asciidoctor.load StringIO.new(doc)
|
142
|
+
|
143
|
+
mtime2 = File.mtime(target)
|
144
|
+
|
145
|
+
expect(mtime2).to eq mtime1
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should handle two block macros with the same source" do
|
149
|
+
File.write('blockdiag.txt', code)
|
150
|
+
|
151
|
+
doc = <<-eos
|
152
|
+
= Hello, BlockDiag!
|
153
|
+
Doc Writer <doc@example.com>
|
154
|
+
|
155
|
+
== First Section
|
156
|
+
|
157
|
+
blockdiag::blockdiag.txt[]
|
158
|
+
blockdiag::blockdiag.txt[]
|
159
|
+
eos
|
160
|
+
|
161
|
+
Asciidoctor.load StringIO.new(doc)
|
162
|
+
expect(File.exists?('blockdiag.png')).to be true
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should respect target attribute in block macros" do
|
166
|
+
File.write('blockdiag.txt', code)
|
167
|
+
|
168
|
+
doc = <<-eos
|
169
|
+
= Hello, BlockDiag!
|
170
|
+
Doc Writer <doc@example.com>
|
171
|
+
|
172
|
+
== First Section
|
173
|
+
|
174
|
+
blockdiag::blockdiag.txt["foobar"]
|
175
|
+
blockdiag::blockdiag.txt["foobaz"]
|
176
|
+
eos
|
177
|
+
|
178
|
+
Asciidoctor.load StringIO.new(doc)
|
179
|
+
expect(File.exists?('foobar.png')).to be true
|
180
|
+
expect(File.exists?('foobaz.png')).to be true
|
181
|
+
expect(File.exists?('blockdiag.png')).to be false
|
182
|
+
end
|
183
|
+
end
|
data/spec/ditaa_spec.rb
CHANGED
@@ -36,7 +36,7 @@ ditaa::ditaa.txt[format="png"]
|
|
36
36
|
target = b.attributes['target']
|
37
37
|
expect(target).to_not be_nil
|
38
38
|
expect(target).to match /\.png$/
|
39
|
-
expect(File.exists?(target)).to
|
39
|
+
expect(File.exists?(target)).to be true
|
40
40
|
|
41
41
|
expect(b.attributes['width']).to_not be_nil
|
42
42
|
expect(b.attributes['height']).to_not be_nil
|
@@ -76,7 +76,7 @@ Doc Writer <doc@example.com>
|
|
76
76
|
target = b.attributes['target']
|
77
77
|
expect(target).to_not be_nil
|
78
78
|
expect(target).to match /\.png$/
|
79
|
-
expect(File.exists?(target)).to
|
79
|
+
expect(File.exists?(target)).to be true
|
80
80
|
|
81
81
|
expect(b.attributes['width']).to_not be_nil
|
82
82
|
expect(b.attributes['height']).to_not be_nil
|
@@ -116,6 +116,6 @@ Doc Writer <doc@example.com>
|
|
116
116
|
expect(b).to_not be_nil
|
117
117
|
target = b.attributes['target']
|
118
118
|
expect(target).to match /\.png$/
|
119
|
-
expect(File.exists?(target)).to
|
119
|
+
expect(File.exists?(target)).to be true
|
120
120
|
end
|
121
121
|
end
|
data/spec/graphviz_spec.rb
CHANGED
@@ -35,7 +35,7 @@ graphviz::graphviz.txt[format="png"]
|
|
35
35
|
target = b.attributes['target']
|
36
36
|
expect(target).to_not be_nil
|
37
37
|
expect(target).to match /\.png$/
|
38
|
-
expect(File.exists?(target)).to
|
38
|
+
expect(File.exists?(target)).to be true
|
39
39
|
|
40
40
|
expect(b.attributes['width']).to_not be_nil
|
41
41
|
expect(b.attributes['height']).to_not be_nil
|
@@ -74,7 +74,7 @@ digraph foo {
|
|
74
74
|
target = b.attributes['target']
|
75
75
|
expect(target).to_not be_nil
|
76
76
|
expect(target).to match /\.png$/
|
77
|
-
expect(File.exists?(target)).to
|
77
|
+
expect(File.exists?(target)).to be true
|
78
78
|
|
79
79
|
expect(b.attributes['width']).to_not be_nil
|
80
80
|
expect(b.attributes['height']).to_not be_nil
|
@@ -111,7 +111,7 @@ digraph foo {
|
|
111
111
|
target = b.attributes['target']
|
112
112
|
expect(target).to_not be_nil
|
113
113
|
expect(target).to match /\.svg$/
|
114
|
-
expect(File.exists?(target)).to
|
114
|
+
expect(File.exists?(target)).to be true
|
115
115
|
|
116
116
|
expect(b.attributes['width']).to_not be_nil
|
117
117
|
expect(b.attributes['height']).to_not be_nil
|
@@ -131,4 +131,29 @@ Doc Writer <doc@example.com>
|
|
131
131
|
|
132
132
|
expect { Asciidoctor.load StringIO.new(doc) }.to raise_error /support.*format/i
|
133
133
|
end
|
134
|
+
|
135
|
+
it "should support single line digraphs" do
|
136
|
+
doc = <<-eos
|
137
|
+
= Hello, graphviz!
|
138
|
+
Doc Writer <doc@example.com>
|
139
|
+
|
140
|
+
== First Section
|
141
|
+
|
142
|
+
[graphviz]
|
143
|
+
----
|
144
|
+
digraph g { rankdir=LR; Text->Graphviz->Image }
|
145
|
+
----
|
146
|
+
eos
|
147
|
+
|
148
|
+
d = Asciidoctor.load StringIO.new(doc)
|
149
|
+
expect(d).to_not be_nil
|
150
|
+
|
151
|
+
b = d.find { |b| b.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.exists?(target)).to be true
|
158
|
+
end
|
134
159
|
end
|
data/spec/plantuml_spec.rb
CHANGED
@@ -31,7 +31,7 @@ plantuml::plantuml.txt[format="png"]
|
|
31
31
|
target = b.attributes['target']
|
32
32
|
expect(target).to_not be_nil
|
33
33
|
expect(target).to match /\.png$/
|
34
|
-
expect(File.exists?(target)).to
|
34
|
+
expect(File.exists?(target)).to be true
|
35
35
|
|
36
36
|
expect(b.attributes['width']).to_not be_nil
|
37
37
|
expect(b.attributes['height']).to_not be_nil
|
@@ -66,7 +66,7 @@ User --> (Use the application) : Label
|
|
66
66
|
target = b.attributes['target']
|
67
67
|
expect(target).to_not be_nil
|
68
68
|
expect(target).to match /\.png$/
|
69
|
-
expect(File.exists?(target)).to
|
69
|
+
expect(File.exists?(target)).to be true
|
70
70
|
|
71
71
|
expect(b.attributes['width']).to_not be_nil
|
72
72
|
expect(b.attributes['height']).to_not be_nil
|
@@ -99,7 +99,7 @@ User --> (Use the application) : Label
|
|
99
99
|
target = b.attributes['target']
|
100
100
|
expect(target).to_not be_nil
|
101
101
|
expect(target).to match /\.svg/
|
102
|
-
expect(File.exists?(target)).to
|
102
|
+
expect(File.exists?(target)).to be true
|
103
103
|
|
104
104
|
expect(b.attributes['width']).to_not be_nil
|
105
105
|
expect(b.attributes['height']).to_not be_nil
|
@@ -176,7 +176,7 @@ ArrowColor #DEADBE
|
|
176
176
|
|
177
177
|
target = b.attributes['target']
|
178
178
|
expect(target).to_not be_nil
|
179
|
-
expect(File.exists?(target)).to
|
179
|
+
expect(File.exists?(target)).to be true
|
180
180
|
|
181
181
|
svg = File.read(target)
|
182
182
|
expect(svg).to match /<path.*fill="#DEADBE"/
|
@@ -243,7 +243,7 @@ plantuml::plantuml.txt[]
|
|
243
243
|
eos
|
244
244
|
|
245
245
|
Asciidoctor.load StringIO.new(doc)
|
246
|
-
expect(File.exists?('plantuml.png')).to
|
246
|
+
expect(File.exists?('plantuml.png')).to be true
|
247
247
|
end
|
248
248
|
|
249
249
|
it "should respect target attribute in block macros" do
|
@@ -267,9 +267,9 @@ plantuml::plantuml.txt["foobaz"]
|
|
267
267
|
eos
|
268
268
|
|
269
269
|
Asciidoctor.load StringIO.new(doc)
|
270
|
-
expect(File.exists?('foobar.png')).to
|
271
|
-
expect(File.exists?('foobaz.png')).to
|
272
|
-
expect(File.exists?('plantuml.png')).to
|
270
|
+
expect(File.exists?('foobar.png')).to be true
|
271
|
+
expect(File.exists?('foobaz.png')).to be true
|
272
|
+
expect(File.exists?('plantuml.png')).to be false
|
273
273
|
end
|
274
274
|
|
275
275
|
|
@@ -293,8 +293,8 @@ Foo1 -> Foo2 : To boundary
|
|
293
293
|
|
294
294
|
target = b.attributes['target']
|
295
295
|
expect(target).to_not be_nil
|
296
|
-
expect(File.exists?(target)).to
|
297
|
-
expect(File.exists?(File.expand_path(target, 'foo'))).to
|
296
|
+
expect(File.exists?(target)).to be false
|
297
|
+
expect(File.exists?(File.expand_path(target, 'foo'))).to be true
|
298
298
|
end
|
299
299
|
|
300
300
|
it "should omit width/height attributes when generating docbook" do
|
@@ -317,7 +317,7 @@ User -> (Start)
|
|
317
317
|
expect(b).to_not be_nil
|
318
318
|
|
319
319
|
target = b.attributes['target']
|
320
|
-
expect(File.exists?(target)).to
|
320
|
+
expect(File.exists?(target)).to be true
|
321
321
|
|
322
322
|
expect(b.attributes['width']).to be_nil
|
323
323
|
expect(b.attributes['height']).to be_nil
|
data/spec/shaape_spec.rb
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
describe Asciidoctor::Diagram::ShaapeBlockMacro 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 = Asciidoctor.load StringIO.new(doc)
|
26
|
+
expect(d).to_not be_nil
|
27
|
+
|
28
|
+
b = d.find { |b| b.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.exists?(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
|
41
|
+
end
|
42
|
+
|
43
|
+
describe Asciidoctor::Diagram::ShaapeBlock 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 = Asciidoctor.load StringIO.new(doc)
|
63
|
+
expect(d).to_not be_nil
|
64
|
+
|
65
|
+
b = d.find { |b| b.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.exists?(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 = Asciidoctor.load StringIO.new(doc)
|
98
|
+
expect(d).to_not be_nil
|
99
|
+
|
100
|
+
b = d.find { |b| b.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.exists?(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 { Asciidoctor.load StringIO.new(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 = Asciidoctor.load StringIO.new(doc)
|
161
|
+
b = d.find { |b| b.context == :image }
|
162
|
+
target = b.attributes['target']
|
163
|
+
mtime1 = File.mtime(target)
|
164
|
+
|
165
|
+
sleep 1
|
166
|
+
|
167
|
+
d = Asciidoctor.load StringIO.new(doc)
|
168
|
+
|
169
|
+
mtime2 = File.mtime(target)
|
170
|
+
|
171
|
+
expect(mtime2).to eq mtime1
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should handle two block macros with the same source" do
|
175
|
+
code = <<-eos
|
176
|
+
+--------+ +-------------+
|
177
|
+
| | \\ /
|
178
|
+
| Hello |---> \\ Goodbye /
|
179
|
+
| ;) | / \\
|
180
|
+
| | / \\
|
181
|
+
+--------+ +-------------+
|
182
|
+
eos
|
183
|
+
|
184
|
+
File.write('shaape.txt', code)
|
185
|
+
|
186
|
+
doc = <<-eos
|
187
|
+
= Hello, Shaape!
|
188
|
+
Doc Writer <doc@example.com>
|
189
|
+
|
190
|
+
== First Section
|
191
|
+
|
192
|
+
shaape::shaape.txt[]
|
193
|
+
shaape::shaape.txt[]
|
194
|
+
eos
|
195
|
+
|
196
|
+
Asciidoctor.load StringIO.new(doc)
|
197
|
+
expect(File.exists?('shaape.png')).to be true
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should respect target attribute in block macros" do
|
201
|
+
code = <<-eos
|
202
|
+
+--------+ +-------------+
|
203
|
+
| | \\ /
|
204
|
+
| Hello |---> \\ Goodbye /
|
205
|
+
| ;) | / \\
|
206
|
+
| | / \\
|
207
|
+
+--------+ +-------------+
|
208
|
+
eos
|
209
|
+
|
210
|
+
File.write('shaape.txt', code)
|
211
|
+
|
212
|
+
doc = <<-eos
|
213
|
+
= Hello, Shaape!
|
214
|
+
Doc Writer <doc@example.com>
|
215
|
+
|
216
|
+
== First Section
|
217
|
+
|
218
|
+
shaape::shaape.txt["foobar"]
|
219
|
+
shaape::shaape.txt["foobaz"]
|
220
|
+
eos
|
221
|
+
|
222
|
+
Asciidoctor.load StringIO.new(doc)
|
223
|
+
expect(File.exists?('foobar.png')).to be true
|
224
|
+
expect(File.exists?('foobaz.png')).to be true
|
225
|
+
expect(File.exists?('shaape.png')).to be false
|
226
|
+
end
|
227
|
+
end
|