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
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative '../diagram_processor'
|
2
|
+
require_relative 'converter'
|
3
|
+
|
4
|
+
module Asciidoctor
|
5
|
+
module Diagram
|
6
|
+
class SymbolatorBlockProcessor < DiagramBlockProcessor
|
7
|
+
use_converter SymbolatorConverter
|
8
|
+
end
|
9
|
+
|
10
|
+
class SymbolatorBlockMacroProcessor < DiagramBlockMacroProcessor
|
11
|
+
use_converter SymbolatorConverter
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -14,16 +14,15 @@ module Asciidoctor
|
|
14
14
|
[:png, :svg]
|
15
15
|
end
|
16
16
|
|
17
|
-
def collect_options(source
|
17
|
+
def collect_options(source)
|
18
18
|
{
|
19
|
-
:heading => source.attr('heading'
|
20
|
-
:scale => source.attr('scale'
|
21
|
-
:transparent => source.attr('transparent'
|
22
|
-
:style => source.attr('style'
|
19
|
+
:heading => source.attr('heading'),
|
20
|
+
:scale => source.attr('scale'),
|
21
|
+
:transparent => source.attr('transparent'),
|
22
|
+
:style => source.attr('style')
|
23
23
|
}
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
26
|
def convert(source, format, options)
|
28
27
|
generate_file(source.find_command('syntrax'), 'spec', format.to_s, source.to_s) do |tool_path, input_path, output_path|
|
29
28
|
args = [tool_path, '-i', Platform.native_path(input_path), '-o', Platform.native_path(output_path)]
|
@@ -50,6 +49,10 @@ module Asciidoctor
|
|
50
49
|
args
|
51
50
|
end
|
52
51
|
end
|
52
|
+
|
53
|
+
def native_scaling?
|
54
|
+
true
|
55
|
+
end
|
53
56
|
end
|
54
57
|
end
|
55
58
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'asciidoctor/logging'
|
1
2
|
require 'tempfile'
|
2
3
|
require_relative 'cli'
|
3
4
|
|
@@ -5,6 +6,8 @@ module Asciidoctor
|
|
5
6
|
module Diagram
|
6
7
|
# @private
|
7
8
|
module CliGenerator
|
9
|
+
include Asciidoctor::Logging
|
10
|
+
|
8
11
|
def generate_stdin(tool, format, code)
|
9
12
|
tool_name = File.basename(tool)
|
10
13
|
|
@@ -51,6 +54,20 @@ module Asciidoctor
|
|
51
54
|
end
|
52
55
|
end
|
53
56
|
|
57
|
+
def generate_file_stdout(tool, input_ext, code)
|
58
|
+
tool_name = File.basename(tool)
|
59
|
+
|
60
|
+
source_file = Tempfile.new([tool_name, ".#{input_ext}"])
|
61
|
+
begin
|
62
|
+
File.write(source_file.path, code)
|
63
|
+
|
64
|
+
opts = yield tool, source_file.path
|
65
|
+
generate(opts, :stdout)
|
66
|
+
ensure
|
67
|
+
source_file.unlink
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
54
71
|
private
|
55
72
|
def generate(opts, target_file, open3_opts = {})
|
56
73
|
case opts
|
@@ -64,6 +81,7 @@ module Asciidoctor
|
|
64
81
|
raise "Block passed to generate_file should return an Array or a Hash"
|
65
82
|
end
|
66
83
|
|
84
|
+
logger.debug "Executing #{args} with options #{open3_opts}"
|
67
85
|
result = ::Asciidoctor::Diagram::Cli.run(*args, open3_opts)
|
68
86
|
|
69
87
|
data = target_file == :stdout ? result[:out] : read_result(target_file, out_file)
|
@@ -7,14 +7,14 @@ module Asciidoctor
|
|
7
7
|
GIF87A_SIGNATURE = 'GIF87a'.force_encoding(Encoding::ASCII_8BIT)
|
8
8
|
GIF89A_SIGNATURE = 'GIF89a'.force_encoding(Encoding::ASCII_8BIT)
|
9
9
|
|
10
|
-
def self.
|
10
|
+
def self.post_process_image(data)
|
11
11
|
bio = BinaryIO.new(data)
|
12
12
|
gif_signature = bio.read_string(6)
|
13
13
|
raise "Invalid GIF signature" unless gif_signature == GIF87A_SIGNATURE || gif_signature == GIF89A_SIGNATURE
|
14
14
|
|
15
15
|
width = bio.read_uint16_le
|
16
16
|
height = bio.read_uint16_le
|
17
|
-
[width, height]
|
17
|
+
[data, width, height]
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -6,7 +6,7 @@ module Asciidoctor
|
|
6
6
|
module PNG
|
7
7
|
PNG_SIGNATURE = [137, 80, 78, 71, 13, 10, 26, 10].pack('CCCCCCCC')
|
8
8
|
|
9
|
-
def self.
|
9
|
+
def self.post_process_image(data)
|
10
10
|
bio = BinaryIO.new(data)
|
11
11
|
png_signature = bio.read_string(8)
|
12
12
|
raise "Invalid PNG signature" unless png_signature == PNG_SIGNATURE
|
@@ -18,7 +18,7 @@ module Asciidoctor
|
|
18
18
|
|
19
19
|
width = bio.read_uint32_be
|
20
20
|
height = bio.read_uint32_be
|
21
|
-
[width, height]
|
21
|
+
[data, width, height]
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -1,34 +1,61 @@
|
|
1
1
|
require_relative 'binaryio'
|
2
|
+
require 'rexml/document'
|
3
|
+
require 'bigdecimal'
|
4
|
+
require 'bigdecimal/util'
|
2
5
|
|
3
6
|
module Asciidoctor
|
4
7
|
module Diagram
|
5
8
|
# @private
|
6
9
|
module SVG
|
7
|
-
def self.
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
height = v[:height]
|
19
|
-
return [width.to_i, height.to_i]
|
20
|
-
end
|
10
|
+
def self.post_process_image(data)
|
11
|
+
svg = REXML::Document.new(data)
|
12
|
+
|
13
|
+
root = svg.root
|
14
|
+
|
15
|
+
unless root.attributes['xmlns']
|
16
|
+
root.add_attribute('xmlns', 'http://www.w3.org/2000/svg')
|
17
|
+
end
|
18
|
+
|
19
|
+
unless root.attributes['preserveAspectRatio']
|
20
|
+
root.add_attribute('preserveAspectRatio', 'xMidYMid meet')
|
21
21
|
end
|
22
22
|
|
23
|
-
nil
|
23
|
+
width = nil
|
24
|
+
height = nil
|
25
|
+
|
26
|
+
if (w = WIDTH_HEIGHT_REGEX.match(root.attributes['width'])) && (h = WIDTH_HEIGHT_REGEX.match(root.attributes['height']))
|
27
|
+
width = to_numeric(w[:value]) * to_px_factor(w[:unit])
|
28
|
+
height = to_numeric(h[:value]) * to_px_factor(h[:unit])
|
29
|
+
end
|
30
|
+
|
31
|
+
viewbox = root.attributes['viewBox']
|
32
|
+
if (v = VIEWBOX_REGEX.match(viewbox)) && width.nil? && height.nil?
|
33
|
+
width = to_numeric(v[:width])
|
34
|
+
height = to_numeric(v[:height])
|
35
|
+
end
|
36
|
+
|
37
|
+
if viewbox.nil? && width && height
|
38
|
+
root.add_attribute('viewBox', "0 0 #{width.to_s} #{height.to_s}")
|
39
|
+
end
|
40
|
+
|
41
|
+
patched_svg = ""
|
42
|
+
svg.write(:output => patched_svg, :indent => 2)
|
43
|
+
|
44
|
+
[patched_svg, width, height]
|
24
45
|
end
|
25
46
|
|
26
47
|
private
|
27
48
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
49
|
+
def self.to_numeric(text)
|
50
|
+
if text.include? '.'
|
51
|
+
text.to_f
|
52
|
+
else
|
53
|
+
text.to_i
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
WIDTH_HEIGHT_REGEX = /^\s*(?<value>\d+(?:\.\d+)?)\s*(?<unit>[a-zA-Z]+)?\s*$/
|
58
|
+
VIEWBOX_REGEX = /^\s*\d+(?:\.\d+)?\s*\d+(?:\.\d+)?\s*(?<width>\d+(?:\.\d+)?)\s*(?<height>\d+(?:\.\d+)?)\s*$/
|
32
59
|
|
33
60
|
def self.to_px_factor(unit)
|
34
61
|
case unit
|
@@ -15,9 +15,9 @@ module Asciidoctor
|
|
15
15
|
end
|
16
16
|
|
17
17
|
|
18
|
-
def collect_options(source
|
18
|
+
def collect_options(source)
|
19
19
|
{
|
20
|
-
:vegalite =>
|
20
|
+
:vegalite => source.diagram_type.to_s.include?('lite') || source.attr('vegalite')
|
21
21
|
}
|
22
22
|
end
|
23
23
|
|
data/spec/a2s_spec.rb
CHANGED
@@ -21,147 +21,9 @@ code = <<-eos
|
|
21
21
|
eos
|
22
22
|
|
23
23
|
describe Asciidoctor::Diagram::AsciiToSvgBlockMacroProcessor, :broken_on_travis, :broken_on_windows do
|
24
|
-
|
25
|
-
File.write('a2s.txt', code)
|
26
|
-
|
27
|
-
doc = <<-eos
|
28
|
-
= Hello, a2s!
|
29
|
-
Doc Writer <doc@example.com>
|
30
|
-
|
31
|
-
== First Section
|
32
|
-
|
33
|
-
a2s::a2s.txt[format="svg"]
|
34
|
-
eos
|
35
|
-
|
36
|
-
d = load_asciidoc doc
|
37
|
-
expect(d).to_not be_nil
|
38
|
-
|
39
|
-
b = d.find { |bl| bl.context == :image }
|
40
|
-
expect(b).to_not be_nil
|
41
|
-
|
42
|
-
expect(b.content_model).to eq :empty
|
43
|
-
|
44
|
-
target = b.attributes['target']
|
45
|
-
expect(target).to_not be_nil
|
46
|
-
expect(target).to match(/\.svg/)
|
47
|
-
expect(File.exist?(target)).to be true
|
48
|
-
|
49
|
-
expect(b.attributes['width']).to_not be_nil
|
50
|
-
expect(b.attributes['height']).to_not be_nil
|
51
|
-
end
|
24
|
+
include_examples "block_macro", :a2s, code, [:svg]
|
52
25
|
end
|
53
26
|
|
54
27
|
describe Asciidoctor::Diagram::AsciiToSvgBlockProcessor, :broken_on_travis, :broken_on_windows do
|
55
|
-
|
56
|
-
doc = <<-eos
|
57
|
-
= Hello, a2s!
|
58
|
-
Doc Writer <doc@example.com>
|
59
|
-
|
60
|
-
== First Section
|
61
|
-
|
62
|
-
[a2s, format="svg"]
|
63
|
-
----
|
64
|
-
#{code}
|
65
|
-
----
|
66
|
-
eos
|
67
|
-
|
68
|
-
d = load_asciidoc doc
|
69
|
-
expect(d).to_not be_nil
|
70
|
-
|
71
|
-
b = d.find { |bl| bl.context == :image }
|
72
|
-
expect(b).to_not be_nil
|
73
|
-
|
74
|
-
expect(b.content_model).to eq :empty
|
75
|
-
|
76
|
-
target = b.attributes['target']
|
77
|
-
expect(target).to_not be_nil
|
78
|
-
expect(target).to match(/\.svg/)
|
79
|
-
expect(File.exist?(target)).to be true
|
80
|
-
|
81
|
-
expect(b.attributes['width']).to_not be_nil
|
82
|
-
expect(b.attributes['height']).to_not be_nil
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should raise an error when when format is set to an invalid value" do
|
86
|
-
doc = <<-eos
|
87
|
-
= Hello, a2s!
|
88
|
-
Doc Writer <doc@example.com>
|
89
|
-
|
90
|
-
== First Section
|
91
|
-
|
92
|
-
[a2s, format="foobar"]
|
93
|
-
----
|
94
|
-
----
|
95
|
-
eos
|
96
|
-
|
97
|
-
expect { load_asciidoc doc }.to raise_error(/support.*format/i)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should not regenerate images when source has not changed" do
|
101
|
-
File.write('a2s.txt', code)
|
102
|
-
|
103
|
-
doc = <<-eos
|
104
|
-
= Hello, a2s!
|
105
|
-
Doc Writer <doc@example.com>
|
106
|
-
|
107
|
-
== First Section
|
108
|
-
|
109
|
-
a2s::a2s.txt
|
110
|
-
|
111
|
-
[a2s]
|
112
|
-
----
|
113
|
-
#{code}
|
114
|
-
----
|
115
|
-
eos
|
116
|
-
|
117
|
-
d = load_asciidoc doc
|
118
|
-
b = d.find { |bl| bl.context == :image }
|
119
|
-
expect(b).to_not be_nil
|
120
|
-
target = b.attributes['target']
|
121
|
-
mtime1 = File.mtime(target)
|
122
|
-
|
123
|
-
sleep 1
|
124
|
-
|
125
|
-
d = load_asciidoc doc
|
126
|
-
|
127
|
-
mtime2 = File.mtime(target)
|
128
|
-
|
129
|
-
expect(mtime2).to eq mtime1
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should handle two block macros with the same source" do
|
133
|
-
File.write('a2s.txt', code)
|
134
|
-
|
135
|
-
doc = <<-eos
|
136
|
-
= Hello, a2s!
|
137
|
-
Doc Writer <doc@example.com>
|
138
|
-
|
139
|
-
== First Section
|
140
|
-
|
141
|
-
a2s::a2s.txt[]
|
142
|
-
a2s::a2s.txt[]
|
143
|
-
eos
|
144
|
-
|
145
|
-
load_asciidoc doc
|
146
|
-
expect(File.exist?('a2s.svg')).to be true
|
147
|
-
end
|
148
|
-
|
149
|
-
it "should respect target attribute in block macros" do
|
150
|
-
File.write('a2s.txt', code)
|
151
|
-
|
152
|
-
doc = <<-eos
|
153
|
-
= Hello, a2s!
|
154
|
-
Doc Writer <doc@example.com>
|
155
|
-
|
156
|
-
== First Section
|
157
|
-
|
158
|
-
a2s::a2s.txt["foobar"]
|
159
|
-
a2s::a2s.txt["foobaz"]
|
160
|
-
eos
|
161
|
-
|
162
|
-
load_asciidoc doc
|
163
|
-
expect(File.exist?('foobar.svg')).to be true
|
164
|
-
expect(File.exist?('foobaz.svg')).to be true
|
165
|
-
expect(File.exist?('a2s.svg')).to be false
|
166
|
-
end
|
28
|
+
include_examples "block", :svgbob, code, [:svg]
|
167
29
|
end
|
data/spec/blockdiag_spec.rb
CHANGED
@@ -8,207 +8,9 @@ blockdiag {
|
|
8
8
|
eos
|
9
9
|
|
10
10
|
describe Asciidoctor::Diagram::BlockDiagBlockMacroProcessor, :broken_on_appveyor do
|
11
|
-
|
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 = load_asciidoc doc
|
24
|
-
expect(d).to_not be_nil
|
25
|
-
|
26
|
-
b = d.find { |bl| bl.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.exist?(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
|
11
|
+
include_examples "block_macro", :blockdiag, code, [:png, :svg, :pdf]
|
39
12
|
end
|
40
13
|
|
41
14
|
describe Asciidoctor::Diagram::BlockDiagBlockProcessor, :broken_on_appveyor do
|
42
|
-
|
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 = load_asciidoc doc
|
56
|
-
expect(d).to_not be_nil
|
57
|
-
|
58
|
-
b = d.find { |bl| bl.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.exist?(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 = 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(/\.svg/)
|
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 PDF files when format is set to 'pdf'" do
|
103
|
-
doc = <<-eos
|
104
|
-
= Hello, BlockDiag!
|
105
|
-
Doc Writer <doc@example.com>
|
106
|
-
|
107
|
-
== First Section
|
108
|
-
|
109
|
-
[blockdiag, format="pdf"]
|
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(/\.pdf/)
|
126
|
-
expect(File.exist?(target)).to be true
|
127
|
-
|
128
|
-
expect(b.attributes['width']).to be_nil
|
129
|
-
expect(b.attributes['height']).to 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, BlockDiag!
|
135
|
-
Doc Writer <doc@example.com>
|
136
|
-
|
137
|
-
== First Section
|
138
|
-
|
139
|
-
[blockdiag, 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('blockdiag.txt', code)
|
149
|
-
|
150
|
-
doc = <<-eos
|
151
|
-
= Hello, BlockDiag!
|
152
|
-
Doc Writer <doc@example.com>
|
153
|
-
|
154
|
-
== First Section
|
155
|
-
|
156
|
-
blockdiag::blockdiag.txt
|
157
|
-
|
158
|
-
[blockdiag, 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('blockdiag.txt', code)
|
181
|
-
|
182
|
-
doc = <<-eos
|
183
|
-
= Hello, BlockDiag!
|
184
|
-
Doc Writer <doc@example.com>
|
185
|
-
|
186
|
-
== First Section
|
187
|
-
|
188
|
-
blockdiag::blockdiag.txt[]
|
189
|
-
blockdiag::blockdiag.txt[]
|
190
|
-
eos
|
191
|
-
|
192
|
-
load_asciidoc doc
|
193
|
-
expect(File.exist?('blockdiag.png')).to be true
|
194
|
-
end
|
195
|
-
|
196
|
-
it "should respect target attribute in block macros" do
|
197
|
-
File.write('blockdiag.txt', code)
|
198
|
-
|
199
|
-
doc = <<-eos
|
200
|
-
= Hello, BlockDiag!
|
201
|
-
Doc Writer <doc@example.com>
|
202
|
-
|
203
|
-
== First Section
|
204
|
-
|
205
|
-
blockdiag::blockdiag.txt["foobar"]
|
206
|
-
blockdiag::blockdiag.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?('blockdiag.png')).to be false
|
213
|
-
end
|
15
|
+
include_examples "block", :blockdiag, code, [:png, :svg, :pdf]
|
214
16
|
end
|