asciidoctor-plantuml 0.0.12 → 0.0.16

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0eec1ab5b66560c09d54f1c5a44f4ca764b41fd8112a2c1ba791de3936ff4d8
4
- data.tar.gz: a806b6892710155ae5d36aee9e3fe0830f30d4606ec8c6b27b3533187f389f80
3
+ metadata.gz: fe7b55f293e7f815c3107f7cb42b8118b2f5cbcc2d46ddc04c003c8e855ae2ff
4
+ data.tar.gz: ded1cc190a25eca2b172fc459a4f77d4f629e484f0112b5d1693686433d2197c
5
5
  SHA512:
6
- metadata.gz: d4924630cd2c797eed3741a6f1b70c2f8eba15b781884a7b76934d090869570615712dd637be42d472610acbf4ea13894c07319c059a213aa9a3c2559e4ac305
7
- data.tar.gz: 4243885ff01513113b5e34412532196b708250cba696c0c094b7a77cb96c656b2302a60aabd37589a6ee398df401506b76cb929ed3ac5631efa54928af580dce
6
+ metadata.gz: ce55a9ec6de14f336fb5330b2a0f5d9369236c8c213fa306a59ba0f14aaddab50a40412ffc3156b16bb6e742ba8b50238f4c06768e22b7def34eedea9d4da0e9
7
+ data.tar.gz: 9aa54dd2b91d173bf8225581bacb82cc2c6b2d8316ceea4f948959cb8696acb0f7f045b01c9f97a80c2476a3d7bc20fae75099c51936420c3763e581bc1bb379
@@ -3,7 +3,6 @@
3
3
  require 'uri'
4
4
  require 'open-uri'
5
5
  require 'zlib'
6
- require 'open-uri'
7
6
  require 'net/http'
8
7
 
9
8
  module Asciidoctor
@@ -11,8 +10,8 @@ module Asciidoctor
11
10
  module PlantUml
12
11
  # PlantUML Configuration
13
12
  class Configuration
14
- DEFAULT_URL = ENV['PLANTUML_URL'] || ''
15
- DEFAULT_ENCODING = ENV['PLANTUML_ENCODING'] || 'legacy'
13
+ DEFAULT_URL = ENV.fetch('PLANTUML_URL', '')
14
+ DEFAULT_ENCODING = ENV.fetch('PLANTUML_ENCODING', 'legacy')
16
15
 
17
16
  attr_accessor :url, :txt_enable, :svg_enable, :png_enable, :encoding
18
17
 
@@ -80,10 +79,9 @@ module Asciidoctor
80
79
  end
81
80
 
82
81
  def plantuml_content_format(code, format, attrs = {})
83
- if %w[png svg].include?(format)
84
- plantuml_img_content(code, format, attrs)
85
- elsif format == 'txt' && txt_enabled?
86
- plantuml_txt_content(code, format, attrs)
82
+ if %w[png svg txt].include?(format) &&
83
+ method("#{format}_enabled?").call
84
+ method("plantuml_#{format}_content").call(code, format, attrs)
87
85
  else
88
86
  plantuml_invalid_content(format, attrs)
89
87
  end
@@ -94,9 +92,7 @@ module Asciidoctor
94
92
 
95
93
  return plantuml_disabled_content(code, attrs) unless enabled?
96
94
 
97
- unless valid_uri?(server_url)
98
- return plantuml_server_unavailable_content(server_url, attrs)
99
- end
95
+ return plantuml_server_unavailable_content(server_url, attrs) unless valid_uri?(server_url)
100
96
 
101
97
  plantuml_content_format(code, format, attrs)
102
98
  end
@@ -125,7 +121,7 @@ module Asciidoctor
125
121
  plantuml_ascii_content(f.read, attrs)
126
122
  end
127
123
  rescue OpenURI::HTTPError, Errno::ECONNREFUSED, SocketError
128
- plantuml_img_content(code, format, attrs)
124
+ plantuml_png_content(code, format, attrs)
129
125
  end
130
126
 
131
127
  def plantuml_ascii_content(code, attrs = {})
@@ -140,7 +136,7 @@ module Asciidoctor
140
136
  content + '</div>'
141
137
  end
142
138
 
143
- def plantuml_img_content(code, format, attrs = {})
139
+ def plantuml_png_content(code, format, attrs = {})
144
140
  content = '<div class="imageblock">'
145
141
  content += '<div class="content">'
146
142
  content += '<img '
@@ -154,37 +150,43 @@ module Asciidoctor
154
150
  content + '</div>'
155
151
  end
156
152
 
157
- def plantuml_invalid_content(format, attrs = {})
158
- content = '<div class="listingblock">'
153
+ def plantuml_svg_content(code, format, attrs = {})
154
+ content = '<div class="imageblock">'
159
155
  content += '<div class="content">'
160
- content += '<pre '
156
+ content += '<object type="image/svg+xml" '
157
+ content += "data=\"#{gen_url(code, format)}\" "
161
158
  content += "id=\"#{attrs['id']}\" " if attrs['id']
162
- content += 'class="plantuml plantuml-error"> '
163
- content += "PlantUML Error: Invalid format \"#{format}\""
164
- content += '</pre>'
159
+ content += "width=\"#{attrs['width']}\" " if attrs['width']
160
+ content += "height=\"#{attrs['height']}\" " if attrs['height']
161
+ content += '>'
162
+ attrs['id'] = 'fallback_' + attrs['id'] if attrs['id']
163
+ content += plantuml_png_content(code, format, attrs)
164
+ content += '</object>'
165
165
  content += '</div>'
166
166
  content + '</div>'
167
167
  end
168
168
 
169
+ def plantuml_invalid_content(format, attrs = {})
170
+ error = "PlantUML Error: Invalid format \"#{format}\""
171
+ _plantuml_error_content(error, attrs)
172
+ end
173
+
169
174
  def plantuml_server_unavailable_content(url, attrs = {})
170
- content = '<div class="listingblock">'
171
- content += '<div class="content">'
172
- content += '<pre '
173
- content += "id=\"#{attrs['id']}\" " if attrs['id']
174
- content += 'class="plantuml plantuml-error"> '
175
- content += "Error: cannot connect to PlantUML server at \"#{url}\""
176
- content += '</pre>'
177
- content += '</div>'
178
- content + '</div>'
175
+ error = "Error: cannot connect to PlantUML server at \"#{url}\""
176
+ _plantuml_error_content(error, attrs)
179
177
  end
180
178
 
181
179
  def plantuml_disabled_content(code, attrs = {})
180
+ _plantuml_error_content(code, attrs)
181
+ end
182
+
183
+ def _plantuml_error_content(error, attrs = {})
182
184
  content = '<div class="listingblock">'
183
185
  content += '<div class="content">'
184
186
  content += '<pre '
185
187
  content += "id=\"#{attrs['id']}\" " if attrs['id']
186
188
  content += 'class="plantuml plantuml-error">\n'
187
- content += code
189
+ content += error
188
190
  content += '</pre>'
189
191
  content += '</div>'
190
192
  content + '</div>'
@@ -244,11 +246,9 @@ module Asciidoctor
244
246
  end
245
247
 
246
248
  def expand_path(path, current, last, separator)
247
- path = path[1..-1] if path.start_with?(separator) && current.zero?
249
+ path = path[1..] if path.start_with?(separator) && current.zero?
248
250
 
249
- unless path.end_with?(separator) || current == last
250
- path = [path, separator]
251
- end
251
+ path = [path, separator] unless path.end_with?(separator) || current == last
252
252
 
253
253
  path
254
254
  end
@@ -259,15 +259,13 @@ module Asciidoctor
259
259
  class BlockProcessor < Asciidoctor::Extensions::BlockProcessor
260
260
  use_dsl
261
261
  named :plantuml
262
- on_context :listing
262
+ on_context :listing, :literal
263
263
  content_model :simple
264
264
 
265
265
  def process(parent, target, attrs)
266
266
  lines = target.lines
267
267
 
268
- unless target.lines[0] =~ /@startuml/
269
- lines = ['@startuml'] + target.lines
270
- end
268
+ lines = ['@startuml'] + target.lines unless target.lines[0] =~ /@startuml/
271
269
 
272
270
  lines += ['@enduml'] unless target.lines[-1] =~ /@enduml/
273
271
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Asciidoctor
4
4
  module PlantUML
5
- VERSION = '0.0.12'
5
+ VERSION = '0.0.16'
6
6
  end
7
7
  end
@@ -17,6 +17,17 @@ DOC_BASIC = <<~ENDOFSTRING
17
17
  ----
18
18
  ENDOFSTRING
19
19
 
20
+ DOC_BASIC_LITERAL = <<~ENDOFSTRING
21
+ = Hello PlantUML!
22
+
23
+ [plantuml, format="png"]
24
+ .Title Of this
25
+ ....
26
+ User -> (Start)
27
+ User --> (Use the application) : Label
28
+ ....
29
+ ENDOFSTRING
30
+
20
31
  DOC_BASIC2 = <<~ENDOFSTRING
21
32
  = Hello PlantUML!
22
33
 
@@ -31,6 +42,20 @@ DOC_BASIC2 = <<~ENDOFSTRING
31
42
  ----
32
43
  ENDOFSTRING
33
44
 
45
+ DOC_BASIC2_LITERAL = <<~ENDOFSTRING
46
+ = Hello PlantUML!
47
+
48
+ [plantuml, format="png"]
49
+ .Title Of this
50
+ [[fig-xref]]
51
+ ....
52
+ @startuml
53
+ User -> (Start)
54
+ User --> (Use the application) : Label
55
+ @enduml
56
+ ....
57
+ ENDOFSTRING
58
+
34
59
  DOC_BASIC3 = <<~ENDOFSTRING
35
60
  = Hello Compound PlantUML!
36
61
 
@@ -43,6 +68,18 @@ DOC_BASIC3 = <<~ENDOFSTRING
43
68
  ----
44
69
  ENDOFSTRING
45
70
 
71
+ DOC_BASIC3_LITERAL = <<~ENDOFSTRING
72
+ = Hello Compound PlantUML!
73
+
74
+ [plantuml, format="png"]
75
+ ....
76
+ [COMP1]
77
+ [COMP2]
78
+ [COMP1] -> [COMP2]
79
+ [COMP2] --> [COMP3]
80
+ ....
81
+ ENDOFSTRING
82
+
46
83
  DOC_ID = <<~ENDOFSTRING
47
84
  = Hello PlantUML!
48
85
 
@@ -105,6 +142,28 @@ DOC_MULTI = <<~ENDOFSTRING
105
142
  ----
106
143
  ENDOFSTRING
107
144
 
145
+ DOC_MULTI_LITERAL = <<~ENDOFSTRING
146
+ = Hello PlantUML!
147
+
148
+ [plantuml, format="png"]
149
+ ....
150
+ User -> (Start)
151
+ User --> (Use the application) : Label
152
+ ....
153
+
154
+ [plantuml, format="png"]
155
+ ....
156
+ User -> (Start)
157
+ User --> (Use the application) : Label
158
+ ....
159
+
160
+ [plantuml, format="txt"]
161
+ ....
162
+ User -> (Start)
163
+ User --> (Use the application) : Label
164
+ ....
165
+ ENDOFSTRING
166
+
108
167
  DOC_TXT = <<~ENDOFSTRING
109
168
  = Hello PlantUML!
110
169
 
@@ -115,15 +174,28 @@ DOC_TXT = <<~ENDOFSTRING
115
174
  ----
116
175
  ENDOFSTRING
117
176
 
177
+ DOC_SVG = <<~ENDOFSTRING
178
+ = Hello PlantUML!
179
+
180
+ [plantuml, format="svg"]
181
+ ----
182
+ User -> (Start)
183
+ User --> (Use the application) : Label
184
+ ----
185
+ ENDOFSTRING
186
+
118
187
  class PlantUmlTest < Test::Unit::TestCase
119
188
  GENURL = 'http://localhost:8080/plantuml/png/U9npA2v9B2efpStX2YrEBLBGjLFG20Q9Q4Bv804WIw4a8rKXiQ0W9pCviIGpFqzJmKh19p4fDOVB8JKl1QWT05kd5wq0'
120
189
  GENURL2 = 'http://localhost:8080/plantuml/png/U9npA2v9B2efpStXYdRszmqmZ8NGHh4mleAkdGAAa15G22Pc7Clba9gN0jGE00W75Cm0'
121
190
  GENURL_ENCODING = 'http://localhost:8080/plantuml/png/~1U9npA2v9B2efpStX2YrEBLBGjLFG20Q9Q4Bv804WIw4a8rKXiQ0W9pCviIGpFqzJmKh19p4fDOVB8JKl1QWT05kd5wq0'
191
+ SVGGENURL = 'http://localhost:8080/plantuml/svg/~1U9npA2v9B2efpStX2YrEBLBGjLFG20Q9Q4Bv804WIw4a8rKXiQ0W9pCviIGpFqzJmKh19p4fDOVB8JKl1QWT05kd5wq0'
122
192
 
123
193
  def setup
124
194
  Asciidoctor::PlantUml.configure do |c|
125
195
  c.url = 'http://localhost:8080/plantuml'
126
196
  c.txt_enable = true
197
+ c.png_enable = true
198
+ c.svg_enable = true
127
199
  end
128
200
  end
129
201
 
@@ -140,8 +212,40 @@ class PlantUmlTest < Test::Unit::TestCase
140
212
  assert_equal GENURL, element['src']
141
213
  end
142
214
 
215
+ def test_plantuml_block_literal_processor
216
+ html = ::Asciidoctor.convert(
217
+ StringIO.new(DOC_BASIC_LITERAL), backend: 'html5'
218
+ )
219
+ page = Nokogiri::HTML(html)
220
+
221
+ elements = page.css('img.plantuml')
222
+
223
+ assert_equal elements.size, 1
224
+
225
+ element = elements.first
226
+
227
+ assert_equal GENURL, element['src']
228
+ end
229
+
143
230
  def test_plantuml_block_processor2
144
- html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC2), backend: 'html5')
231
+ html = ::Asciidoctor.convert(
232
+ StringIO.new(DOC_BASIC2), backend: 'html5'
233
+ )
234
+ page = Nokogiri::HTML(html)
235
+
236
+ elements = page.css('img.plantuml')
237
+
238
+ assert_equal elements.size, 1
239
+
240
+ element = elements.first
241
+
242
+ assert_equal GENURL, element['src']
243
+ end
244
+
245
+ def test_plantuml_block_literal_processor2
246
+ html = ::Asciidoctor.convert(
247
+ StringIO.new(DOC_BASIC2_LITERAL), backend: 'html5'
248
+ )
145
249
  page = Nokogiri::HTML(html)
146
250
 
147
251
  elements = page.css('img.plantuml')
@@ -166,6 +270,21 @@ class PlantUmlTest < Test::Unit::TestCase
166
270
  assert_equal GENURL2, element['src']
167
271
  end
168
272
 
273
+ def test_plantuml_block_literal_processor3
274
+ html = ::Asciidoctor.convert(
275
+ StringIO.new(DOC_BASIC3_LITERAL), backend: 'html5'
276
+ )
277
+ page = Nokogiri::HTML(html)
278
+
279
+ elements = page.css('img.plantuml')
280
+
281
+ assert_equal elements.size, 1
282
+
283
+ element = elements.first
284
+
285
+ assert_equal GENURL2, element['src']
286
+ end
287
+
169
288
  def test_plantuml_block_processor_encoding
170
289
  Asciidoctor::PlantUml.configure do |c|
171
290
  c.encoding = 'deflate'
@@ -229,7 +348,7 @@ class PlantUmlTest < Test::Unit::TestCase
229
348
  assert_equal elements.size, 1
230
349
  end
231
350
 
232
- def test_plantuml_multiple
351
+ def test_plantuml_multiple_listing
233
352
  html = ::Asciidoctor.convert(StringIO.new(DOC_MULTI), backend: 'html5')
234
353
  page = Nokogiri::HTML(html)
235
354
 
@@ -240,6 +359,19 @@ class PlantUmlTest < Test::Unit::TestCase
240
359
  assert_equal elements.size, 0
241
360
  end
242
361
 
362
+ def test_plantuml_multiple_literal
363
+ html = ::Asciidoctor.convert(
364
+ StringIO.new(DOC_MULTI_LITERAL), backend: 'html5'
365
+ )
366
+ page = Nokogiri::HTML(html)
367
+
368
+ elements = page.css('img.plantuml')
369
+ assert elements.size >= 2
370
+
371
+ elements = page.css('.plantuml-error')
372
+ assert_equal elements.size, 0
373
+ end
374
+
243
375
  def test_plantuml_bad_server
244
376
  Asciidoctor::PlantUml.configure do |c|
245
377
  c.url = 'http://nonexistent.com/plantuml'
@@ -299,4 +431,44 @@ class PlantUmlTest < Test::Unit::TestCase
299
431
  elements = page.css('pre.plantuml-error')
300
432
  assert_equal elements.size, 1
301
433
  end
434
+
435
+ def test_svg
436
+ Asciidoctor::PlantUml.configure do |c|
437
+ c.url = 'http://localhost:8080/plantuml'
438
+ c.svg_enable = true
439
+ end
440
+
441
+ html = ::Asciidoctor.convert(StringIO.new(DOC_SVG), backend: 'html5')
442
+ page = Nokogiri::HTML(html)
443
+ elements = page.css("object[type='image/svg+xml']")
444
+ assert_equal elements.size, 1
445
+
446
+ element = elements.first
447
+
448
+ assert_equal SVGGENURL, element['data']
449
+ end
450
+
451
+ def test_disable_svg
452
+ Asciidoctor::PlantUml.configure do |c|
453
+ c.url = 'http://localhost:8080/plantuml'
454
+ c.svg_enable = false
455
+ end
456
+
457
+ html = ::Asciidoctor.convert(StringIO.new(DOC_SVG), backend: 'html5')
458
+ page = Nokogiri::HTML(html)
459
+ elements = page.css('pre.plantuml-error')
460
+ assert_equal elements.size, 1
461
+ end
462
+
463
+ def test_disable_png
464
+ Asciidoctor::PlantUml.configure do |c|
465
+ c.url = 'http://localhost:8080/plantuml'
466
+ c.png_enable = false
467
+ end
468
+
469
+ html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC_LITERAL), backend: 'html5')
470
+ page = Nokogiri::HTML(html)
471
+ elements = page.css('pre.plantuml-error')
472
+ assert_equal elements.size, 1
473
+ end
302
474
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-plantuml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Horacio Sanson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-11 00:00:00.000000000 Z
11
+ date: 2022-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '2.2'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '2.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.6'
33
+ version: 1.13.4
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.6'
40
+ version: 1.13.4
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,35 +58,35 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.66'
61
+ version: '1.28'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.66'
68
+ version: '1.28'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: test-unit
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '3.3'
75
+ version: '3.5'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '3.3'
82
+ version: '3.5'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: asciidoctor
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 1.5.6
89
+ version: 2.0.17
90
90
  - - "<"
91
91
  - !ruby/object:Gem::Version
92
92
  version: 3.0.0
@@ -96,7 +96,7 @@ dependencies:
96
96
  requirements:
97
97
  - - ">="
98
98
  - !ruby/object:Gem::Version
99
- version: 1.5.6
99
+ version: 2.0.17
100
100
  - - "<"
101
101
  - !ruby/object:Gem::Version
102
102
  version: 3.0.0
@@ -114,7 +114,8 @@ files:
114
114
  homepage: https://github.com/hsanson/asciidoctor-plantuml
115
115
  licenses:
116
116
  - MIT
117
- metadata: {}
117
+ metadata:
118
+ rubygems_mfa_required: 'true'
118
119
  post_install_message:
119
120
  rdoc_options: []
120
121
  require_paths:
@@ -123,15 +124,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
124
  requirements:
124
125
  - - ">="
125
126
  - !ruby/object:Gem::Version
126
- version: '2.3'
127
+ version: '2.6'
127
128
  required_rubygems_version: !ruby/object:Gem::Requirement
128
129
  requirements:
129
130
  - - ">="
130
131
  - !ruby/object:Gem::Version
131
132
  version: '0'
132
133
  requirements: []
133
- rubyforge_project:
134
- rubygems_version: 2.7.6
134
+ rubygems_version: 3.1.2
135
135
  signing_key:
136
136
  specification_version: 4
137
137
  summary: Asciidoctor support for PlantUML diagrams.