asciidoctor-diagram 1.5.5 → 1.5.6

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.
@@ -0,0 +1,8 @@
1
+ require_relative 'extensions'
2
+
3
+ Asciidoctor::Extensions.register do
4
+ require_relative 'syntrax/extension'
5
+
6
+ block Asciidoctor::Diagram::SyntraxBlockProcessor, :syntrax
7
+ block_macro Asciidoctor::Diagram::SyntraxBlockMacroProcessor, :syntrax
8
+ end
@@ -0,0 +1,54 @@
1
+ require_relative '../extensions'
2
+ require_relative '../util/cli_generator'
3
+ require_relative '../util/platform'
4
+ require_relative '../util/which'
5
+
6
+ module Asciidoctor
7
+ module Diagram
8
+ # @private
9
+ module Syntrax
10
+ include CliGenerator
11
+ include Which
12
+
13
+ def self.included(mod)
14
+ [:png, :svg].each do |f|
15
+ mod.register_format(f, :image) do |parent, source|
16
+ syntrax(parent, source, f)
17
+ end
18
+ end
19
+ end
20
+
21
+ def syntrax(parent, source, format)
22
+ inherit_prefix = name
23
+
24
+ generate_file(which(parent, 'syntrax'), 'spec', format.to_s, source.to_s) do |tool_path, input_path, output_path|
25
+ args = [tool_path, '-i', Platform.native_path(input_path), '-o', Platform.native_path(output_path)]
26
+
27
+ scale = source.attr('scale', nil, inherit_prefix)
28
+ if scale
29
+ args << '--scale' << scale
30
+ end
31
+
32
+ transparent = source.attr('transparent', nil, inherit_prefix)
33
+ if transparent == 'true'
34
+ args << '--transparent'
35
+ end
36
+ style = source.attr('style', nil, inherit_prefix)
37
+ if style
38
+ args << '--style' << style
39
+ end
40
+
41
+ args
42
+ end
43
+ end
44
+ end
45
+
46
+ class SyntraxBlockProcessor < Extensions::DiagramBlockProcessor
47
+ include Syntrax
48
+ end
49
+
50
+ class SyntraxBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
51
+ include Syntrax
52
+ end
53
+ end
54
+ end
@@ -1,5 +1,5 @@
1
1
  module Asciidoctor
2
2
  module Diagram
3
- VERSION = "1.5.5"
3
+ VERSION = "1.5.6"
4
4
  end
5
5
  end
@@ -7,7 +7,7 @@ blockdiag {
7
7
  }
8
8
  eos
9
9
 
10
- describe Asciidoctor::Diagram::BlockDiagBlockMacroProcessor do
10
+ describe Asciidoctor::Diagram::BlockDiagBlockMacroProcessor, :broken_on_appveyor do
11
11
  it "should generate PNG images when format is set to 'png'" do
12
12
  File.write('blockdiag.txt', code)
13
13
 
@@ -38,7 +38,7 @@ blockdiag::blockdiag.txt[format="png"]
38
38
  end
39
39
  end
40
40
 
41
- describe Asciidoctor::Diagram::BlockDiagBlockProcessor do
41
+ describe Asciidoctor::Diagram::BlockDiagBlockProcessor, :broken_on_appveyor do
42
42
  it "should generate PNG images when format is set to 'png'" do
43
43
  doc = <<-eos
44
44
  = Hello, BlockDiag!
@@ -0,0 +1,230 @@
1
+ require_relative 'test_helper'
2
+
3
+ code = <<-eos
4
+ # MSC for some fictional process
5
+ msc {
6
+ hscale = "2";
7
+
8
+ a,b,c;
9
+
10
+ a->b [ label = "ab()" ] ;
11
+ b->c [ label = "bc(TRUE)"];
12
+ c=>c [ label = "process(1)" ];
13
+ c=>c [ label = "process(2)" ];
14
+ ...;
15
+ c=>c [ label = "process(n)" ];
16
+ c=>c [ label = "process(END)" ];
17
+ a<<=c [ label = "callback()"];
18
+ --- [ label = "If more to run", ID="*" ];
19
+ a->a [ label = "next()"];
20
+ a->c [ label = "ac1()\nac2()"];
21
+ b<-c [ label = "cb(TRUE)"];
22
+ b->b [ label = "stalled(...)"];
23
+ a<-b [ label = "ab() = FALSE"];
24
+ }
25
+ eos
26
+
27
+ describe Asciidoctor::Diagram::MscBlockMacroProcessor, :broken_on_windows do
28
+ it "should generate PNG images when format is set to 'png'" do
29
+ File.write('msc.txt', code)
30
+
31
+ doc = <<-eos
32
+ = Hello, Msc!
33
+ Doc Writer <doc@example.com>
34
+
35
+ == First Section
36
+
37
+ msc::msc.txt[format="png"]
38
+ eos
39
+
40
+ d = load_asciidoc doc
41
+ expect(d).to_not be_nil
42
+
43
+ b = d.find { |bl| bl.context == :image }
44
+ expect(b).to_not be_nil
45
+
46
+ expect(b.content_model).to eq :empty
47
+
48
+ target = b.attributes['target']
49
+ expect(target).to_not be_nil
50
+ expect(target).to match(/\.png$/)
51
+ expect(File.exist?(target)).to be true
52
+
53
+ expect(b.attributes['width']).to_not be_nil
54
+ expect(b.attributes['height']).to_not be_nil
55
+ end
56
+
57
+ it "should generate SVG images when format is set to 'svg'" do
58
+ File.write('msc.txt', code)
59
+
60
+ doc = <<-eos
61
+ = Hello, Msc!
62
+ Doc Writer <doc@example.com>
63
+
64
+ == First Section
65
+
66
+ msc::msc.txt[format="svg"]
67
+ eos
68
+
69
+ d = load_asciidoc doc
70
+ expect(d).to_not be_nil
71
+
72
+ b = d.find { |bl| bl.context == :image }
73
+ expect(b).to_not be_nil
74
+
75
+ expect(b.content_model).to eq :empty
76
+
77
+ target = b.attributes['target']
78
+ expect(target).to_not be_nil
79
+ expect(target).to match(/\.svg/)
80
+ expect(File.exist?(target)).to be true
81
+
82
+ expect(b.attributes['width']).to_not be_nil
83
+ expect(b.attributes['height']).to_not be_nil
84
+ end
85
+ end
86
+
87
+ describe Asciidoctor::Diagram::MscBlockProcessor, :broken_on_windows do
88
+ it "should generate PNG images when format is set to 'png'" do
89
+ doc = <<-eos
90
+ = Hello, Msc!
91
+ Doc Writer <doc@example.com>
92
+
93
+ == First Section
94
+
95
+ [msc, format="png"]
96
+ ----
97
+ #{code}
98
+ ----
99
+ eos
100
+
101
+ d = load_asciidoc doc
102
+ expect(d).to_not be_nil
103
+
104
+ b = d.find { |bl| bl.context == :image }
105
+ expect(b).to_not be_nil
106
+
107
+ expect(b.content_model).to eq :empty
108
+
109
+ target = b.attributes['target']
110
+ expect(target).to_not be_nil
111
+ expect(target).to match(/\.png$/)
112
+ expect(File.exist?(target)).to be true
113
+
114
+ expect(b.attributes['width']).to_not be_nil
115
+ expect(b.attributes['height']).to_not be_nil
116
+ end
117
+
118
+ it "should generate SVG images when format is set to 'svg'" do
119
+ doc = <<-eos
120
+ = Hello, Msc!
121
+ Doc Writer <doc@example.com>
122
+
123
+ == First Section
124
+
125
+ [msc, format="svg"]
126
+ ----
127
+ #{code}
128
+ ----
129
+ eos
130
+
131
+ d = load_asciidoc doc
132
+ expect(d).to_not be_nil
133
+
134
+ b = d.find { |bl| bl.context == :image }
135
+ expect(b).to_not be_nil
136
+
137
+ expect(b.content_model).to eq :empty
138
+
139
+ target = b.attributes['target']
140
+ expect(target).to_not be_nil
141
+ expect(target).to match(/\.svg/)
142
+ expect(File.exist?(target)).to be true
143
+
144
+ expect(b.attributes['width']).to_not be_nil
145
+ expect(b.attributes['height']).to_not be_nil
146
+ end
147
+
148
+ it "should raise an error when when format is set to an invalid value" do
149
+ doc = <<-eos
150
+ = Hello, Msc!
151
+ Doc Writer <doc@example.com>
152
+
153
+ == First Section
154
+
155
+ [msc, format="foobar"]
156
+ ----
157
+ ----
158
+ eos
159
+
160
+ expect { load_asciidoc doc }.to raise_error(/support.*format/i)
161
+ end
162
+
163
+ it "should not regenerate images when source has not changed" do
164
+ File.write('msc.txt', code)
165
+
166
+ doc = <<-eos
167
+ = Hello, Msc!
168
+ Doc Writer <doc@example.com>
169
+
170
+ == First Section
171
+
172
+ msc::msc.txt
173
+
174
+ [msc, format="png"]
175
+ ----
176
+ #{code}
177
+ ----
178
+ eos
179
+
180
+ d = load_asciidoc doc
181
+ b = d.find { |bl| bl.context == :image }
182
+ expect(b).to_not be_nil
183
+ target = b.attributes['target']
184
+ mtime1 = File.mtime(target)
185
+
186
+ sleep 1
187
+
188
+ d = load_asciidoc doc
189
+
190
+ mtime2 = File.mtime(target)
191
+
192
+ expect(mtime2).to eq mtime1
193
+ end
194
+
195
+ it "should handle two block macros with the same source" do
196
+ File.write('msc.txt', code)
197
+
198
+ doc = <<-eos
199
+ = Hello, Msc!
200
+ Doc Writer <doc@example.com>
201
+
202
+ == First Section
203
+
204
+ msc::msc.txt[]
205
+ msc::msc.txt[]
206
+ eos
207
+
208
+ load_asciidoc doc
209
+ expect(File.exist?('msc.png')).to be true
210
+ end
211
+
212
+ it "should respect target attribute in block macros" do
213
+ File.write('msc.txt', code)
214
+
215
+ doc = <<-eos
216
+ = Hello, Msc!
217
+ Doc Writer <doc@example.com>
218
+
219
+ == First Section
220
+
221
+ msc::msc.txt["foobar"]
222
+ msc::msc.txt["foobaz"]
223
+ eos
224
+
225
+ load_asciidoc doc
226
+ expect(File.exist?('foobar.png')).to be true
227
+ expect(File.exist?('foobaz.png')).to be true
228
+ expect(File.exist?('msc.png')).to be false
229
+ end
230
+ end
@@ -73,7 +73,7 @@ plantuml::plantuml.txt[format="png"]
73
73
  expect(b.attributes['height']).to_not be_nil
74
74
  end
75
75
 
76
- it 'should support substitutions' do
76
+ it 'should support substitutions in diagram code' do
77
77
  code = <<-eos
78
78
  class {parent-class}
79
79
  class {child-class}
@@ -102,7 +102,7 @@ plantuml::plantuml.txt[format="svg", subs=attributes+]
102
102
  target = b.attributes['target']
103
103
  expect(File.exist?(target)).to be true
104
104
 
105
- content = File.read(target)
105
+ content = File.read(target, :encoding => Encoding::UTF_8)
106
106
  expect(content).to include('ParentClass')
107
107
  expect(content).to include('ChildClass')
108
108
  end
@@ -137,11 +137,45 @@ plantuml::{file}.txt[format="svg", subs=attributes+]
137
137
  target = b.attributes['target']
138
138
  expect(File.exist?(target)).to be true
139
139
 
140
- content = File.read(target)
140
+ content = File.read(target, :encoding => Encoding::UTF_8)
141
141
  expect(content).to include('ParentClass')
142
142
  expect(content).to include('ChildClass')
143
143
  end
144
144
 
145
+ it 'should support substitutions in the format attribute' do
146
+ code = <<-eos
147
+ class Parent
148
+ class Child
149
+ Parent <|-- Child
150
+ eos
151
+
152
+ File.write('plantuml.txt', code)
153
+
154
+ doc = <<-eos
155
+ = Hello, PlantUML!
156
+ Doc Writer <doc@example.com>
157
+ :file: plantuml
158
+ :plantumlformat: png
159
+
160
+ == First Section
161
+
162
+ plantuml::{file}.txt[format="{plantumlformat}", subs=attributes+]
163
+ eos
164
+
165
+ d = load_asciidoc doc, :attributes => {'backend' => 'html5'}
166
+ expect(d).to_not be_nil
167
+
168
+ b = d.find { |bl| bl.context == :image }
169
+ expect(b).to_not be_nil
170
+
171
+ target = b.attributes['target']
172
+ expect(target).to match(/\.png$/)
173
+ expect(File.exist?(target)).to be true
174
+
175
+ expect(b.attributes['width']).to_not be_nil
176
+ expect(b.attributes['height']).to_not be_nil
177
+ end
178
+
145
179
  it 'should resolve !include directives with relative paths' do
146
180
  included = <<-eos
147
181
  interface List
@@ -166,12 +200,50 @@ Doc Writer <doc@example.com>
166
200
 
167
201
  == First Section
168
202
 
169
- plantuml::dir/plantuml.txt[format="png", subs=attributes+]
203
+ plantuml::dir/plantuml.txt[format="svg", subs=attributes+]
170
204
  eos
171
205
 
172
- load_asciidoc doc, :attributes => {'backend' => 'html5'}
206
+ d = load_asciidoc doc, :attributes => {'backend' => 'html5'}
207
+
208
+ expect(d).to_not be_nil
209
+
210
+ b = d.find { |bl| bl.context == :image }
211
+ expect(b).to_not be_nil
212
+
213
+ target = b.attributes['target']
214
+ expect(File.exist?(target)).to be true
173
215
 
174
- # No easy way to assert this since PlantUML doesn't produce an error on file not found
216
+ content = File.read(target, :encoding => Encoding::UTF_8)
217
+ expect(content).to_not include('!include')
218
+ end
219
+
220
+ it 'should generate blocks with figure captions' do
221
+ code = <<-eos
222
+ User -> (Start)
223
+ User --> (Use the application) : Label
224
+
225
+ :Main Admin: ---> (Use the application) : Another label
226
+ eos
227
+
228
+ File.write('plantuml.txt', code)
229
+
230
+ doc = <<-eos
231
+ = Hello, PlantUML!
232
+ Doc Writer <doc@example.com>
233
+
234
+ == First Section
235
+
236
+ .This is a UML diagram
237
+ plantuml::plantuml.txt[format="png"]
238
+ eos
239
+
240
+ d = load_asciidoc doc
241
+ expect(d).to_not be_nil
242
+
243
+ b = d.find { |bl| bl.context == :image }
244
+ expect(b).to_not be_nil
245
+
246
+ expect(b.caption).to match /Figure \d+/
175
247
  end
176
248
  end
177
249
 
@@ -288,11 +360,12 @@ Doc Writer <doc@example.com>
288
360
  doc = <<-eos
289
361
  = Hello, PlantUML!
290
362
  Doc Writer <doc@example.com>
291
- :plantumlconfig: test.config
363
+ :plantuml-config: test.config
364
+ :plantuml-format: svg
292
365
 
293
366
  == First Section
294
367
 
295
- [plantuml, format="svg"]
368
+ [plantuml]
296
369
  ----
297
370
  actor Foo1
298
371
  boundary Foo2
@@ -315,7 +388,7 @@ ArrowColor #DEADBE
315
388
  expect(target).to_not be_nil
316
389
  expect(File.exist?(target)).to be true
317
390
 
318
- svg = File.read(target)
391
+ svg = File.read(target, :encoding => Encoding::UTF_8)
319
392
  expect(svg).to match(/<path.*fill="#DEADBE"/)
320
393
  end
321
394
 
@@ -510,6 +583,29 @@ User -> (Start)
510
583
  expect(b.attributes['height']).to be_nil
511
584
  end
512
585
 
586
+ it 'should generate blocks with figure captions' do
587
+ doc = <<-eos
588
+ = Hello, PlantUML!
589
+ Doc Writer <doc@example.com>
590
+
591
+ == First Section
592
+
593
+ .Caption for my UML diagram
594
+ [plantuml, format="png"]
595
+ ----
596
+ User -> (Start)
597
+ ----
598
+ eos
599
+
600
+ d = load_asciidoc doc
601
+ expect(d).to_not be_nil
602
+
603
+ b = d.find { |bl| bl.context == :image }
604
+ expect(b).to_not be_nil
605
+
606
+ expect(b.caption).to match /Figure \d+/
607
+ end
608
+
513
609
  it 'should support salt diagrams using salt block type' do
514
610
  doc = <<-eos
515
611
  = Hello, PlantUML!
@@ -683,7 +779,7 @@ List : void clear()
683
779
  eos
684
780
 
685
781
  Dir.mkdir('dir')
686
- File.write('dir/list.iuml', included)
782
+ File.write('dir/List.iuml', included)
687
783
 
688
784
  creole_doc = <<-eos
689
785
  = Hello, PlantUML!
@@ -691,16 +787,25 @@ Doc Writer <doc@example.com>
691
787
 
692
788
  == First Section
693
789
 
694
- [plantuml, format="png"]
790
+ [plantuml, format="svg"]
695
791
  ----
696
792
  !include dir/List.iuml
697
793
  List <|.. ArrayList
698
794
  ----
699
795
  eos
700
796
 
701
- load_asciidoc creole_doc, :attributes => {'backend' => 'html5'}
797
+ d = load_asciidoc creole_doc, :attributes => {'backend' => 'html5'}
798
+
799
+ expect(d).to_not be_nil
800
+
801
+ b = d.find { |bl| bl.context == :image }
802
+ expect(b).to_not be_nil
803
+
804
+ target = b.attributes['target']
805
+ expect(File.exist?(target)).to be true
702
806
 
703
- # No easy way to assert this since PlantUML doesn't produce an error on file not found
807
+ content = File.read(target, :encoding => Encoding::UTF_8)
808
+ expect(content).to_not include('!include')
704
809
  end
705
810
 
706
811
  it 'should support substitutions' do
@@ -726,7 +831,7 @@ class {child-class}
726
831
  target = b.attributes['target']
727
832
  expect(File.exist?(target)).to be true
728
833
 
729
- content = File.read(target)
834
+ content = File.read(target, :encoding => Encoding::UTF_8)
730
835
  expect(content).to include('ParentClass')
731
836
  expect(content).to include('ChildClass')
732
837
  end