asciidoctor-diagram 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +15 -0
  3. data/README.adoc +252 -95
  4. data/README_zh-CN.adoc +333 -0
  5. data/images/asciidoctor-diagram-classes.png +0 -0
  6. data/images/asciidoctor-diagram-process.png +0 -0
  7. data/lib/{asciidoctor-diagram-java-1.3.8.jar → asciidoctor-diagram-java-1.3.10.jar} +0 -0
  8. data/lib/asciidoctor-diagram.rb +9 -9
  9. data/lib/asciidoctor-diagram/blockdiag.rb +1 -2
  10. data/lib/asciidoctor-diagram/blockdiag/extension.rb +27 -12
  11. data/lib/asciidoctor-diagram/ditaa.rb +1 -2
  12. data/lib/asciidoctor-diagram/ditaa/extension.rb +33 -48
  13. data/lib/asciidoctor-diagram/extensions.rb +85 -18
  14. data/lib/asciidoctor-diagram/graphviz.rb +1 -2
  15. data/lib/asciidoctor-diagram/graphviz/extension.rb +14 -4
  16. data/lib/asciidoctor-diagram/meme.rb +1 -2
  17. data/lib/asciidoctor-diagram/meme/extension.rb +82 -79
  18. data/lib/asciidoctor-diagram/mermaid.rb +1 -2
  19. data/lib/asciidoctor-diagram/mermaid/extension.rb +33 -25
  20. data/lib/asciidoctor-diagram/plantuml.rb +1 -2
  21. data/lib/asciidoctor-diagram/plantuml/extension.rb +33 -22
  22. data/lib/asciidoctor-diagram/salt.rb +1 -2
  23. data/lib/asciidoctor-diagram/shaape.rb +1 -2
  24. data/lib/asciidoctor-diagram/shaape/extension.rb +10 -5
  25. data/lib/asciidoctor-diagram/util/cli_generator.rb +7 -5
  26. data/lib/asciidoctor-diagram/util/java.rb +1 -1
  27. data/lib/asciidoctor-diagram/util/platform.rb +12 -1
  28. data/lib/asciidoctor-diagram/util/which.rb +16 -7
  29. data/lib/asciidoctor-diagram/version.rb +1 -1
  30. data/lib/asciidoctor-diagram/wavedrom.rb +1 -2
  31. data/lib/asciidoctor-diagram/wavedrom/extension.rb +24 -20
  32. data/lib/plantuml.jar +0 -0
  33. data/spec/blockdiag_spec.rb +8 -8
  34. data/spec/ditaa_spec.rb +7 -7
  35. data/spec/graphviz_spec.rb +7 -7
  36. data/spec/meme_spec.rb +2 -2
  37. data/spec/mermaid_spec.rb +11 -11
  38. data/spec/plantuml_spec.rb +156 -34
  39. data/spec/shaape_spec.rb +8 -8
  40. data/spec/test_helper.rb +24 -5
  41. data/spec/wavedrom_spec.rb +11 -11
  42. metadata +6 -3
@@ -6,7 +6,7 @@ module Asciidoctor
6
6
  module Java
7
7
  def self.classpath
8
8
  @classpath ||= [
9
- File.expand_path(File.join('../..', 'asciidoctor-diagram-java-1.3.8.jar'), File.dirname(__FILE__))
9
+ File.expand_path(File.join('../..', 'asciidoctor-diagram-java-1.3.10.jar'), File.dirname(__FILE__))
10
10
  ]
11
11
  end
12
12
 
@@ -20,6 +20,17 @@ module Asciidoctor
20
20
  end
21
21
  )
22
22
  end
23
+
24
+ def self.native_path(path)
25
+ return path if path.nil?
26
+
27
+ case os
28
+ when :windows
29
+ path.to_s.gsub('/', '\\')
30
+ else
31
+ path.to_s
32
+ end
33
+ end
23
34
  end
24
35
  end
25
- end
36
+ end
@@ -12,24 +12,33 @@ module Asciidoctor
12
12
  return exe if File.executable? exe
13
13
  }
14
14
  end
15
+
15
16
  nil
16
17
  end
17
18
 
18
19
  def which(parent_block, cmd, options = {})
19
- attr_names = options[:attr_names] || [cmd]
20
+ attr_names = options.fetch(:alt_attrs, []) + [cmd]
21
+ cmd_names = [cmd] + options.fetch(:alt_cmds, [])
20
22
 
21
23
  cmd_var = '@' + attr_names[0]
22
24
 
23
- already_defined = instance_variable_defined?(cmd_var)
24
-
25
- if already_defined
25
+ if instance_variable_defined?(cmd_var)
26
26
  cmd_path = instance_variable_get(cmd_var)
27
27
  else
28
- cmd_path = attr_names.map { |attr_name| parent_block.document.attributes[attr_name] }.find { |attr| !attr.nil? }
29
- cmd_path = ::Asciidoctor::Diagram::Which.which(cmd, :path => options[:path]) unless cmd_path && File.executable?(cmd_path)
28
+ cmd_path = attr_names.map { |attr_name| parent_block.attr(attr_name, nil, true) }.find { |attr| !attr.nil? }
29
+
30
+ unless cmd_path && File.executable?(cmd_path)
31
+ cmd_paths = cmd_names.map do |c|
32
+ ::Asciidoctor::Diagram::Which.which(c, :path => options[:path])
33
+ end
34
+
35
+ cmd_path = cmd_paths.reject { |c| c.nil? }.first
36
+ end
37
+
30
38
  instance_variable_set(cmd_var, cmd_path)
39
+
31
40
  if cmd_path.nil? && options.fetch(:raise_on_error, true)
32
- raise "Could not find the '#{cmd}' executable in PATH; add it to the PATH or specify its location using the '#{attr_names[0]}' document attribute"
41
+ raise "Could not find the #{cmd_names.map { |c| "'#{c}'" }.join(', ')} executable in PATH; add it to the PATH or specify its location using the '#{attr_names[0]}' document attribute"
33
42
  end
34
43
  end
35
44
 
@@ -1,5 +1,5 @@
1
1
  module Asciidoctor
2
2
  module Diagram
3
- VERSION = "1.4.0"
3
+ VERSION = "1.5.0"
4
4
  end
5
5
  end
@@ -1,5 +1,4 @@
1
- require 'asciidoctor/extensions'
2
- require_relative 'version'
1
+ require_relative 'extensions'
3
2
 
4
3
  Asciidoctor::Extensions.register do
5
4
  require_relative 'wavedrom/extension'
@@ -11,28 +11,32 @@ module Asciidoctor
11
11
 
12
12
  def self.included(mod)
13
13
  [:png, :svg].each do |f|
14
- mod.register_format(f, :image) do |c, p|
15
- wavedrom_cli = which(p, 'wavedrom', :raise_on_error => false)
16
- phantomjs = which(p, 'phantomjs', :raise_on_error => false)
14
+ mod.register_format(f, :image) do |parent, source|
15
+ wavedrom(parent, source, f)
16
+ end
17
+ end
18
+ end
17
19
 
18
- if wavedrom_cli && phantomjs
19
- CliGenerator.generate_file(wavedrom_cli, f.to_s, c.to_s) do |tool_path, input_path, output_path|
20
- [phantomjs, tool_path, '-i', input_path, "-#{f.to_s[0]}", output_path]
21
- end
22
- else
23
- if ::Asciidoctor::Diagram::Platform.os == :macosx
24
- wavedrom = which(p, 'WaveDromEditor.app', :attr_names => ['wavedrom'], :path => ['/Applications'])
25
- if wavedrom
26
- wavedrom = File.join(wavedrom, 'Contents/MacOS/nwjs')
27
- end
28
- else
29
- wavedrom = which(p, 'WaveDromEditor', :attr_names => ['wavedrom'])
30
- end
20
+ def wavedrom(parent, source, format)
21
+ wavedrom_cli = which(parent, 'wavedrom', :raise_on_error => false)
22
+ phantomjs = which(parent, 'phantomjs', :alt_attrs => ['phantomjs_2'], :raise_on_error => false)
31
23
 
32
- CliGenerator.generate_file(wavedrom, f.to_s, c.to_s) do |tool_path, input_path, output_path|
33
- [tool_path, 'source', input_path, f.to_s, output_path]
34
- end
24
+ if wavedrom_cli && !wavedrom_cli.include?('WaveDromEditor') && phantomjs
25
+ CliGenerator.generate_file(wavedrom_cli, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
26
+ [phantomjs, Platform.native_path(tool_path), '-i', Platform.native_path(input_path), "-#{format.to_s[0]}", Platform.native_path(output_path)]
27
+ end
28
+ else
29
+ if ::Asciidoctor::Diagram::Platform.os == :macosx
30
+ wavedrom = which(parent, 'WaveDromEditor.app', :alt_attrs => ['wavedrom'], :path => ['/Applications'])
31
+ if wavedrom
32
+ wavedrom = File.join(wavedrom, 'Contents/MacOS/nwjs')
35
33
  end
34
+ else
35
+ wavedrom = which(parent, 'WaveDromEditor', :alt_attrs => ['wavedrom'])
36
+ end
37
+
38
+ CliGenerator.generate_file(wavedrom, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
39
+ [tool_path, 'source', Platform.native_path(input_path), format.to_s, Platform.native_path(output_path)]
36
40
  end
37
41
  end
38
42
  end
@@ -46,4 +50,4 @@ module Asciidoctor
46
50
  include Wavedrom
47
51
  end
48
52
  end
49
- end
53
+ end
data/lib/plantuml.jar CHANGED
Binary file
@@ -20,7 +20,7 @@ Doc Writer <doc@example.com>
20
20
  blockdiag::blockdiag.txt[format="png"]
21
21
  eos
22
22
 
23
- d = Asciidoctor.load StringIO.new(doc)
23
+ d = load_asciidoc doc
24
24
  expect(d).to_not be_nil
25
25
 
26
26
  b = d.find { |b| b.context == :image }
@@ -52,7 +52,7 @@ Doc Writer <doc@example.com>
52
52
  ----
53
53
  eos
54
54
 
55
- d = Asciidoctor.load StringIO.new(doc)
55
+ d = load_asciidoc doc
56
56
  expect(d).to_not be_nil
57
57
 
58
58
  b = d.find { |b| b.context == :image }
@@ -82,7 +82,7 @@ Doc Writer <doc@example.com>
82
82
  ----
83
83
  eos
84
84
 
85
- d = Asciidoctor.load StringIO.new(doc)
85
+ d = load_asciidoc doc
86
86
  expect(d).to_not be_nil
87
87
 
88
88
  b = d.find { |b| b.context == :image }
@@ -111,7 +111,7 @@ Doc Writer <doc@example.com>
111
111
  ----
112
112
  eos
113
113
 
114
- expect { Asciidoctor.load StringIO.new(doc) }.to raise_error /support.*format/i
114
+ expect { load_asciidoc doc }.to raise_error /support.*format/i
115
115
  end
116
116
 
117
117
  it "should not regenerate images when source has not changed" do
@@ -131,7 +131,7 @@ blockdiag::blockdiag.txt
131
131
  ----
132
132
  eos
133
133
 
134
- d = Asciidoctor.load StringIO.new(doc)
134
+ d = load_asciidoc doc
135
135
  b = d.find { |b| b.context == :image }
136
136
  expect(b).to_not be_nil
137
137
  target = b.attributes['target']
@@ -139,7 +139,7 @@ blockdiag::blockdiag.txt
139
139
 
140
140
  sleep 1
141
141
 
142
- d = Asciidoctor.load StringIO.new(doc)
142
+ d = load_asciidoc doc
143
143
 
144
144
  mtime2 = File.mtime(target)
145
145
 
@@ -159,7 +159,7 @@ blockdiag::blockdiag.txt[]
159
159
  blockdiag::blockdiag.txt[]
160
160
  eos
161
161
 
162
- Asciidoctor.load StringIO.new(doc)
162
+ load_asciidoc doc
163
163
  expect(File.exists?('blockdiag.png')).to be true
164
164
  end
165
165
 
@@ -176,7 +176,7 @@ blockdiag::blockdiag.txt["foobar"]
176
176
  blockdiag::blockdiag.txt["foobaz"]
177
177
  eos
178
178
 
179
- Asciidoctor.load StringIO.new(doc)
179
+ load_asciidoc doc
180
180
  expect(File.exists?('foobar.png')).to be true
181
181
  expect(File.exists?('foobaz.png')).to be true
182
182
  expect(File.exists?('blockdiag.png')).to be false
data/spec/ditaa_spec.rb CHANGED
@@ -25,7 +25,7 @@ Doc Writer <doc@example.com>
25
25
  ditaa::ditaa.txt[format="png"]
26
26
  eos
27
27
 
28
- d = Asciidoctor.load StringIO.new(doc)
28
+ d = load_asciidoc doc
29
29
  expect(d).to_not be_nil
30
30
 
31
31
  b = d.find { |b| b.context == :image }
@@ -65,7 +65,7 @@ Doc Writer <doc@example.com>
65
65
  ----
66
66
  eos
67
67
 
68
- d = Asciidoctor.load StringIO.new(doc)
68
+ d = load_asciidoc doc
69
69
  expect(d).to_not be_nil
70
70
 
71
71
  b = d.find { |b| b.context == :image }
@@ -94,7 +94,7 @@ Doc Writer <doc@example.com>
94
94
  ----
95
95
  eos
96
96
 
97
- expect { Asciidoctor.load StringIO.new(doc) }.to raise_error /support.*format/i
97
+ expect { load_asciidoc doc }.to raise_error /support.*format/i
98
98
  end
99
99
 
100
100
  it "should use a default format when none was given" do
@@ -109,7 +109,7 @@ Doc Writer <doc@example.com>
109
109
  ----
110
110
  eos
111
111
 
112
- d = Asciidoctor.load StringIO.new(doc)
112
+ d = load_asciidoc doc
113
113
  expect(d).to_not be_nil
114
114
 
115
115
  b = d.find { |b| b.context == :image }
@@ -142,7 +142,7 @@ Doc Writer <doc@example.com>
142
142
  ----
143
143
  eos
144
144
 
145
- d = Asciidoctor.load StringIO.new(doc)
145
+ d = load_asciidoc doc
146
146
  expect(d).to_not be_nil
147
147
 
148
148
  b = d.find { |b| b.context == :image }
@@ -173,14 +173,14 @@ Doc Writer <doc@example.com>
173
173
  ----
174
174
  eos
175
175
 
176
- d = Asciidoctor.load StringIO.new(doc.sub('{opts}', 'shadow=false'))
176
+ d = load_asciidoc(doc.sub('{opts}', 'shadow=false'))
177
177
  b = d.find { |b| b.context == :image }
178
178
  target = b.attributes['target']
179
179
  mtime1 = File.mtime(target)
180
180
 
181
181
  sleep 1
182
182
 
183
- d = Asciidoctor.load StringIO.new(doc.sub('{opts}', 'round-corners=true'))
183
+ d = load_asciidoc(doc.sub('{opts}', 'round-corners=true'))
184
184
 
185
185
  mtime2 = File.mtime(target)
186
186
 
@@ -24,7 +24,7 @@ Doc Writer <doc@example.com>
24
24
  graphviz::graphviz.txt[format="png"]
25
25
  eos
26
26
 
27
- d = Asciidoctor.load StringIO.new(doc)
27
+ d = load_asciidoc doc
28
28
  expect(d).to_not be_nil
29
29
 
30
30
  b = d.find { |b| b.context == :image }
@@ -63,7 +63,7 @@ digraph foo {
63
63
  ----
64
64
  eos
65
65
 
66
- d = Asciidoctor.load StringIO.new(doc)
66
+ d = load_asciidoc doc
67
67
  expect(d).to_not be_nil
68
68
 
69
69
  b = d.find { |b| b.context == :image }
@@ -100,7 +100,7 @@ digraph foo {
100
100
  ----
101
101
  eos
102
102
 
103
- d = Asciidoctor.load StringIO.new(doc)
103
+ d = load_asciidoc doc
104
104
  expect(d).to_not be_nil
105
105
 
106
106
  b = d.find { |b| b.context == :image }
@@ -129,23 +129,23 @@ Doc Writer <doc@example.com>
129
129
  ----
130
130
  eos
131
131
 
132
- expect { Asciidoctor.load StringIO.new(doc) }.to raise_error /support.*format/i
132
+ expect { load_asciidoc doc }.to raise_error /support.*format/i
133
133
  end
134
134
 
135
- it "should support single line digraphs" do
135
+ it "should support neato layout engine" do
136
136
  doc = <<-eos
137
137
  = Hello, graphviz!
138
138
  Doc Writer <doc@example.com>
139
139
 
140
140
  == First Section
141
141
 
142
- [graphviz]
142
+ [graphviz, layout=neato]
143
143
  ----
144
144
  digraph g { rankdir=LR; Text->Graphviz->Image }
145
145
  ----
146
146
  eos
147
147
 
148
- d = Asciidoctor.load StringIO.new(doc)
148
+ d = load_asciidoc doc
149
149
  expect(d).to_not be_nil
150
150
 
151
151
  b = d.find { |b| b.context == :image }
data/spec/meme_spec.rb CHANGED
@@ -16,7 +16,7 @@ Doc Writer <doc@example.com>
16
16
  meme::man.jpg[I don't always // write unit tests, but when I do // they generate memes, format=png, options=noupcase]
17
17
  eos
18
18
 
19
- d = Asciidoctor.load StringIO.new(doc)
19
+ d = load_asciidoc doc
20
20
  expect(d).to_not be_nil
21
21
 
22
22
  b = d.find { |b| b.context == :image }
@@ -48,7 +48,7 @@ Doc Writer <doc@example.com>
48
48
  meme::man.jpg[I don't always // write unit tests, but when I do // they generate memes, format=gif, options=noupcase]
49
49
  eos
50
50
 
51
- d = Asciidoctor.load StringIO.new(doc)
51
+ d = load_asciidoc doc
52
52
  expect(d).to_not be_nil
53
53
 
54
54
  b = d.find { |b| b.context == :image }
data/spec/mermaid_spec.rb CHANGED
@@ -21,7 +21,7 @@ Doc Writer <doc@example.com>
21
21
  mermaid::mermaid.txt[format="png"]
22
22
  eos
23
23
 
24
- d = Asciidoctor.load StringIO.new(doc)
24
+ d = load_asciidoc doc
25
25
  expect(d).to_not be_nil
26
26
 
27
27
  b = d.find { |b| b.context == :image }
@@ -50,7 +50,7 @@ Doc Writer <doc@example.com>
50
50
  mermaid::mermaid.txt[format="svg"]
51
51
  eos
52
52
 
53
- d = Asciidoctor.load StringIO.new(doc)
53
+ d = load_asciidoc doc
54
54
  expect(d).to_not be_nil
55
55
 
56
56
  b = d.find { |b| b.context == :image }
@@ -82,7 +82,7 @@ Doc Writer <doc@example.com>
82
82
  ----
83
83
  eos
84
84
 
85
- d = Asciidoctor.load StringIO.new(doc)
85
+ d = load_asciidoc doc
86
86
  expect(d).to_not be_nil
87
87
 
88
88
  b = d.find { |b| b.context == :image }
@@ -112,7 +112,7 @@ Doc Writer <doc@example.com>
112
112
  ----
113
113
  eos
114
114
 
115
- d = Asciidoctor.load StringIO.new(doc)
115
+ d = load_asciidoc doc
116
116
  expect(d).to_not be_nil
117
117
 
118
118
  b = d.find { |b| b.context == :image }
@@ -141,7 +141,7 @@ Doc Writer <doc@example.com>
141
141
  ----
142
142
  eos
143
143
 
144
- expect { Asciidoctor.load StringIO.new(doc) }.to raise_error /support.*format/i
144
+ expect { load_asciidoc doc }.to raise_error /support.*format/i
145
145
  end
146
146
 
147
147
  it "should not regenerate images when source has not changed" do
@@ -161,7 +161,7 @@ mermaid::mermaid.txt
161
161
  ----
162
162
  eos
163
163
 
164
- d = Asciidoctor.load StringIO.new(doc)
164
+ d = load_asciidoc doc
165
165
  b = d.find { |b| b.context == :image }
166
166
  expect(b).to_not be_nil
167
167
  target = b.attributes['target']
@@ -169,7 +169,7 @@ mermaid::mermaid.txt
169
169
 
170
170
  sleep 1
171
171
 
172
- d = Asciidoctor.load StringIO.new(doc)
172
+ d = load_asciidoc doc
173
173
 
174
174
  mtime2 = File.mtime(target)
175
175
 
@@ -189,7 +189,7 @@ mermaid::mermaid.txt[]
189
189
  mermaid::mermaid.txt[]
190
190
  eos
191
191
 
192
- Asciidoctor.load StringIO.new(doc)
192
+ load_asciidoc doc
193
193
  expect(File.exists?('mermaid.png')).to be true
194
194
  end
195
195
 
@@ -206,7 +206,7 @@ mermaid::mermaid.txt["foobar"]
206
206
  mermaid::mermaid.txt["foobaz"]
207
207
  eos
208
208
 
209
- Asciidoctor.load StringIO.new(doc)
209
+ load_asciidoc doc
210
210
  expect(File.exists?('foobar.png')).to be true
211
211
  expect(File.exists?('foobaz.png')).to be true
212
212
  expect(File.exists?('mermaid.png')).to be false
@@ -244,7 +244,7 @@ mermaid::mermaid.txt["with_config", sequenceConfig="seqconfig.txt"]
244
244
  mermaid::mermaid.txt["without_config"]
245
245
  eos
246
246
 
247
- Asciidoctor.load StringIO.new(doc)
247
+ load_asciidoc doc
248
248
  expect(File.exists?('with_config.png')).to be true
249
249
  expect(File.exists?('without_config.png')).to be true
250
250
  expect(File.size('with_config.png')).to_not be File.size('without_config.png')
@@ -269,7 +269,7 @@ mermaid::mermaid.txt["with_width", width="700"]
269
269
  mermaid::mermaid.txt["without_width"]
270
270
  eos
271
271
 
272
- Asciidoctor.load StringIO.new(doc)
272
+ load_asciidoc doc
273
273
  expect(File.exists?('with_width.png')).to be true
274
274
  expect(File.exists?('without_width.png')).to be true
275
275
  expect(File.size('with_width.png')).to_not be File.size('without_width.png')
@@ -20,7 +20,7 @@ Doc Writer <doc@example.com>
20
20
  plantuml::plantuml.txt[format="png"]
21
21
  eos
22
22
 
23
- d = Asciidoctor.load StringIO.new(doc)
23
+ d = load_asciidoc doc
24
24
  expect(d).to_not be_nil
25
25
 
26
26
  b = d.find { |b| b.context == :image }
@@ -36,6 +36,72 @@ plantuml::plantuml.txt[format="png"]
36
36
  expect(b.attributes['width']).to_not be_nil
37
37
  expect(b.attributes['height']).to_not be_nil
38
38
  end
39
+
40
+ it 'should support substitutions' do
41
+ code = <<-eos
42
+ class {parent-class}
43
+ class {child-class}
44
+ {parent-class} <|-- {child-class}
45
+ eos
46
+
47
+ File.write('plantuml.txt', code)
48
+
49
+ doc = <<-eos
50
+ = Hello, PlantUML!
51
+ Doc Writer <doc@example.com>
52
+ :parent-class: ParentClass
53
+ :child-class: ChildClass
54
+
55
+ == First Section
56
+
57
+ plantuml::plantuml.txt[format="svg", subs=attributes+]
58
+ eos
59
+
60
+ d = load_asciidoc doc, :attributes => {'backend' => 'html5'}
61
+ expect(d).to_not be_nil
62
+
63
+ b = d.find { |b| b.context == :image }
64
+ expect(b).to_not be_nil
65
+
66
+ target = b.attributes['target']
67
+ expect(File.exists?(target)).to be true
68
+
69
+ content = File.read(target)
70
+ expect(content).to include('ParentClass')
71
+ expect(content).to include('ChildClass')
72
+ end
73
+
74
+ it 'should resolve !include directives with relative paths' do
75
+ included = <<-eos
76
+ interface List
77
+ List : int size()
78
+ List : void clear()
79
+ eos
80
+
81
+ code = <<-eos
82
+ !include list.iuml
83
+ List <|.. ArrayList
84
+ eos
85
+
86
+ Dir.mkdir('dir')
87
+ File.write('dir/list.iuml', included)
88
+ File.write('dir/plantuml.txt', code)
89
+
90
+ doc = <<-eos
91
+ = Hello, PlantUML!
92
+ Doc Writer <doc@example.com>
93
+ :parent-class: ParentClass
94
+ :child-class: ChildClass
95
+
96
+ == First Section
97
+
98
+ plantuml::dir/plantuml.txt[format="png", subs=attributes+]
99
+ eos
100
+
101
+ load_asciidoc doc, :attributes => {'backend' => 'html5'}
102
+
103
+ # No easy way to assert this since PlantUML doesn't produce an error on file not found
104
+ end
39
105
  end
40
106
 
41
107
  describe Asciidoctor::Diagram::PlantUmlBlockProcessor do
@@ -55,7 +121,7 @@ User --> (Use the application) : Label
55
121
  ----
56
122
  eos
57
123
 
58
- d = Asciidoctor.load StringIO.new(doc)
124
+ d = load_asciidoc doc
59
125
  expect(d).to_not be_nil
60
126
 
61
127
  b = d.find { |b| b.context == :image }
@@ -88,7 +154,7 @@ User --> (Use the application) : Label
88
154
  ----
89
155
  eos
90
156
 
91
- d = Asciidoctor.load StringIO.new(doc)
157
+ d = load_asciidoc doc
92
158
  expect(d).to_not be_nil
93
159
 
94
160
  b = d.find { |b| b.context == :image }
@@ -121,7 +187,7 @@ User --> (Use the application) : Label
121
187
  ----
122
188
  eos
123
189
 
124
- d = Asciidoctor.load StringIO.new(doc)
190
+ d = load_asciidoc doc
125
191
  expect(d).to_not be_nil
126
192
 
127
193
  b = d.find { |b| b.context == :literal }
@@ -132,7 +198,7 @@ User --> (Use the application) : Label
132
198
  expect(b.attributes['target']).to be_nil
133
199
  end
134
200
 
135
- it "should raise an error when when format is set to an invalid value" do
201
+ it 'should raise an error when when format is set to an invalid value' do
136
202
  doc = <<-eos
137
203
  = Hello, PlantUML!
138
204
  Doc Writer <doc@example.com>
@@ -144,10 +210,10 @@ Doc Writer <doc@example.com>
144
210
  ----
145
211
  eos
146
212
 
147
- expect { Asciidoctor.load StringIO.new(doc) }.to raise_error /support.*format/i
213
+ expect { load_asciidoc doc }.to raise_error /support.*format/i
148
214
  end
149
215
 
150
- it "should use plantuml configuration when specified as a document attribute" do
216
+ it 'should use plantuml configuration when specified as a document attribute' do
151
217
  doc = <<-eos
152
218
  = Hello, PlantUML!
153
219
  Doc Writer <doc@example.com>
@@ -171,7 +237,7 @@ ArrowColor #DEADBE
171
237
  f.write config
172
238
  end
173
239
 
174
- d = Asciidoctor.load StringIO.new(doc)
240
+ d = load_asciidoc doc
175
241
  b = d.find { |b| b.context == :image }
176
242
 
177
243
  target = b.attributes['target']
@@ -182,7 +248,7 @@ ArrowColor #DEADBE
182
248
  expect(svg).to match /<path.*fill="#DEADBE"/
183
249
  end
184
250
 
185
- it "should not regenerate images when source has not changed" do
251
+ it 'should not regenerate images when source has not changed' do
186
252
  code = <<-eos
187
253
  User -> (Start)
188
254
  User --> (Use the application) : Label
@@ -208,21 +274,21 @@ Foo1 -> Foo2 : To boundary
208
274
  ----
209
275
  eos
210
276
 
211
- d = Asciidoctor.load StringIO.new(doc)
277
+ d = load_asciidoc doc
212
278
  b = d.find { |b| b.context == :image }
213
279
  target = b.attributes['target']
214
280
  mtime1 = File.mtime(target)
215
281
 
216
282
  sleep 1
217
283
 
218
- d = Asciidoctor.load StringIO.new(doc)
284
+ d = load_asciidoc doc
219
285
 
220
286
  mtime2 = File.mtime(target)
221
287
 
222
288
  expect(mtime2).to eq mtime1
223
289
  end
224
290
 
225
- it "should handle two block macros with the same source" do
291
+ it 'should handle two block macros with the same source' do
226
292
  code = <<-eos
227
293
  User -> (Start)
228
294
  User --> (Use the application) : Label
@@ -242,11 +308,11 @@ plantuml::plantuml.txt[]
242
308
  plantuml::plantuml.txt[]
243
309
  eos
244
310
 
245
- Asciidoctor.load StringIO.new(doc)
311
+ load_asciidoc doc
246
312
  expect(File.exists?('plantuml.png')).to be true
247
313
  end
248
314
 
249
- it "should respect target attribute in block macros" do
315
+ it 'should respect target attribute in block macros' do
250
316
  code = <<-eos
251
317
  User -> (Start)
252
318
  User --> (Use the application) : Label
@@ -266,13 +332,13 @@ plantuml::plantuml.txt["foobar"]
266
332
  plantuml::plantuml.txt["foobaz"]
267
333
  eos
268
334
 
269
- Asciidoctor.load StringIO.new(doc)
335
+ load_asciidoc doc
270
336
  expect(File.exists?('foobar.png')).to be true
271
337
  expect(File.exists?('foobaz.png')).to be true
272
338
  expect(File.exists?('plantuml.png')).to be false
273
339
  end
274
340
 
275
- it "should respect target attribute values with relative paths in block macros" do
341
+ it 'should respect target attribute values with relative paths in block macros' do
276
342
  code = <<-eos
277
343
  User -> (Start)
278
344
  User --> (Use the application) : Label
@@ -292,13 +358,13 @@ plantuml::plantuml.txt["test/foobar"]
292
358
  plantuml::plantuml.txt["test2/foobaz"]
293
359
  eos
294
360
 
295
- Asciidoctor.load StringIO.new(doc)
361
+ load_asciidoc doc
296
362
  expect(File.exists?('test/foobar.png')).to be true
297
363
  expect(File.exists?('test2/foobaz.png')).to be true
298
364
  expect(File.exists?('plantuml.png')).to be false
299
365
  end
300
366
 
301
- it "should write files to outdir if set" do
367
+ it 'should write files to outdir if set' do
302
368
  doc = <<-eos
303
369
  = Hello, PlantUML!
304
370
  Doc Writer <doc@example.com>
@@ -313,7 +379,7 @@ Foo1 -> Foo2 : To boundary
313
379
  ----
314
380
  eos
315
381
 
316
- d = Asciidoctor.load StringIO.new(doc), {:attributes => {'outdir' => 'foo'}}
382
+ d = load_asciidoc doc, {:attributes => {'outdir' => 'foo'}}
317
383
  b = d.find { |b| b.context == :image }
318
384
 
319
385
  target = b.attributes['target']
@@ -322,7 +388,7 @@ Foo1 -> Foo2 : To boundary
322
388
  expect(File.exists?(File.expand_path(target, 'foo'))).to be true
323
389
  end
324
390
 
325
- it "should write files to imagesoutdir if set" do
391
+ it 'should write files to imagesoutdir if set' do
326
392
  doc = <<-eos
327
393
  = Hello, PlantUML!
328
394
  Doc Writer <doc@example.com>
@@ -337,7 +403,7 @@ Foo1 -> Foo2 : To boundary
337
403
  ----
338
404
  eos
339
405
 
340
- d = Asciidoctor.load StringIO.new(doc), {:attributes => {'imagesoutdir' => 'bar', 'outdir' => 'foo'}}
406
+ d = load_asciidoc doc, {:attributes => {'imagesoutdir' => 'bar', 'outdir' => 'foo'}}
341
407
  b = d.find { |b| b.context == :image }
342
408
 
343
409
  target = b.attributes['target']
@@ -347,7 +413,7 @@ Foo1 -> Foo2 : To boundary
347
413
  expect(File.exists?(File.expand_path(target, 'foo'))).to be false
348
414
  end
349
415
 
350
- it "should omit width/height attributes when generating docbook" do
416
+ it 'should omit width/height attributes when generating docbook' do
351
417
  doc = <<-eos
352
418
  = Hello, PlantUML!
353
419
  Doc Writer <doc@example.com>
@@ -360,7 +426,7 @@ User -> (Start)
360
426
  ----
361
427
  eos
362
428
 
363
- d = Asciidoctor.load StringIO.new(doc), :attributes => {'backend' => 'docbook5'}
429
+ d = load_asciidoc doc, :attributes => {'backend' => 'docbook5'}
364
430
  expect(d).to_not be_nil
365
431
 
366
432
  b = d.find { |b| b.context == :image }
@@ -373,7 +439,7 @@ User -> (Start)
373
439
  expect(b.attributes['height']).to be_nil
374
440
  end
375
441
 
376
- it "should support salt diagrams using salt block type" do
442
+ it 'should support salt diagrams using salt block type' do
377
443
  doc = <<-eos
378
444
  = Hello, PlantUML!
379
445
  Doc Writer <doc@example.com>
@@ -395,7 +461,7 @@ Doc Writer <doc@example.com>
395
461
  ----
396
462
  eos
397
463
 
398
- d = Asciidoctor.load StringIO.new(doc), :attributes => {'backend' => 'docbook5'}
464
+ d = load_asciidoc doc, :attributes => {'backend' => 'docbook5'}
399
465
  expect(d).to_not be_nil
400
466
 
401
467
  b = d.find { |b| b.context == :image }
@@ -408,7 +474,7 @@ Doc Writer <doc@example.com>
408
474
  expect(b.attributes['height']).to be_nil
409
475
  end
410
476
 
411
- it "should support salt diagrams using plantuml block type" do
477
+ it 'should support salt diagrams using plantuml block type' do
412
478
  doc = <<-eos
413
479
  = Hello, PlantUML!
414
480
  Doc Writer <doc@example.com>
@@ -431,7 +497,7 @@ salt
431
497
  ----
432
498
  eos
433
499
 
434
- d = Asciidoctor.load StringIO.new(doc), :attributes => {'backend' => 'docbook5'}
500
+ d = load_asciidoc doc, :attributes => {'backend' => 'docbook5'}
435
501
  expect(d).to_not be_nil
436
502
 
437
503
  b = d.find { |b| b.context == :image }
@@ -444,7 +510,7 @@ salt
444
510
  expect(b.attributes['height']).to be_nil
445
511
  end
446
512
 
447
- it "should support salt diagrams containing tree widgets" do
513
+ it 'should support salt diagrams containing tree widgets' do
448
514
  doc = <<-eos
449
515
  = Hello, PlantUML!
450
516
  Doc Writer <doc@example.com>
@@ -463,7 +529,7 @@ salt
463
529
  ----
464
530
  eos
465
531
 
466
- d = Asciidoctor.load StringIO.new(doc), :attributes => {'backend' => 'docbook5'}
532
+ d = load_asciidoc doc, :attributes => {'backend' => 'docbook5'}
467
533
  expect(d).to_not be_nil
468
534
 
469
535
  b = d.find { |b| b.context == :image }
@@ -476,7 +542,7 @@ salt
476
542
  expect(b.attributes['height']).to be_nil
477
543
  end
478
544
 
479
- it "should support scaling diagrams" do
545
+ it 'should support scaling diagrams' do
480
546
  doc = <<-eos
481
547
  = Hello, PlantUML!
482
548
  Doc Writer <doc@example.com>
@@ -501,17 +567,17 @@ A -> B
501
567
  ----
502
568
  eos
503
569
 
504
- d = Asciidoctor.load StringIO.new(doc), :attributes => {'backend' => 'html5'}
570
+ d = load_asciidoc doc, :attributes => {'backend' => 'html5'}
505
571
  unscaled_image = d.find { |b| b.context == :image }
506
572
 
507
- d = Asciidoctor.load StringIO.new(scaled_doc), :attributes => {'backend' => 'html5'}
573
+ d = load_asciidoc scaled_doc, :attributes => {'backend' => 'html5'}
508
574
  scaled_image = d.find { |b| b.context == :image }
509
575
 
510
576
  expect(scaled_image.attributes['width']).to be_within(1).of(unscaled_image.attributes['width'] * 1.5)
511
577
  expect(scaled_image.attributes['height']).to be_within(1).of(unscaled_image.attributes['height'] * 1.5)
512
578
  end
513
579
 
514
- it "should handle embedded creole images correctly" do
580
+ it 'should handle embedded creole images correctly' do
515
581
  creole_doc = <<-eos
516
582
  = Hello, PlantUML!
517
583
  Doc Writer <doc@example.com>
@@ -533,8 +599,64 @@ Doc Writer <doc@example.com>
533
599
  ----
534
600
  eos
535
601
 
536
- Asciidoctor.load StringIO.new(creole_doc), :attributes => {'backend' => 'html5'}
602
+ load_asciidoc creole_doc, :attributes => {'backend' => 'html5'}
537
603
 
538
604
  # No real way to assert this since PlantUML doesn't produce an error on file not found
539
605
  end
606
+
607
+ it 'should resolve !include directives with relative paths' do
608
+ included = <<-eos
609
+ interface List
610
+ List : int size()
611
+ List : void clear()
612
+ eos
613
+
614
+ Dir.mkdir('dir')
615
+ File.write('dir/list.iuml', included)
616
+
617
+ creole_doc = <<-eos
618
+ = Hello, PlantUML!
619
+ Doc Writer <doc@example.com>
620
+
621
+ == First Section
622
+
623
+ [plantuml, format="png"]
624
+ ----
625
+ !include dir/List.iuml
626
+ List <|.. ArrayList
627
+ ----
628
+ eos
629
+
630
+ load_asciidoc creole_doc, :attributes => {'backend' => 'html5'}
631
+
632
+ # No easy way to assert this since PlantUML doesn't produce an error on file not found
633
+ end
634
+
635
+ it 'should support substitutions' do
636
+ doc = <<-eos
637
+ = Hello, PlantUML!
638
+ :parent-class: ParentClass
639
+ :child-class: ChildClass
640
+
641
+ [plantuml,class-inheritence,svg,subs=attributes+]
642
+ ....
643
+ class {parent-class}
644
+ class {child-class}
645
+ {parent-class} <|-- {child-class}
646
+ ....
647
+ eos
648
+
649
+ d = load_asciidoc doc, :attributes => {'backend' => 'html5'}
650
+ expect(d).to_not be_nil
651
+
652
+ b = d.find { |b| b.context == :image }
653
+ expect(b).to_not be_nil
654
+
655
+ target = b.attributes['target']
656
+ expect(File.exists?(target)).to be true
657
+
658
+ content = File.read(target)
659
+ expect(content).to include('ParentClass')
660
+ expect(content).to include('ChildClass')
661
+ end
540
662
  end