asciidoctor-diagram 1.1.6 → 1.2.0.preview.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
-
4
- require 'asciidoctor'
5
- require 'asciidoctor/cli/options'
6
- require 'asciidoctor/cli/invoker'
7
- require 'asciidoctor-diagram'
8
-
9
- Asciidoctor::Cli::Invoker.new(*ARGV).invoke!
@@ -1,8 +0,0 @@
1
- require 'asciidoctor/extensions'
2
- require_relative 'version'
3
-
4
- Asciidoctor::Extensions.register do
5
- require_relative 'blockdiag/extension'
6
- block :blockdiag, Asciidoctor::Diagram::BlockDiagBlock
7
- block_macro :blockdiag, Asciidoctor::Diagram::BlockDiagBlockMacro
8
- end
@@ -1,18 +0,0 @@
1
- require_relative '../util/cli_generator'
2
- require_relative '../util/diagram'
3
-
4
- module Asciidoctor
5
- module Diagram
6
- ['BlockDiag', 'SeqDiag', 'ActDiag', 'NwDiag', 'RackDiag', 'PacketDiag'].each do |tool|
7
- DiagramProcessor.define_processors(tool) do
8
- [:png, :svg].each do |f|
9
- register_format(f, :image) do |c, p|
10
- CliGenerator.generate(tool.downcase, p, c) do |tool_path, output_path|
11
- [tool_path, '-o', output_path, "-T#{f.to_s}", '-']
12
- end
13
- end
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,8 +0,0 @@
1
- require 'asciidoctor/extensions'
2
- require_relative 'version'
3
-
4
- Asciidoctor::Extensions.register do
5
- require_relative 'shaape/extension'
6
- block :shaape, Asciidoctor::Diagram::ShaapeBlock
7
- block_macro :shaape, Asciidoctor::Diagram::ShaapeBlockMacro
8
- end
@@ -1,16 +0,0 @@
1
- require_relative '../util/cli_generator'
2
- require_relative '../util/diagram'
3
-
4
- module Asciidoctor
5
- module Diagram
6
- DiagramProcessor.define_processors('Shaape') do
7
- [:png, :svg].each do |f|
8
- register_format(f, :image) do |c, p|
9
- CliGenerator.generate('shaape', p, c) do |tool_path, output_path|
10
- [tool_path, '-o', output_path, '-t', f.to_s, '-']
11
- end
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,40 +0,0 @@
1
- require 'tempfile'
2
-
3
- require_relative '../util/java'
4
- require_relative '../util/which'
5
-
6
- module Asciidoctor
7
- module Diagram
8
- module CliGenerator
9
- def self.generate(tool, parent, code)
10
- tool_var = '@' + tool
11
-
12
- tool_path = instance_variable_get(tool_var)
13
- unless tool_path
14
- tool_path = parent.document.attributes[tool]
15
- tool_path = ::Asciidoctor::Diagram.which(tool) unless tool_path && File.executable?(tool_path)
16
- raise "Could not find the '#{tool}' executable in PATH; add it to the PATH or specify its location using the 'shaape' document attribute" unless tool_path
17
- instance_variable_set(tool_var, tool_path)
18
- end
19
-
20
- target_file = Tempfile.new(tool)
21
- begin
22
- target_file.close
23
-
24
- args = yield tool_path, target_file.path
25
-
26
- IO.popen(args, "w") do |io|
27
- io.write code
28
- end
29
- result_code = $?
30
-
31
- raise "#{tool} image generation failed" unless result_code == 0
32
-
33
- File.read(target_file.path)
34
- ensure
35
- target_file.unlink
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,14 +0,0 @@
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
@@ -1,183 +0,0 @@
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/shaape_spec.rb DELETED
@@ -1,227 +0,0 @@
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