asciidoctor-plantuml 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/asciidoctor-plantuml/plantuml.rb +30 -15
- data/lib/asciidoctor-plantuml/version.rb +1 -1
- data/test/test_plantuml.rb +75 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d237e41919909a5acb269df07453ddaacb86f70e
|
4
|
+
data.tar.gz: 8a9bf93e2949704fd34072d77dad08ba7c6a1153
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8966c1145904166a1ba1ab7c9a90eea626814025dffed69a9db7c5e3f65941b781188a72c5271b966d949851a97fbeb129b17a9e8e1791a8d2529358e2b4622b
|
7
|
+
data.tar.gz: 381214dd99a3b8f99a4ba692cc741206e601bd4ad4ecc85decf4024e3af8f6dd9da9f17cd8ac20d300ce421c057d654b5ebd9625002b14a3cdb3b16d08a8a5e0
|
@@ -8,13 +8,13 @@ module Asciidoctor
|
|
8
8
|
|
9
9
|
class Configuration
|
10
10
|
|
11
|
-
DEFAULT_URL = ENV["PLANTUML_URL"] || "
|
11
|
+
DEFAULT_URL = ENV["PLANTUML_URL"] || ""
|
12
12
|
|
13
|
-
attr_accessor :url, :
|
13
|
+
attr_accessor :url, :txt_enable
|
14
14
|
|
15
15
|
def initialize
|
16
16
|
@url = DEFAULT_URL
|
17
|
-
@
|
17
|
+
@txt_enable = true
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -43,17 +43,27 @@ module Asciidoctor
|
|
43
43
|
PlantUml::configuration.url
|
44
44
|
end
|
45
45
|
|
46
|
-
def
|
46
|
+
def txt_enabled?
|
47
|
+
PlantUml::configuration.txt_enable
|
48
|
+
end
|
47
49
|
|
48
|
-
|
50
|
+
def plantuml_content(code, attrs = {})
|
49
51
|
|
50
52
|
format = attrs["format"] || DEFAULT_FORMAT
|
51
53
|
|
54
|
+
if !valid_uri?(server_url)
|
55
|
+
return plantuml_server_unavailable_content(server_url, attrs)
|
56
|
+
end
|
57
|
+
|
52
58
|
case format
|
53
59
|
when "png"
|
54
60
|
plantuml_img_content(code, format, attrs)
|
55
61
|
when "txt"
|
56
|
-
|
62
|
+
if txt_enabled?
|
63
|
+
plantuml_txt_content(code, format, attrs)
|
64
|
+
else
|
65
|
+
plantuml_invalid_content(format, attrs)
|
66
|
+
end
|
57
67
|
when "svg"
|
58
68
|
plantuml_img_content(code, format, attrs)
|
59
69
|
else
|
@@ -62,21 +72,23 @@ module Asciidoctor
|
|
62
72
|
end
|
63
73
|
|
64
74
|
def plantuml_txt_content(code, format, attrs = {})
|
65
|
-
url = gen_url(code, format)
|
66
|
-
content = "<div class=\"listingblock\">"
|
67
|
-
content += "<div class=\"content\">"
|
68
|
-
content += "<pre "
|
69
|
-
content +="id=\"#{attrs['id']}\" " if attrs['id']
|
70
|
-
content +="class=\"plantuml\">\n"
|
71
|
-
|
72
75
|
begin
|
76
|
+
url = gen_url(code, format)
|
73
77
|
open(url) do |f|
|
74
|
-
|
78
|
+
plantuml_ascii_content(f.read, format, attrs)
|
75
79
|
end
|
76
80
|
rescue
|
77
|
-
|
81
|
+
plantuml_img_content(code, format, attrs)
|
78
82
|
end
|
83
|
+
end
|
79
84
|
|
85
|
+
def plantuml_ascii_content(code, format, attrs = {})
|
86
|
+
content = "<div class=\"listingblock\">"
|
87
|
+
content += "<div class=\"content\">"
|
88
|
+
content += "<pre "
|
89
|
+
content +="id=\"#{attrs['id']}\" " if attrs['id']
|
90
|
+
content +="class=\"plantuml\">\n"
|
91
|
+
content += code
|
80
92
|
content +="</pre>"
|
81
93
|
content += "</div>"
|
82
94
|
content += "</div>"
|
@@ -178,6 +190,9 @@ module Asciidoctor
|
|
178
190
|
return false
|
179
191
|
end
|
180
192
|
|
193
|
+
def valid_uri?(uri)
|
194
|
+
!(uri =~ /\A#{URI::regexp(['http', 'https'])}\z/).nil?
|
195
|
+
end
|
181
196
|
|
182
197
|
def create_plantuml_block(parent, content)
|
183
198
|
Asciidoctor::Block.new parent, :pass, :content_model => :raw,
|
data/test/test_plantuml.rb
CHANGED
@@ -7,7 +7,7 @@ require "asciidoctor-plantuml"
|
|
7
7
|
DOC_BASIC = <<-eos
|
8
8
|
= Hello PlantUML!
|
9
9
|
|
10
|
-
[plantuml, format="png"
|
10
|
+
[plantuml, format="png"]
|
11
11
|
--
|
12
12
|
User -> (Start)
|
13
13
|
User --> (Use the application) : Label
|
@@ -17,7 +17,7 @@ eos
|
|
17
17
|
DOC_BASIC2 = <<-eos
|
18
18
|
= Hello PlantUML!
|
19
19
|
|
20
|
-
[plantuml, format="png"
|
20
|
+
[plantuml, format="png"]
|
21
21
|
@startuml
|
22
22
|
User -> (Start)
|
23
23
|
User --> (Use the application) : Label
|
@@ -27,7 +27,7 @@ eos
|
|
27
27
|
DOC_ID = <<-eos
|
28
28
|
= Hello PlantUML!
|
29
29
|
|
30
|
-
[plantuml, format="png",
|
30
|
+
[plantuml, format="png", id="myId"]
|
31
31
|
User -> (Start)
|
32
32
|
User --> (Use the application) : Label
|
33
33
|
eos
|
@@ -35,7 +35,7 @@ eos
|
|
35
35
|
DOC_DIM = <<-eos
|
36
36
|
= Hello PlantUML!
|
37
37
|
|
38
|
-
[plantuml, format="png",
|
38
|
+
[plantuml, format="png", width="100px", height="50px"]
|
39
39
|
User -> (Start)
|
40
40
|
User --> (Use the application) : Label
|
41
41
|
eos
|
@@ -43,7 +43,7 @@ eos
|
|
43
43
|
DOC_ALT = <<-eos
|
44
44
|
= Hello PlantUML!
|
45
45
|
|
46
|
-
[plantuml, format="png",
|
46
|
+
[plantuml, format="png", alt="alt"]
|
47
47
|
User -> (Start)
|
48
48
|
User --> (Use the application) : Label
|
49
49
|
eos
|
@@ -51,7 +51,7 @@ eos
|
|
51
51
|
DOC_BAD_FORMAT = <<-eos
|
52
52
|
= Hello PlantUML!
|
53
53
|
|
54
|
-
[plantuml, format="jpg"
|
54
|
+
[plantuml, format="jpg"]
|
55
55
|
User -> (Start)
|
56
56
|
User --> (Use the application) : Label
|
57
57
|
eos
|
@@ -59,19 +59,29 @@ eos
|
|
59
59
|
DOC_MULTI = <<-eos
|
60
60
|
= Hello PlantUML!
|
61
61
|
|
62
|
-
[plantuml, format="png"
|
62
|
+
[plantuml, format="png"]
|
63
63
|
User -> (Start)
|
64
64
|
User --> (Use the application) : Label
|
65
65
|
|
66
|
-
[plantuml, format="png"
|
66
|
+
[plantuml, format="png"]
|
67
67
|
User -> (Start)
|
68
68
|
User --> (Use the application) : Label
|
69
69
|
|
70
|
-
[plantuml, format="txt"
|
70
|
+
[plantuml, format="txt"]
|
71
71
|
User -> (Start)
|
72
72
|
User --> (Use the application) : Label
|
73
73
|
eos
|
74
74
|
|
75
|
+
DOC_TXT = <<-eos
|
76
|
+
= Hello PlantUML!
|
77
|
+
|
78
|
+
[plantuml, format="txt"]
|
79
|
+
--
|
80
|
+
User -> (Start)
|
81
|
+
User --> (Use the application) : Label
|
82
|
+
--
|
83
|
+
eos
|
84
|
+
|
75
85
|
class PlantUmlTest < Test::Unit::TestCase
|
76
86
|
|
77
87
|
GENURL = "http://localhost:8080/plantuml/png/U9npA2v9B2efpStX2YrEBLBGjLFG20Q9Q4Bv804WIw4a8rKXiQ0W9pCviIGpFqzJmKh19p4fDOVB8JKl1QWT05kd5wq0"
|
@@ -79,6 +89,7 @@ class PlantUmlTest < Test::Unit::TestCase
|
|
79
89
|
def setup
|
80
90
|
Asciidoctor::PlantUml.configure do |c|
|
81
91
|
c.url = "http://localhost:8080/plantuml"
|
92
|
+
c.txt_enable = true
|
82
93
|
end
|
83
94
|
end
|
84
95
|
|
@@ -168,11 +179,10 @@ class PlantUmlTest < Test::Unit::TestCase
|
|
168
179
|
page = Nokogiri::HTML(html)
|
169
180
|
|
170
181
|
elements = page.css('img.plantuml')
|
182
|
+
assert elements.size >= 2
|
171
183
|
|
172
|
-
|
173
|
-
|
174
|
-
elements = page.css('pre.plantuml')
|
175
|
-
assert_equal elements.size, 1
|
184
|
+
elements = page.css('.plantuml-error')
|
185
|
+
assert_equal elements.size, 0
|
176
186
|
|
177
187
|
end
|
178
188
|
|
@@ -186,8 +196,59 @@ class PlantUmlTest < Test::Unit::TestCase
|
|
186
196
|
page = Nokogiri::HTML(html)
|
187
197
|
|
188
198
|
elements = page.css('img.plantuml')
|
189
|
-
assert_equal elements.size,
|
199
|
+
assert_equal elements.size, 3
|
200
|
+
|
201
|
+
elements = page.css('.plantuml-error')
|
202
|
+
assert_equal elements.size, 0
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_plantuml_invalid_uri
|
206
|
+
|
207
|
+
Asciidoctor::PlantUml.configure do |c|
|
208
|
+
c.url = "ftp://test.com"
|
209
|
+
end
|
210
|
+
|
211
|
+
html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC), backend: "html5")
|
212
|
+
page = Nokogiri::HTML(html)
|
213
|
+
elements = page.css('pre.plantuml-error')
|
214
|
+
assert_equal elements.size, 1
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_plantuml_nil_uri
|
218
|
+
|
219
|
+
Asciidoctor::PlantUml.configure do |c|
|
220
|
+
c.url = nil
|
221
|
+
end
|
190
222
|
|
223
|
+
html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC), backend: "html5")
|
224
|
+
page = Nokogiri::HTML(html)
|
225
|
+
elements = page.css('pre.plantuml-error')
|
226
|
+
assert_equal elements.size, 1
|
191
227
|
end
|
192
228
|
|
229
|
+
def test_plantuml_empty_uri
|
230
|
+
|
231
|
+
Asciidoctor::PlantUml.configure do |c|
|
232
|
+
c.url = ""
|
233
|
+
end
|
234
|
+
|
235
|
+
html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC), backend: "html5")
|
236
|
+
page = Nokogiri::HTML(html)
|
237
|
+
elements = page.css('pre.plantuml-error')
|
238
|
+
assert_equal elements.size, 1
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_disable_txt
|
242
|
+
|
243
|
+
Asciidoctor::PlantUml.configure do |c|
|
244
|
+
c.url = "http://localhost:8080/plantuml"
|
245
|
+
c.txt_enable = false
|
246
|
+
end
|
247
|
+
|
248
|
+
html = ::Asciidoctor.convert(StringIO.new(DOC_TXT), backend: "html5")
|
249
|
+
page = Nokogiri::HTML(html)
|
250
|
+
elements = page.css('pre.plantuml-error')
|
251
|
+
assert_equal elements.size, 1
|
252
|
+
|
253
|
+
end
|
193
254
|
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.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Horacio Sanson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|