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