asciidoctor-plantuml 0.0.2 → 0.0.4
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 +72 -19
- data/lib/asciidoctor-plantuml/version.rb +1 -1
- data/test/test_plantuml.rb +31 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f6246a07cb6ee77b07fdecc5e32d30ef9def178
|
4
|
+
data.tar.gz: 995226fa46cd4ea93df420da01adb17f9456e6e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5718a88809d793a13d872a84e146acce5adb6d17561b15f2ad5f983d2b65fb876f5a3dbbb3d637e2f0bd5321cfb1944afbb14f87f920ecf5061c47b6467dcd1
|
7
|
+
data.tar.gz: e0864e23a800018aa552c7a96df18bb7c7985ab4d7a08d1ec4c91d3244d7f7b45afc5960006053c5b7fb81e751c3c75e6b3110339c45f3f0f2af492b817ae145
|
@@ -43,16 +43,84 @@ module Asciidoctor
|
|
43
43
|
PlantUml::configuration.url
|
44
44
|
end
|
45
45
|
|
46
|
-
def plantuml_content(code,
|
47
|
-
|
46
|
+
def plantuml_content(code, attrs = {})
|
47
|
+
|
48
|
+
testing = attrs["test"] == "true"
|
49
|
+
|
50
|
+
format = attrs["format"] || DEFAULT_FORMAT
|
51
|
+
|
52
|
+
case format
|
53
|
+
when "png"
|
54
|
+
plantuml_img_content(code, format, attrs)
|
55
|
+
when "txt"
|
56
|
+
plantuml_txt_content(code, format, attrs)
|
57
|
+
when "svg"
|
58
|
+
plantuml_img_content(code, format, attrs)
|
59
|
+
else
|
60
|
+
plantuml_invalid_content(format, attrs)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
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
|
+
begin
|
73
|
+
open(url) do |f|
|
74
|
+
content += f.read
|
75
|
+
end
|
76
|
+
rescue
|
77
|
+
content += "Failed to query PlantUML server #{url}"
|
78
|
+
end
|
79
|
+
|
80
|
+
content +="</pre>"
|
81
|
+
content += "</div>"
|
82
|
+
content += "</div>"
|
83
|
+
end
|
84
|
+
|
85
|
+
def plantuml_img_content(code, format, attrs = {})
|
86
|
+
content = "<div class=\"imageblock\">"
|
87
|
+
content += "<div class=\"content\">"
|
88
|
+
content += "<img "
|
48
89
|
content +="id=\"#{attrs['id']}\" " if attrs['id']
|
49
90
|
content +="class=\"plantuml\" "
|
50
91
|
content +="width=\"#{attrs['width']}\" " if attrs['width']
|
51
92
|
content +="height=\"#{attrs['height']}\" " if attrs['height']
|
52
93
|
content +="alt=\"#{attrs['alt']}\" " if attrs['alt']
|
53
94
|
content +="src=\"#{gen_url(code, format)}\" />"
|
95
|
+
content += "</div>"
|
96
|
+
content += "</div>"
|
97
|
+
end
|
98
|
+
|
99
|
+
def plantuml_invalid_content(format, attrs = {})
|
100
|
+
content = "<div class=\"listingblock\">"
|
101
|
+
content += "<div class=\"content\">"
|
102
|
+
content += "<pre "
|
103
|
+
content +="id=\"#{attrs['id']}\" " if attrs['id']
|
104
|
+
content +="class=\"plantuml plantuml-error\"> "
|
105
|
+
content += "PlantUML Error: Invalid format \"#{format}\""
|
106
|
+
content +="</pre>"
|
107
|
+
content += "</div>"
|
108
|
+
content += "</div>"
|
109
|
+
end
|
110
|
+
|
111
|
+
def plantuml_server_unavailable_content(url, attrs = {})
|
112
|
+
content = "<div class=\"listingblock\">"
|
113
|
+
content += "<div class=\"content\">"
|
114
|
+
content += "<pre "
|
115
|
+
content +="id=\"#{attrs['id']}\" " if attrs['id']
|
116
|
+
content +="class=\"plantuml plantuml-error\"> "
|
117
|
+
content += "PlantUML Error: cannot connect to PlantUML server at \"#{url}\""
|
118
|
+
content +="</pre>"
|
119
|
+
content += "</div>"
|
120
|
+
content += "</div>"
|
54
121
|
end
|
55
122
|
|
123
|
+
|
56
124
|
# Compression code used to generate PlantUML URLs. Taken directly from the
|
57
125
|
# Transcoder class in the PlantUML java code.
|
58
126
|
def gen_url(text, format)
|
@@ -142,22 +210,6 @@ module Asciidoctor
|
|
142
210
|
|
143
211
|
def process(parent, target, attrs)
|
144
212
|
|
145
|
-
testing = attrs["test"] == "true"
|
146
|
-
|
147
|
-
check_url = join_paths(server_url, "/png/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000")
|
148
|
-
|
149
|
-
if ! check_server(check_url) && ! testing
|
150
|
-
content = "<div class='plantuml'>PlantUML server [#{check_url}] is unreachable</div>"
|
151
|
-
return create_plantuml_block(parent, content)
|
152
|
-
end
|
153
|
-
|
154
|
-
format = attrs["format"] || DEFAULT_FORMAT
|
155
|
-
|
156
|
-
if ! valid_format?(format)
|
157
|
-
content = "<div class='plantuml'>Invalid format #{format}</div>"
|
158
|
-
return create_plantuml_block(parent, content)
|
159
|
-
end
|
160
|
-
|
161
213
|
lines = target.lines
|
162
214
|
|
163
215
|
if !(target.lines[0] =~ /@startuml/)
|
@@ -168,7 +220,8 @@ module Asciidoctor
|
|
168
220
|
lines += ["@enduml"]
|
169
221
|
end
|
170
222
|
|
171
|
-
content = plantuml_content(lines.join("\n"),
|
223
|
+
content = plantuml_content(lines.join("\n"), attrs)
|
224
|
+
|
172
225
|
return create_plantuml_block(parent, content)
|
173
226
|
|
174
227
|
end
|
data/test/test_plantuml.rb
CHANGED
@@ -8,8 +8,10 @@ DOC_BASIC = <<-eos
|
|
8
8
|
= Hello PlantUML!
|
9
9
|
|
10
10
|
[plantuml, format="png", test="true"]
|
11
|
+
--
|
11
12
|
User -> (Start)
|
12
13
|
User --> (Use the application) : Label
|
14
|
+
--
|
13
15
|
eos
|
14
16
|
|
15
17
|
DOC_BASIC2 = <<-eos
|
@@ -61,6 +63,10 @@ DOC_MULTI = <<-eos
|
|
61
63
|
User -> (Start)
|
62
64
|
User --> (Use the application) : Label
|
63
65
|
|
66
|
+
[plantuml, format="png", test="true"]
|
67
|
+
User -> (Start)
|
68
|
+
User --> (Use the application) : Label
|
69
|
+
|
64
70
|
[plantuml, format="txt", test="true"]
|
65
71
|
User -> (Start)
|
66
72
|
User --> (Use the application) : Label
|
@@ -70,6 +76,12 @@ class PlantUmlTest < Test::Unit::TestCase
|
|
70
76
|
|
71
77
|
GENURL = "http://localhost:8080/plantuml/png/U9npA2v9B2efpStX2YrEBLBGjLFG20Q9Q4Bv804WIw4a8rKXiQ0W9pCviIGpFqzJmKh19p4fDOVB8JKl1QWT05kd5wq0"
|
72
78
|
|
79
|
+
def setup
|
80
|
+
Asciidoctor::PlantUml.configure do |c|
|
81
|
+
c.url = "http://localhost:8080/plantuml"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
73
85
|
def test_plantuml_block_processor
|
74
86
|
|
75
87
|
html = ::Asciidoctor.convert(StringIO.new(DOC_BASIC), backend: "html5")
|
@@ -145,11 +157,9 @@ class PlantUmlTest < Test::Unit::TestCase
|
|
145
157
|
|
146
158
|
page = Nokogiri::HTML(html)
|
147
159
|
|
148
|
-
elements = page.css('
|
149
|
-
assert_equal elements.size, 0
|
150
|
-
|
151
|
-
elements = page.css('div.plantuml')
|
160
|
+
elements = page.css('pre.plantuml-error')
|
152
161
|
assert_equal elements.size, 1
|
162
|
+
|
153
163
|
end
|
154
164
|
|
155
165
|
def test_plantuml_multiple
|
@@ -161,6 +171,23 @@ class PlantUmlTest < Test::Unit::TestCase
|
|
161
171
|
|
162
172
|
assert_equal elements.size, 2
|
163
173
|
|
174
|
+
elements = page.css('pre.plantuml')
|
175
|
+
assert_equal elements.size, 1
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_plantuml_bad_server
|
180
|
+
|
181
|
+
Asciidoctor::PlantUml.configure do |c|
|
182
|
+
c.url = "http://nonexistent.com/plantuml"
|
183
|
+
end
|
184
|
+
|
185
|
+
html = ::Asciidoctor.convert(StringIO.new(DOC_MULTI), backend: "html5")
|
186
|
+
page = Nokogiri::HTML(html)
|
187
|
+
|
188
|
+
elements = page.css('img.plantuml')
|
189
|
+
assert_equal elements.size, 2
|
190
|
+
|
164
191
|
end
|
165
192
|
|
166
193
|
end
|