asciidoctor-plantuml 0.0.11 → 0.0.15

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: b550934d0e6408099c74544fa93071a1c04f64392353e1a11a7388d1a897bc8a
4
- data.tar.gz: cd0627162cf7f60af7d2b9fc2e4a7edd20c36ac429e4e7340129281968a14422
3
+ metadata.gz: 7673d42a2b0bcc381cb0111511bfc05584ed0c509dfad8dcf9b20919b9d8b689
4
+ data.tar.gz: 2a8c98b8a3adfc09e57a7928e9f23a86230072da14ca9a9593d627401f40d194
5
5
  SHA512:
6
- metadata.gz: 5d9131c6af8a5be72c7732afe20ac2fd9fd874c22774dafe0cfc37be4c94941d8ab3a1bddacdb973e9a4e7bff6b45a76c6d69b5bd9136375104d9415fff4cb0b
7
- data.tar.gz: 8a200585455b8937b6d4f2f7772d3f77321c38de64633a81b2525c38b5e55050f6948870b2010b829cb8b8ce0fb912f77f5e9792a9cd0e548f58e7f93fe4bc07
6
+ metadata.gz: 9ed82c582714d60f1a0cf57d5bbb070250dc07744a7545b28912d2e4e97f13ceff292d3d528df7f23ea683e4bfbd1cd6ce5c2500f1b8fb2b274429395fede02c
7
+ data.tar.gz: 78e840faff576976ecdf0d1584d0e9b86d07a8afed74c7248f210d7bd306a25c1c67c1bb41165d2e54b559d02f122d0cc8c8d960c989b0a3a0fc057f32e4d600
@@ -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
@@ -12,14 +11,16 @@ module Asciidoctor
12
11
  # PlantUML Configuration
13
12
  class Configuration
14
13
  DEFAULT_URL = ENV['PLANTUML_URL'] || ''
14
+ DEFAULT_ENCODING = ENV['PLANTUML_ENCODING'] || 'legacy'
15
15
 
16
- attr_accessor :url, :txt_enable, :svg_enable, :png_enable
16
+ attr_accessor :url, :txt_enable, :svg_enable, :png_enable, :encoding
17
17
 
18
18
  def initialize
19
19
  @url = DEFAULT_URL
20
20
  @txt_enable = true
21
21
  @svg_enable = true
22
22
  @png_enable = true
23
+ @encoding = DEFAULT_ENCODING
23
24
  end
24
25
  end
25
26
 
@@ -39,6 +40,13 @@ module Asciidoctor
39
40
  class Processor
40
41
  FORMATS = %w[png svg txt].freeze
41
42
  DEFAULT_FORMAT = FORMATS[0]
43
+
44
+ ENCODINGS = %w[legacy deflate].freeze
45
+ DEFAULT_ENCODING = ENCODINGS[0]
46
+
47
+ ENCODINGS_MAGIC_STRINGS_MAP = Hash.new('')
48
+ ENCODINGS_MAGIC_STRINGS_MAP['deflate'] = '~1'
49
+
42
50
  URI_SCHEMES_REGEXP = ::URI::DEFAULT_PARSER.make_regexp(%w[http https])
43
51
 
44
52
  class << self
@@ -46,6 +54,10 @@ module Asciidoctor
46
54
  FORMATS.include?(format)
47
55
  end
48
56
 
57
+ def valid_encoding?(encoding)
58
+ ENCODINGS.include?(encoding)
59
+ end
60
+
49
61
  def server_url
50
62
  PlantUml.configuration.url
51
63
  end
@@ -67,10 +79,9 @@ module Asciidoctor
67
79
  end
68
80
 
69
81
  def plantuml_content_format(code, format, attrs = {})
70
- if %w[png svg].include?(format)
71
- plantuml_img_content(code, format, attrs)
72
- elsif format == 'txt' && txt_enabled?
73
- 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)
74
85
  else
75
86
  plantuml_invalid_content(format, attrs)
76
87
  end
@@ -81,9 +92,7 @@ module Asciidoctor
81
92
 
82
93
  return plantuml_disabled_content(code, attrs) unless enabled?
83
94
 
84
- unless valid_uri?(server_url)
85
- return plantuml_server_unavailable_content(server_url, attrs)
86
- end
95
+ return plantuml_server_unavailable_content(server_url, attrs) unless valid_uri?(server_url)
87
96
 
88
97
  plantuml_content_format(code, format, attrs)
89
98
  end
@@ -92,6 +101,7 @@ module Asciidoctor
92
101
  # the transcoder class in the PlantUML java code.
93
102
  def gen_url(text, format)
94
103
  result = ''
104
+ result += encoding_magic_prefix
95
105
  compressed_data = Zlib::Deflate.deflate(text)
96
106
  compressed_data.chars.each_slice(3) do |bytes|
97
107
  # print bytes[0], ' ' , bytes[1] , ' ' , bytes[2]
@@ -111,7 +121,7 @@ module Asciidoctor
111
121
  plantuml_ascii_content(f.read, attrs)
112
122
  end
113
123
  rescue OpenURI::HTTPError, Errno::ECONNREFUSED, SocketError
114
- plantuml_img_content(code, format, attrs)
124
+ plantuml_png_content(code, format, attrs)
115
125
  end
116
126
 
117
127
  def plantuml_ascii_content(code, attrs = {})
@@ -126,7 +136,7 @@ module Asciidoctor
126
136
  content + '</div>'
127
137
  end
128
138
 
129
- def plantuml_img_content(code, format, attrs = {})
139
+ def plantuml_png_content(code, format, attrs = {})
130
140
  content = '<div class="imageblock">'
131
141
  content += '<div class="content">'
132
142
  content += '<img '
@@ -140,37 +150,43 @@ module Asciidoctor
140
150
  content + '</div>'
141
151
  end
142
152
 
143
- def plantuml_invalid_content(format, attrs = {})
144
- content = '<div class="listingblock">'
153
+ def plantuml_svg_content(code, format, attrs = {})
154
+ content = '<div class="imageblock">'
145
155
  content += '<div class="content">'
146
- content += '<pre '
156
+ content += '<object type="image/svg+xml" '
157
+ content += "data=\"#{gen_url(code, format)}\" "
147
158
  content += "id=\"#{attrs['id']}\" " if attrs['id']
148
- content += 'class="plantuml plantuml-error"> '
149
- content += "PlantUML Error: Invalid format \"#{format}\""
150
- 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>'
151
165
  content += '</div>'
152
166
  content + '</div>'
153
167
  end
154
168
 
169
+ def plantuml_invalid_content(format, attrs = {})
170
+ error = "PlantUML Error: Invalid format \"#{format}\""
171
+ _plantuml_error_content(error, attrs)
172
+ end
173
+
155
174
  def plantuml_server_unavailable_content(url, attrs = {})
156
- content = '<div class="listingblock">'
157
- content += '<div class="content">'
158
- content += '<pre '
159
- content += "id=\"#{attrs['id']}\" " if attrs['id']
160
- content += 'class="plantuml plantuml-error"> '
161
- content += "Error: cannot connect to PlantUML server at \"#{url}\""
162
- content += '</pre>'
163
- content += '</div>'
164
- content + '</div>'
175
+ error = "Error: cannot connect to PlantUML server at \"#{url}\""
176
+ _plantuml_error_content(error, attrs)
165
177
  end
166
178
 
167
179
  def plantuml_disabled_content(code, attrs = {})
180
+ _plantuml_error_content(code, attrs)
181
+ end
182
+
183
+ def _plantuml_error_content(error, attrs = {})
168
184
  content = '<div class="listingblock">'
169
185
  content += '<div class="content">'
170
186
  content += '<pre '
171
187
  content += "id=\"#{attrs['id']}\" " if attrs['id']
172
188
  content += 'class="plantuml plantuml-error">\n'
173
- content += code
189
+ content += error
174
190
  content += '</pre>'
175
191
  content += '</div>'
176
192
  content + '</div>'
@@ -204,6 +220,10 @@ module Asciidoctor
204
220
  encode6bit(c4 & 0x3F).chr
205
221
  end
206
222
 
223
+ def encoding_magic_prefix
224
+ ENCODINGS_MAGIC_STRINGS_MAP[PlantUml.configuration.encoding]
225
+ end
226
+
207
227
  # Make a call to the PlantUML server with the simplest diagram possible
208
228
  # to check if the server is available or not.
209
229
  def check_server(check_url)
@@ -228,9 +248,7 @@ module Asciidoctor
228
248
  def expand_path(path, current, last, separator)
229
249
  path = path[1..-1] if path.start_with?(separator) && current.zero?
230
250
 
231
- unless path.end_with?(separator) || current == last
232
- path = [path, separator]
233
- end
251
+ path = [path, separator] unless path.end_with?(separator) || current == last
234
252
 
235
253
  path
236
254
  end
@@ -241,15 +259,13 @@ module Asciidoctor
241
259
  class BlockProcessor < Asciidoctor::Extensions::BlockProcessor
242
260
  use_dsl
243
261
  named :plantuml
244
- on_context :listing
262
+ on_context :listing, :literal
245
263
  content_model :simple
246
264
 
247
265
  def process(parent, target, attrs)
248
266
  lines = target.lines
249
267
 
250
- unless target.lines[0] =~ /@startuml/
251
- lines = ['@startuml'] + target.lines
252
- end
268
+ lines = ['@startuml'] + target.lines unless target.lines[0] =~ /@startuml/
253
269
 
254
270
  lines += ['@enduml'] unless target.lines[-1] =~ /@enduml/
255
271
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Asciidoctor
4
4
  module PlantUML
5
- VERSION = '0.0.11'
5
+ VERSION = '0.0.15'
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,14 +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'
190
+ GENURL_ENCODING = 'http://localhost:8080/plantuml/png/~1U9npA2v9B2efpStX2YrEBLBGjLFG20Q9Q4Bv804WIw4a8rKXiQ0W9pCviIGpFqzJmKh19p4fDOVB8JKl1QWT05kd5wq0'
191
+ SVGGENURL = 'http://localhost:8080/plantuml/svg/~1U9npA2v9B2efpStX2YrEBLBGjLFG20Q9Q4Bv804WIw4a8rKXiQ0W9pCviIGpFqzJmKh19p4fDOVB8JKl1QWT05kd5wq0'
121
192
 
122
193
  def setup
123
194
  Asciidoctor::PlantUml.configure do |c|
124
195
  c.url = 'http://localhost:8080/plantuml'
125
196
  c.txt_enable = true
197
+ c.png_enable = true
198
+ c.svg_enable = true
126
199
  end
127
200
  end
128
201
 
@@ -139,8 +212,40 @@ class PlantUmlTest < Test::Unit::TestCase
139
212
  assert_equal GENURL, element['src']
140
213
  end
141
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
+
142
230
  def test_plantuml_block_processor2
143
- 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
+ )
144
249
  page = Nokogiri::HTML(html)
145
250
 
146
251
  elements = page.css('img.plantuml')
@@ -165,6 +270,38 @@ class PlantUmlTest < Test::Unit::TestCase
165
270
  assert_equal GENURL2, element['src']
166
271
  end
167
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
+
288
+ def test_plantuml_block_processor_encoding
289
+ Asciidoctor::PlantUml.configure do |c|
290
+ c.encoding = 'deflate'
291
+ end
292
+
293
+ html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC), backend: 'html5')
294
+ page = Nokogiri::HTML(html)
295
+
296
+ elements = page.css('img.plantuml')
297
+
298
+ assert_equal elements.size, 1
299
+
300
+ element = elements.first
301
+
302
+ assert_equal GENURL_ENCODING, element['src']
303
+ end
304
+
168
305
  def test_plantuml_id_attribute
169
306
  html = ::Asciidoctor.convert(StringIO.new(DOC_ID), backend: 'html5')
170
307
  page = Nokogiri::HTML(html)
@@ -211,7 +348,7 @@ class PlantUmlTest < Test::Unit::TestCase
211
348
  assert_equal elements.size, 1
212
349
  end
213
350
 
214
- def test_plantuml_multiple
351
+ def test_plantuml_multiple_listing
215
352
  html = ::Asciidoctor.convert(StringIO.new(DOC_MULTI), backend: 'html5')
216
353
  page = Nokogiri::HTML(html)
217
354
 
@@ -222,6 +359,19 @@ class PlantUmlTest < Test::Unit::TestCase
222
359
  assert_equal elements.size, 0
223
360
  end
224
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
+
225
375
  def test_plantuml_bad_server
226
376
  Asciidoctor::PlantUml.configure do |c|
227
377
  c.url = 'http://nonexistent.com/plantuml'
@@ -281,4 +431,44 @@ class PlantUmlTest < Test::Unit::TestCase
281
431
  elements = page.css('pre.plantuml-error')
282
432
  assert_equal elements.size, 1
283
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
284
474
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-plantuml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.15
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-03-01 00:00:00.000000000 Z
11
+ date: 2021-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: 2.2.10
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.10
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.11'
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.11'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.66'
61
+ version: '1.7'
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.7'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: test-unit
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -123,15 +123,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
123
  requirements:
124
124
  - - ">="
125
125
  - !ruby/object:Gem::Version
126
- version: '2.3'
126
+ version: '2.5'
127
127
  required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  requirements: []
133
- rubyforge_project:
134
- rubygems_version: 2.7.6
133
+ rubygems_version: 3.1.2
135
134
  signing_key:
136
135
  specification_version: 4
137
136
  summary: Asciidoctor support for PlantUML diagrams.