asciidoctor-plantuml 0.0.8 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c25b4e32ecf70068397ea52deddddd097660da66
4
- data.tar.gz: 9608a7e5e741c82d4a7dc778639acda1f4dd5df7
2
+ SHA256:
3
+ metadata.gz: de8d640d579d7d3c4171db4f02210fbe508868d8c70de10d4ce1a622bc8b14b1
4
+ data.tar.gz: a86d4afa322bf30c3f074c7c53e38dab0dcabf52df340ba685bae463143aa41f
5
5
  SHA512:
6
- metadata.gz: 14f45816129d36158f4c704c1950f4b6ab7b7a84dc0371b4904892d5fa1d763fe2a3306fb7a45ed2ba4512fab5ddfa3e6a8255114ae08ccc82a5897122e5d808
7
- data.tar.gz: 804afa9408568fb49611a736155e9d83723749d66e6f1a41c9470b73acfff91f88cb353e2b453d6b6485734019bc374fbe311006a1b229de540d7acd643bdfdb
6
+ metadata.gz: 5e81d9655d877bc2d53492d954f08e7176e5c8da48eb0ac82d693368092684781fb173ae8b36baacab5f71f974d12596036c9dd6fccd3c3752a7ebcfcafe1384
7
+ data.tar.gz: 69eba0374e2621ca0abbb100154fd8f4627e09bbd5192d09feea79315f16a7486309deb60c76042b174068b61de29ae6294d1ac001582391b8d03907dfea4422
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'asciidoctor'
2
4
  require 'asciidoctor/extensions'
3
- require_relative 'asciidoctor-plantuml/plantuml'
5
+ require_relative 'asciidoctor_plantuml/plantuml'
4
6
 
5
7
  Asciidoctor::Extensions.register do
6
8
  block Asciidoctor::PlantUml::BlockProcessor, :plantuml
@@ -0,0 +1,295 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+ require 'open-uri'
5
+ require 'zlib'
6
+ require 'open-uri'
7
+ require 'net/http'
8
+
9
+ module Asciidoctor
10
+ # PlantUML Module
11
+ module PlantUml
12
+ # PlantUML Configuration
13
+ class Configuration
14
+ DEFAULT_URL = ENV['PLANTUML_URL'] || ''
15
+ DEFAULT_ENCODING = ENV['PLANTUML_ENCODING'] || 'legacy'
16
+
17
+ attr_accessor :url, :txt_enable, :svg_enable, :png_enable, :encoding
18
+
19
+ def initialize
20
+ @url = DEFAULT_URL
21
+ @txt_enable = true
22
+ @svg_enable = true
23
+ @png_enable = true
24
+ @encoding = DEFAULT_ENCODING
25
+ end
26
+ end
27
+
28
+ class << self
29
+ attr_writer :configuration
30
+ end
31
+
32
+ def self.configuration
33
+ @configuration ||= Configuration.new
34
+ end
35
+
36
+ def self.configure
37
+ yield(configuration)
38
+ end
39
+
40
+ # PlantUML Processor
41
+ class Processor
42
+ FORMATS = %w[png svg txt].freeze
43
+ DEFAULT_FORMAT = FORMATS[0]
44
+
45
+ ENCODINGS = %w[legacy deflate].freeze
46
+ DEFAULT_ENCODING = ENCODINGS[0]
47
+
48
+ ENCODINGS_MAGIC_STRINGS_MAP = Hash.new('')
49
+ ENCODINGS_MAGIC_STRINGS_MAP['deflate'] = '~1'
50
+
51
+ URI_SCHEMES_REGEXP = ::URI::DEFAULT_PARSER.make_regexp(%w[http https])
52
+
53
+ class << self
54
+ def valid_format?(format)
55
+ FORMATS.include?(format)
56
+ end
57
+
58
+ def valid_encoding?(encoding)
59
+ ENCODINGS.include?(encoding)
60
+ end
61
+
62
+ def server_url
63
+ PlantUml.configuration.url
64
+ end
65
+
66
+ def txt_enabled?
67
+ PlantUml.configuration.txt_enable
68
+ end
69
+
70
+ def png_enabled?
71
+ PlantUml.configuration.png_enable
72
+ end
73
+
74
+ def svg_enabled?
75
+ PlantUml.configuration.svg_enable
76
+ end
77
+
78
+ def enabled?
79
+ txt_enabled? || png_enabled? || svg_enabled?
80
+ end
81
+
82
+ def plantuml_content_format(code, format, attrs = {})
83
+ if %w[png svg txt].include?(format) &&
84
+ method("#{format}_enabled?").call
85
+ method("plantuml_#{format}_content").call(code, format, attrs)
86
+ else
87
+ plantuml_invalid_content(format, attrs)
88
+ end
89
+ end
90
+
91
+ def plantuml_content(code, attrs = {})
92
+ format = attrs['format'] || DEFAULT_FORMAT
93
+
94
+ return plantuml_disabled_content(code, attrs) unless enabled?
95
+
96
+ unless valid_uri?(server_url)
97
+ return plantuml_server_unavailable_content(server_url, attrs)
98
+ end
99
+
100
+ plantuml_content_format(code, format, attrs)
101
+ end
102
+
103
+ # Compression code used to generate PlantUML URLs. Taken directly from
104
+ # the transcoder class in the PlantUML java code.
105
+ def gen_url(text, format)
106
+ result = ''
107
+ result += encoding_magic_prefix
108
+ compressed_data = Zlib::Deflate.deflate(text)
109
+ compressed_data.chars.each_slice(3) do |bytes|
110
+ # print bytes[0], ' ' , bytes[1] , ' ' , bytes[2]
111
+ b1 = bytes[0].nil? ? 0 : (bytes[0].ord & 0xFF)
112
+ b2 = bytes[1].nil? ? 0 : (bytes[1].ord & 0xFF)
113
+ b3 = bytes[2].nil? ? 0 : (bytes[2].ord & 0xFF)
114
+ result += append3bytes(b1, b2, b3)
115
+ end
116
+ join_paths(server_url, "#{format}/", result).to_s
117
+ end
118
+
119
+ private
120
+
121
+ def plantuml_txt_content(code, format, attrs = {})
122
+ url = gen_url(code, format)
123
+ URI(url).open do |f|
124
+ plantuml_ascii_content(f.read, attrs)
125
+ end
126
+ rescue OpenURI::HTTPError, Errno::ECONNREFUSED, SocketError
127
+ plantuml_png_content(code, format, attrs)
128
+ end
129
+
130
+ def plantuml_ascii_content(code, attrs = {})
131
+ content = '<div class="listingblock">'
132
+ content += '<div class="content">'
133
+ content += '<pre '
134
+ content += "id=\"#{attrs['id']}\" " if attrs['id']
135
+ content += 'class="plantuml">\n'
136
+ content += code
137
+ content += '</pre>'
138
+ content += '</div>'
139
+ content + '</div>'
140
+ end
141
+
142
+ def plantuml_png_content(code, format, attrs = {})
143
+ content = '<div class="imageblock">'
144
+ content += '<div class="content">'
145
+ content += '<img '
146
+ content += "id=\"#{attrs['id']}\" " if attrs['id']
147
+ content += 'class="plantuml" '
148
+ content += "width=\"#{attrs['width']}\" " if attrs['width']
149
+ content += "height=\"#{attrs['height']}\" " if attrs['height']
150
+ content += "alt=\"#{attrs['alt']}\" " if attrs['alt']
151
+ content += "src=\"#{gen_url(code, format)}\" />"
152
+ content += '</div>'
153
+ content + '</div>'
154
+ end
155
+
156
+ def plantuml_svg_content(code, format, attrs = {})
157
+ content = '<div class="imageblock">'
158
+ content += '<div class="content">'
159
+ content += '<object type="image/svg+xml" '
160
+ content += "data=\"#{gen_url(code, format)}\" "
161
+ content += "id=\"#{attrs['id']}\" " if attrs['id']
162
+ content += "width=\"#{attrs['width']}\" " if attrs['width']
163
+ content += "height=\"#{attrs['height']}\" " if attrs['height']
164
+ content += '>'
165
+ attrs['id'] = 'fallback_' + attrs['id'] if attrs['id']
166
+ content += plantuml_png_content(code, format, attrs)
167
+ content += '</object>'
168
+ content += '</div>'
169
+ content + '</div>'
170
+ end
171
+
172
+ def plantuml_invalid_content(format, attrs = {})
173
+ error = "PlantUML Error: Invalid format \"#{format}\""
174
+ _plantuml_error_content(error, attrs)
175
+ end
176
+
177
+ def plantuml_server_unavailable_content(url, attrs = {})
178
+ error = "Error: cannot connect to PlantUML server at \"#{url}\""
179
+ _plantuml_error_content(error, attrs)
180
+ end
181
+
182
+ def plantuml_disabled_content(code, attrs = {})
183
+ _plantuml_error_content(code, attrs)
184
+ end
185
+
186
+ def _plantuml_error_content(error, attrs = {})
187
+ content = '<div class="listingblock">'
188
+ content += '<div class="content">'
189
+ content += '<pre '
190
+ content += "id=\"#{attrs['id']}\" " if attrs['id']
191
+ content += 'class="plantuml plantuml-error">\n'
192
+ content += error
193
+ content += '</pre>'
194
+ content += '</div>'
195
+ content + '</div>'
196
+ end
197
+
198
+ def encode6bit(bit)
199
+ return ('0'.ord + bit).chr if bit < 10
200
+
201
+ bit -= 10
202
+ return ('A'.ord + bit).chr if bit < 26
203
+
204
+ bit -= 26
205
+ return ('a'.ord + bit).chr if bit < 26
206
+
207
+ bit -= 26
208
+ return '-' if bit.zero?
209
+
210
+ return '_' if bit == 1
211
+
212
+ '?'
213
+ end
214
+
215
+ def append3bytes(bit1, bit2, bit3)
216
+ c1 = bit1 >> 2
217
+ c2 = ((bit1 & 0x3) << 4) | (bit2 >> 4)
218
+ c3 = ((bit2 & 0xF) << 2) | (bit3 >> 6)
219
+ c4 = bit3 & 0x3F
220
+ encode6bit(c1 & 0x3F).chr +
221
+ encode6bit(c2 & 0x3F).chr +
222
+ encode6bit(c3 & 0x3F).chr +
223
+ encode6bit(c4 & 0x3F).chr
224
+ end
225
+
226
+ def encoding_magic_prefix
227
+ ENCODINGS_MAGIC_STRINGS_MAP[PlantUml.configuration.encoding]
228
+ end
229
+
230
+ # Make a call to the PlantUML server with the simplest diagram possible
231
+ # to check if the server is available or not.
232
+ def check_server(check_url)
233
+ response = Net::HTTP.get_response(URI(check_url))
234
+ response.is_a?(Net::HTTPSuccess)
235
+ rescue OpenURI::HTTPError, Errno::ECONNREFUSED, SocketError
236
+ false
237
+ end
238
+
239
+ def valid_uri?(uri)
240
+ !(uri =~ /\A#{URI_SCHEMES_REGEXP}\z/).nil?
241
+ end
242
+
243
+ def join_paths(*paths, separator: '/')
244
+ paths = paths.compact.reject(&:empty?)
245
+ last = paths.length - 1
246
+ paths.each_with_index.map do |path, index|
247
+ expand_path(path, index, last, separator)
248
+ end.join
249
+ end
250
+
251
+ def expand_path(path, current, last, separator)
252
+ path = path[1..-1] if path.start_with?(separator) && current.zero?
253
+
254
+ unless path.end_with?(separator) || current == last
255
+ path = [path, separator]
256
+ end
257
+
258
+ path
259
+ end
260
+ end
261
+ end
262
+
263
+ # PlantUML BlockProcessor
264
+ class BlockProcessor < Asciidoctor::Extensions::BlockProcessor
265
+ use_dsl
266
+ named :plantuml
267
+ on_context :listing, :literal
268
+ content_model :simple
269
+
270
+ def process(parent, target, attrs)
271
+ lines = target.lines
272
+
273
+ unless target.lines[0] =~ /@startuml/
274
+ lines = ['@startuml'] + target.lines
275
+ end
276
+
277
+ lines += ['@enduml'] unless target.lines[-1] =~ /@enduml/
278
+
279
+ content = Processor.plantuml_content(lines.join("\n"), attrs)
280
+
281
+ create_plantuml_block(parent, content, attrs)
282
+ end
283
+
284
+ private
285
+
286
+ def create_plantuml_block(parent, content, attrs)
287
+ Asciidoctor::Block.new parent, :pass, {
288
+ content_model: :raw,
289
+ source: content,
290
+ subs: :default
291
+ }.merge(attrs)
292
+ end
293
+ end
294
+ end
295
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Asciidoctor
4
+ module PlantUML
5
+ VERSION = '0.0.13'
6
+ end
7
+ end
@@ -1,133 +1,221 @@
1
- require "test/unit"
2
- require "asciidoctor"
3
- require "stringio"
4
- require "nokogiri"
5
- require "asciidoctor-plantuml"
6
-
7
- DOC_BASIC = <<-eos
8
- = Hello PlantUML!
9
-
10
- [plantuml, format="png"]
11
- .Title Of this
12
- ----
13
- User -> (Start)
14
- User --> (Use the application) : Label
15
- ----
16
- eos
17
-
18
- DOC_BASIC2 = <<-eos
19
- = Hello PlantUML!
20
-
21
- [plantuml, format="png"]
22
- .Title Of this
23
- [[fig-xref]]
24
- ----
25
- @startuml
26
- User -> (Start)
27
- User --> (Use the application) : Label
28
- @enduml
29
- ----
30
- eos
31
-
32
- DOC_BASIC3 = <<-eos
33
- = Hello Compound PlantUML!
34
-
35
- [plantuml, format="png"]
36
- ----
37
- [COMP1]
38
- [COMP2]
39
- [COMP1] -> [COMP2]
40
- [COMP2] --> [COMP3]
41
- ----
42
- eos
43
-
44
- DOC_ID = <<-eos
45
- = Hello PlantUML!
46
-
47
- [plantuml, format="png", id="myId"]
48
- ----
49
- User -> (Start)
50
- User --> (Use the application) : Label
51
- ----
52
- eos
53
-
54
- DOC_DIM = <<-eos
55
- = Hello PlantUML!
56
-
57
- [plantuml, format="png", width="100px", height="50px"]
58
- ----
59
- User -> (Start)
60
- User --> (Use the application) : Label
61
- ----
62
- eos
63
-
64
- DOC_ALT = <<-eos
65
- = Hello PlantUML!
66
-
67
- [plantuml, format="png", alt="alt"]
68
- ----
69
- User -> (Start)
70
- User --> (Use the application) : Label
71
- ----
72
- eos
73
-
74
- DOC_BAD_FORMAT = <<-eos
75
- = Hello PlantUML!
76
-
77
- [plantuml, format="jpg"]
78
- ----
79
- User -> (Start)
80
- User --> (Use the application) : Label
81
- ----
82
- eos
83
-
84
- DOC_MULTI = <<-eos
85
- = Hello PlantUML!
86
-
87
- [plantuml, format="png"]
88
- ----
89
- User -> (Start)
90
- User --> (Use the application) : Label
91
- ----
92
-
93
- [plantuml, format="png"]
94
- ----
95
- User -> (Start)
96
- User --> (Use the application) : Label
97
- ----
98
-
99
- [plantuml, format="txt"]
100
- ----
101
- User -> (Start)
102
- User --> (Use the application) : Label
103
- ----
104
- eos
105
-
106
- DOC_TXT = <<-eos
107
- = Hello PlantUML!
108
-
109
- [plantuml, format="txt"]
110
- ----
111
- User -> (Start)
112
- User --> (Use the application) : Label
113
- ----
114
- eos
1
+ # frozen_string_literal: true
2
+
3
+ require 'test/unit'
4
+ require 'asciidoctor'
5
+ require 'stringio'
6
+ require 'nokogiri'
7
+ require 'asciidoctor-plantuml'
8
+
9
+ DOC_BASIC = <<~ENDOFSTRING
10
+ = Hello PlantUML!
11
+
12
+ [plantuml, format="png"]
13
+ .Title Of this
14
+ ----
15
+ User -> (Start)
16
+ User --> (Use the application) : Label
17
+ ----
18
+ ENDOFSTRING
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
+
31
+ DOC_BASIC2 = <<~ENDOFSTRING
32
+ = Hello PlantUML!
33
+
34
+ [plantuml, format="png"]
35
+ .Title Of this
36
+ [[fig-xref]]
37
+ ----
38
+ @startuml
39
+ User -> (Start)
40
+ User --> (Use the application) : Label
41
+ @enduml
42
+ ----
43
+ ENDOFSTRING
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
+
59
+ DOC_BASIC3 = <<~ENDOFSTRING
60
+ = Hello Compound PlantUML!
61
+
62
+ [plantuml, format="png"]
63
+ ----
64
+ [COMP1]
65
+ [COMP2]
66
+ [COMP1] -> [COMP2]
67
+ [COMP2] --> [COMP3]
68
+ ----
69
+ ENDOFSTRING
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
+
83
+ DOC_ID = <<~ENDOFSTRING
84
+ = Hello PlantUML!
85
+
86
+ [plantuml, format="png", id="myId"]
87
+ ----
88
+ User -> (Start)
89
+ User --> (Use the application) : Label
90
+ ----
91
+ ENDOFSTRING
92
+
93
+ DOC_DIM = <<~ENDOFSTRING
94
+ = Hello PlantUML!
95
+
96
+ [plantuml, format="png", width="100px", height="50px"]
97
+ ----
98
+ User -> (Start)
99
+ User --> (Use the application) : Label
100
+ ----
101
+ ENDOFSTRING
102
+
103
+ DOC_ALT = <<~ENDOFSTRING
104
+ = Hello PlantUML!
105
+
106
+ [plantuml, format="png", alt="alt"]
107
+ ----
108
+ User -> (Start)
109
+ User --> (Use the application) : Label
110
+ ----
111
+ ENDOFSTRING
112
+
113
+ DOC_BAD_FORMAT = <<~ENDOFSTRING
114
+ = Hello PlantUML!
115
+
116
+ [plantuml, format="jpg"]
117
+ ----
118
+ User -> (Start)
119
+ User --> (Use the application) : Label
120
+ ----
121
+ ENDOFSTRING
122
+
123
+ DOC_MULTI = <<~ENDOFSTRING
124
+ = Hello PlantUML!
125
+
126
+ [plantuml, format="png"]
127
+ ----
128
+ User -> (Start)
129
+ User --> (Use the application) : Label
130
+ ----
131
+
132
+ [plantuml, format="png"]
133
+ ----
134
+ User -> (Start)
135
+ User --> (Use the application) : Label
136
+ ----
137
+
138
+ [plantuml, format="txt"]
139
+ ----
140
+ User -> (Start)
141
+ User --> (Use the application) : Label
142
+ ----
143
+ ENDOFSTRING
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
+
167
+ DOC_TXT = <<~ENDOFSTRING
168
+ = Hello PlantUML!
169
+
170
+ [plantuml, format="txt"]
171
+ ----
172
+ User -> (Start)
173
+ User --> (Use the application) : Label
174
+ ----
175
+ ENDOFSTRING
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
115
186
 
116
187
  class PlantUmlTest < Test::Unit::TestCase
117
-
118
- GENURL = "http://localhost:8080/plantuml/png/U9npA2v9B2efpStX2YrEBLBGjLFG20Q9Q4Bv804WIw4a8rKXiQ0W9pCviIGpFqzJmKh19p4fDOVB8JKl1QWT05kd5wq0"
119
- GENURL2 = "http://localhost:8080/plantuml/png/U9npA2v9B2efpStXYdRszmqmZ8NGHh4mleAkdGAAa15G22Pc7Clba9gN0jGE00W75Cm0"
188
+ GENURL = 'http://localhost:8080/plantuml/png/U9npA2v9B2efpStX2YrEBLBGjLFG20Q9Q4Bv804WIw4a8rKXiQ0W9pCviIGpFqzJmKh19p4fDOVB8JKl1QWT05kd5wq0'
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'
120
192
 
121
193
  def setup
122
194
  Asciidoctor::PlantUml.configure do |c|
123
- c.url = "http://localhost:8080/plantuml"
195
+ c.url = 'http://localhost:8080/plantuml'
124
196
  c.txt_enable = true
197
+ c.png_enable = true
198
+ c.svg_enable = true
125
199
  end
126
200
  end
127
201
 
128
202
  def test_plantuml_block_processor
203
+ html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC), backend: 'html5')
204
+ page = Nokogiri::HTML(html)
205
+
206
+ elements = page.css('img.plantuml')
207
+
208
+ assert_equal elements.size, 1
129
209
 
130
- html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC), backend: "html5")
210
+ element = elements.first
211
+
212
+ assert_equal GENURL, element['src']
213
+ end
214
+
215
+ def test_plantuml_block_literal_processor
216
+ html = ::Asciidoctor.convert(
217
+ StringIO.new(DOC_BASIC_LITERAL), backend: 'html5'
218
+ )
131
219
  page = Nokogiri::HTML(html)
132
220
 
133
221
  elements = page.css('img.plantuml')
@@ -136,11 +224,28 @@ class PlantUmlTest < Test::Unit::TestCase
136
224
 
137
225
  element = elements.first
138
226
 
139
- assert_equal GENURL, element["src"]
227
+ assert_equal GENURL, element['src']
140
228
  end
141
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')
@@ -149,11 +254,11 @@ class PlantUmlTest < Test::Unit::TestCase
149
254
 
150
255
  element = elements.first
151
256
 
152
- assert_equal GENURL, element["src"]
257
+ assert_equal GENURL, element['src']
153
258
  end
154
259
 
155
260
  def test_plantuml_block_processor3
156
- html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC3), backend: "html5")
261
+ html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC3), backend: 'html5')
157
262
  page = Nokogiri::HTML(html)
158
263
 
159
264
  elements = page.css('img.plantuml')
@@ -162,26 +267,55 @@ class PlantUmlTest < Test::Unit::TestCase
162
267
 
163
268
  element = elements.first
164
269
 
165
- assert_equal GENURL2, element["src"]
270
+ assert_equal GENURL2, element['src']
166
271
  end
167
272
 
168
- def test_plantuml_id_attribute
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)
169
278
 
170
- html = ::Asciidoctor.convert(StringIO.new(DOC_ID), backend: "html5")
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')
171
294
  page = Nokogiri::HTML(html)
172
295
 
173
296
  elements = page.css('img.plantuml')
174
297
 
175
298
  assert_equal elements.size, 1
299
+
176
300
  element = elements.first
177
301
 
178
- assert_equal "myId", element["id"]
302
+ assert_equal GENURL_ENCODING, element['src']
303
+ end
304
+
305
+ def test_plantuml_id_attribute
306
+ html = ::Asciidoctor.convert(StringIO.new(DOC_ID), backend: 'html5')
307
+ page = Nokogiri::HTML(html)
179
308
 
309
+ elements = page.css('img.plantuml')
310
+
311
+ assert_equal elements.size, 1
312
+ element = elements.first
313
+
314
+ assert_equal 'myId', element['id']
180
315
  end
181
316
 
182
317
  def test_plantuml_dimension_attribute
183
-
184
- html = ::Asciidoctor.convert(StringIO.new(DOC_DIM), backend: "html5")
318
+ html = ::Asciidoctor.convert(StringIO.new(DOC_DIM), backend: 'html5')
185
319
  page = Nokogiri::HTML(html)
186
320
 
187
321
  elements = page.css('img.plantuml')
@@ -189,14 +323,12 @@ class PlantUmlTest < Test::Unit::TestCase
189
323
  assert_equal elements.size, 1
190
324
  element = elements.first
191
325
 
192
- assert_equal "100px", element["width"]
193
- assert_equal "50px", element["height"]
194
-
326
+ assert_equal '100px', element['width']
327
+ assert_equal '50px', element['height']
195
328
  end
196
329
 
197
330
  def test_plantuml_alt_attribute
198
-
199
- html = ::Asciidoctor.convert(StringIO.new(DOC_ALT), backend: "html5")
331
+ html = ::Asciidoctor.convert(StringIO.new(DOC_ALT), backend: 'html5')
200
332
  page = Nokogiri::HTML(html)
201
333
 
202
334
  elements = page.css('img.plantuml')
@@ -204,23 +336,20 @@ class PlantUmlTest < Test::Unit::TestCase
204
336
  assert_equal elements.size, 1
205
337
  element = elements.first
206
338
 
207
- assert_equal "alt", element["alt"]
208
-
339
+ assert_equal 'alt', element['alt']
209
340
  end
210
341
 
211
342
  def test_should_show_bad_format
212
- html = ::Asciidoctor.convert(StringIO.new(DOC_BAD_FORMAT), backend: "html5")
343
+ html = ::Asciidoctor.convert(StringIO.new(DOC_BAD_FORMAT), backend: 'html5')
213
344
 
214
345
  page = Nokogiri::HTML(html)
215
346
 
216
347
  elements = page.css('pre.plantuml-error')
217
348
  assert_equal elements.size, 1
218
-
219
349
  end
220
350
 
221
- def test_plantuml_multiple
222
-
223
- html = ::Asciidoctor.convert(StringIO.new(DOC_MULTI), backend: "html5")
351
+ def test_plantuml_multiple_listing
352
+ html = ::Asciidoctor.convert(StringIO.new(DOC_MULTI), backend: 'html5')
224
353
  page = Nokogiri::HTML(html)
225
354
 
226
355
  elements = page.css('img.plantuml')
@@ -228,72 +357,118 @@ class PlantUmlTest < Test::Unit::TestCase
228
357
 
229
358
  elements = page.css('.plantuml-error')
230
359
  assert_equal elements.size, 0
360
+ end
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
231
370
 
371
+ elements = page.css('.plantuml-error')
372
+ assert_equal elements.size, 0
232
373
  end
233
374
 
234
375
  def test_plantuml_bad_server
235
-
236
376
  Asciidoctor::PlantUml.configure do |c|
237
- c.url = "http://nonexistent.com/plantuml"
377
+ c.url = 'http://nonexistent.com/plantuml'
238
378
  end
239
379
 
240
- html = ::Asciidoctor.convert(StringIO.new(DOC_MULTI), backend: "html5")
380
+ html = ::Asciidoctor.convert(StringIO.new(DOC_MULTI), backend: 'html5')
241
381
  page = Nokogiri::HTML(html)
242
382
 
243
383
  elements = page.css('img.plantuml')
244
- assert_equal elements.size, 3
384
+ assert_equal 3, elements.size
245
385
 
246
386
  elements = page.css('.plantuml-error')
247
- assert_equal elements.size, 0
387
+ assert_equal 0, elements.size
248
388
  end
249
389
 
250
390
  def test_plantuml_invalid_uri
251
-
252
391
  Asciidoctor::PlantUml.configure do |c|
253
- c.url = "ftp://test.com"
392
+ c.url = 'ftp://test.com'
254
393
  end
255
394
 
256
- html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC), backend: "html5")
395
+ html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC), backend: 'html5')
257
396
  page = Nokogiri::HTML(html)
258
397
  elements = page.css('pre.plantuml-error')
259
398
  assert_equal elements.size, 1
260
399
  end
261
400
 
262
401
  def test_plantuml_nil_uri
263
-
264
402
  Asciidoctor::PlantUml.configure do |c|
265
403
  c.url = nil
266
404
  end
267
405
 
268
- html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC), backend: "html5")
406
+ html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC), backend: 'html5')
269
407
  page = Nokogiri::HTML(html)
270
408
  elements = page.css('pre.plantuml-error')
271
409
  assert_equal elements.size, 1
272
410
  end
273
411
 
274
412
  def test_plantuml_empty_uri
275
-
276
413
  Asciidoctor::PlantUml.configure do |c|
277
- c.url = ""
414
+ c.url = ''
278
415
  end
279
416
 
280
- html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC), backend: "html5")
417
+ html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC), backend: 'html5')
281
418
  page = Nokogiri::HTML(html)
282
419
  elements = page.css('pre.plantuml-error')
283
420
  assert_equal elements.size, 1
284
421
  end
285
422
 
286
423
  def test_disable_txt
287
-
288
424
  Asciidoctor::PlantUml.configure do |c|
289
- c.url = "http://localhost:8080/plantuml"
425
+ c.url = 'http://localhost:8080/plantuml'
290
426
  c.txt_enable = false
291
427
  end
292
428
 
293
- html = ::Asciidoctor.convert(StringIO.new(DOC_TXT), backend: "html5")
429
+ html = ::Asciidoctor.convert(StringIO.new(DOC_TXT), backend: 'html5')
430
+ page = Nokogiri::HTML(html)
431
+ elements = page.css('pre.plantuml-error')
432
+ assert_equal elements.size, 1
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')
294
458
  page = Nokogiri::HTML(html)
295
459
  elements = page.css('pre.plantuml-error')
296
460
  assert_equal elements.size, 1
461
+ end
297
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
298
473
  end
299
474
  end