asciidoctor-plantuml 0.0.16 → 0.1.0
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.rb +1 -0
- data/lib/asciidoctor_plantuml/plantuml.rb +65 -22
- data/lib/asciidoctor_plantuml/version.rb +1 -1
- data/test/fixtures/config.puml +3 -0
- data/test/fixtures/test.puml +4 -0
- data/test/test_plantuml.rb +129 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06c1cf16fb57543cec6f90c9d907894ebe6c8b8888396f5cfeb9305340f130c1
|
4
|
+
data.tar.gz: 82488d9c4c5431c9244e0ad834bfbb2ae88ef1fe38146cca7d369352f967ff4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71e3258bc87c722dc6c393129ca5b5984c4ac45f4ea3f6c7ef49907d9dc71c605a1650852bcf6b6f9201115179f3672724883eaa6db0947dca387bb1a7ecf47c
|
7
|
+
data.tar.gz: 41993506e615c6ce9180b5677d2bb40a83e18b33abae1b1d16e96ed5b0493d773a747659a4c08be24a13728ac0303e3c63f31ea194b109decec8f0148f7ef79f
|
data/lib/asciidoctor-plantuml.rb
CHANGED
@@ -78,23 +78,48 @@ module Asciidoctor
|
|
78
78
|
txt_enabled? || png_enabled? || svg_enabled?
|
79
79
|
end
|
80
80
|
|
81
|
-
def plantuml_content_format(code, format, attrs = {})
|
82
|
-
|
83
|
-
|
84
|
-
|
81
|
+
def plantuml_content_format(parent, code, format, attrs = {})
|
82
|
+
content = code.read
|
83
|
+
|
84
|
+
# honor subs attributes
|
85
|
+
# e.g. replace asciidoc variables
|
86
|
+
subs = attrs['subs']
|
87
|
+
content = parent.apply_subs(content, parent.resolve_subs(subs)) if subs
|
88
|
+
|
89
|
+
# add @start... and @end... if missing
|
90
|
+
content = "@startuml\n#{content}\n@enduml" unless content =~ /^@start.*@end[a-z]*$/m
|
91
|
+
|
92
|
+
# insert global plantuml config after first line
|
93
|
+
config_path = parent.attr('plantuml-include', '', true)
|
94
|
+
begin
|
95
|
+
content = insert_config_to_content(parent, config_path, content, attrs) unless config_path.empty?
|
96
|
+
rescue StandardError => e
|
97
|
+
return plantuml_invalid_file(config_path, e.message, attrs)
|
98
|
+
end
|
99
|
+
|
100
|
+
if %w[png svg txt].include?(format) && method("#{format}_enabled?").call
|
101
|
+
method("plantuml_#{format}_content").call(content, format, attrs)
|
85
102
|
else
|
86
103
|
plantuml_invalid_content(format, attrs)
|
87
104
|
end
|
88
105
|
end
|
89
106
|
|
90
|
-
def plantuml_content(code, attrs = {})
|
107
|
+
def plantuml_content(parent, code, attrs = {})
|
91
108
|
format = attrs['format'] || DEFAULT_FORMAT
|
92
109
|
|
93
110
|
return plantuml_disabled_content(code, attrs) unless enabled?
|
94
111
|
|
95
112
|
return plantuml_server_unavailable_content(server_url, attrs) unless valid_uri?(server_url)
|
96
113
|
|
97
|
-
plantuml_content_format(code, format, attrs)
|
114
|
+
plantuml_content_format(parent, code, format, attrs)
|
115
|
+
end
|
116
|
+
|
117
|
+
def plantuml_content_from_file(parent, source_file, attrs = {})
|
118
|
+
File.open(source_file) do |f|
|
119
|
+
return plantuml_content(parent, f, attrs)
|
120
|
+
end
|
121
|
+
rescue StandardError => e
|
122
|
+
plantuml_invalid_file(source_file, e.message, attrs)
|
98
123
|
end
|
99
124
|
|
100
125
|
# Compression code used to generate PlantUML URLs. Taken directly from
|
@@ -113,8 +138,25 @@ module Asciidoctor
|
|
113
138
|
join_paths(server_url, "#{format}/", result).to_s
|
114
139
|
end
|
115
140
|
|
141
|
+
def create_plantuml_block(parent, content, attrs)
|
142
|
+
Asciidoctor::Block.new parent, :pass, {
|
143
|
+
content_model: :raw,
|
144
|
+
source: content,
|
145
|
+
subs: :default
|
146
|
+
}.merge(attrs)
|
147
|
+
end
|
148
|
+
|
116
149
|
private
|
117
150
|
|
151
|
+
def insert_config_to_content(parent, config_path, content, attrs)
|
152
|
+
File.open(config_path) do |file|
|
153
|
+
config = file.read
|
154
|
+
subs = attrs['subs']
|
155
|
+
config = parent.apply_subs(config, parent.resolve_subs(subs)) if subs
|
156
|
+
return content.dup.insert(content.index("\n"), "\n#{config}") unless config.empty?
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
118
160
|
def plantuml_txt_content(code, format, attrs = {})
|
119
161
|
url = gen_url(code, format)
|
120
162
|
URI(url).open do |f|
|
@@ -180,6 +222,11 @@ module Asciidoctor
|
|
180
222
|
_plantuml_error_content(code, attrs)
|
181
223
|
end
|
182
224
|
|
225
|
+
def plantuml_invalid_file(file, error, attrs = {})
|
226
|
+
error = "PlantUML Error: Could not parse \"#{file}\": #{error}"
|
227
|
+
_plantuml_error_content(error, attrs)
|
228
|
+
end
|
229
|
+
|
183
230
|
def _plantuml_error_content(error, attrs = {})
|
184
231
|
content = '<div class="listingblock">'
|
185
232
|
content += '<div class="content">'
|
@@ -263,25 +310,21 @@ module Asciidoctor
|
|
263
310
|
content_model :simple
|
264
311
|
|
265
312
|
def process(parent, target, attrs)
|
266
|
-
|
267
|
-
|
268
|
-
lines = ['@startuml'] + target.lines unless target.lines[0] =~ /@startuml/
|
269
|
-
|
270
|
-
lines += ['@enduml'] unless target.lines[-1] =~ /@enduml/
|
271
|
-
|
272
|
-
content = Processor.plantuml_content(lines.join("\n"), attrs)
|
273
|
-
|
274
|
-
create_plantuml_block(parent, content, attrs)
|
313
|
+
content = Processor.plantuml_content(parent, target, attrs)
|
314
|
+
Processor.create_plantuml_block(parent, content, attrs)
|
275
315
|
end
|
316
|
+
end
|
276
317
|
|
277
|
-
|
318
|
+
# PlantUML BlockMacroProcessor
|
319
|
+
class BlockMacroProcessor < Asciidoctor::Extensions::BlockMacroProcessor
|
320
|
+
use_dsl
|
321
|
+
named :plantuml
|
278
322
|
|
279
|
-
def
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
}.merge(attrs)
|
323
|
+
def process(parent, target, attrs)
|
324
|
+
base_dir = parent.document.base_dir
|
325
|
+
source_file = parent.document.path_resolver.system_path(target, base_dir, base_dir)
|
326
|
+
content = Processor.plantuml_content_from_file(parent, source_file, attrs)
|
327
|
+
Processor.create_plantuml_block(parent, content, attrs)
|
285
328
|
end
|
286
329
|
end
|
287
330
|
end
|
data/test/test_plantuml.rb
CHANGED
@@ -184,10 +184,69 @@ DOC_SVG = <<~ENDOFSTRING
|
|
184
184
|
----
|
185
185
|
ENDOFSTRING
|
186
186
|
|
187
|
+
DOC_BLOCK_MACRO = <<~ENDOFSTRING
|
188
|
+
= Hello PlantUML!
|
189
|
+
|
190
|
+
.Title Of this
|
191
|
+
plantuml::test/fixtures/test.puml[]
|
192
|
+
ENDOFSTRING
|
193
|
+
|
194
|
+
DOC_BLOCK_MACRO_MISSING_FILE = <<~ENDOFSTRING
|
195
|
+
= Hello PlantUML!
|
196
|
+
|
197
|
+
.Title Of this
|
198
|
+
plantuml::test/fixtures/missing.puml[]
|
199
|
+
ENDOFSTRING
|
200
|
+
|
201
|
+
DOC_SUBS_ATTRIBUTES = <<~ENDOFSTRING
|
202
|
+
= Hello PlantUML!
|
203
|
+
:text: Label
|
204
|
+
|
205
|
+
[plantuml, format="png", subs="attributes+"]
|
206
|
+
.Title Of this
|
207
|
+
----
|
208
|
+
User -> (Start)
|
209
|
+
User --> (Use the application) : {text}
|
210
|
+
----
|
211
|
+
ENDOFSTRING
|
212
|
+
|
213
|
+
DOC_CONFIG_INCLUDE = <<~ENDOFSTRING
|
214
|
+
= Hello PlantUML!
|
215
|
+
:plantuml-include: test/fixtures/config.puml
|
216
|
+
|
217
|
+
[plantuml, format="png"]
|
218
|
+
.Title Of this
|
219
|
+
----
|
220
|
+
User -> (Start)
|
221
|
+
User --> (Use the application) : Label
|
222
|
+
----
|
223
|
+
ENDOFSTRING
|
224
|
+
|
225
|
+
DOC_CONFIG_INCLUDE_MISSING_FILE = <<~ENDOFSTRING
|
226
|
+
= Hello PlantUML!
|
227
|
+
:plantuml-include: test/fixtures/missing.puml
|
228
|
+
|
229
|
+
[plantuml, format="png"]
|
230
|
+
.Title Of this
|
231
|
+
----
|
232
|
+
User -> (Start)
|
233
|
+
User --> (Use the application) : Label
|
234
|
+
----
|
235
|
+
ENDOFSTRING
|
236
|
+
|
237
|
+
DOC_CONFIG_INCLUDE_MACRO_BLOCK = <<~ENDOFSTRING
|
238
|
+
= Hello PlantUML!
|
239
|
+
:plantuml-include: test/fixtures/config.puml
|
240
|
+
|
241
|
+
[plantuml, format="png"]
|
242
|
+
plantuml::test/fixtures/test.puml[]
|
243
|
+
ENDOFSTRING
|
244
|
+
|
187
245
|
class PlantUmlTest < Test::Unit::TestCase
|
188
246
|
GENURL = 'http://localhost:8080/plantuml/png/U9npA2v9B2efpStX2YrEBLBGjLFG20Q9Q4Bv804WIw4a8rKXiQ0W9pCviIGpFqzJmKh19p4fDOVB8JKl1QWT05kd5wq0'
|
189
247
|
GENURL2 = 'http://localhost:8080/plantuml/png/U9npA2v9B2efpStXYdRszmqmZ8NGHh4mleAkdGAAa15G22Pc7Clba9gN0jGE00W75Cm0'
|
190
248
|
GENURL_ENCODING = 'http://localhost:8080/plantuml/png/~1U9npA2v9B2efpStX2YrEBLBGjLFG20Q9Q4Bv804WIw4a8rKXiQ0W9pCviIGpFqzJmKh19p4fDOVB8JKl1QWT05kd5wq0'
|
249
|
+
GENURL_CONFIG = 'http://localhost:8080/plantuml/png/~1U9nDZJ4Emp08HVUSWh4PUe4ELQIktQeUW3YeiMA31NZexKEg3bc-Fly1Vp97zLxBO5lcXeeLgh2aLQKIk7OwaHdJzb7fl3oaY0P6ja34Vjeo_nOArPn-dzz62jSxN5v7r_YVZo0S-4g0hPMSqBFm23Tuuanbc8YNEDy1SzOwlG00'
|
191
250
|
SVGGENURL = 'http://localhost:8080/plantuml/svg/~1U9npA2v9B2efpStX2YrEBLBGjLFG20Q9Q4Bv804WIw4a8rKXiQ0W9pCviIGpFqzJmKh19p4fDOVB8JKl1QWT05kd5wq0'
|
192
251
|
|
193
252
|
def setup
|
@@ -302,6 +361,76 @@ class PlantUmlTest < Test::Unit::TestCase
|
|
302
361
|
assert_equal GENURL_ENCODING, element['src']
|
303
362
|
end
|
304
363
|
|
364
|
+
def test_plantuml_block_macro_processor
|
365
|
+
html = ::Asciidoctor.convert(StringIO.new(DOC_BLOCK_MACRO), backend: 'html5')
|
366
|
+
page = Nokogiri::HTML(html)
|
367
|
+
|
368
|
+
elements = page.css('img.plantuml')
|
369
|
+
|
370
|
+
assert_equal elements.size, 1
|
371
|
+
|
372
|
+
element = elements.first
|
373
|
+
|
374
|
+
assert_equal GENURL, element['src']
|
375
|
+
end
|
376
|
+
|
377
|
+
def test_should_show_file_error
|
378
|
+
html = ::Asciidoctor.convert(StringIO.new(DOC_BLOCK_MACRO_MISSING_FILE), backend: 'html5')
|
379
|
+
page = Nokogiri::HTML(html)
|
380
|
+
|
381
|
+
elements = page.css('pre.plantuml-error')
|
382
|
+
assert_equal elements.size, 1
|
383
|
+
assert_includes html, 'No such file or directory'
|
384
|
+
end
|
385
|
+
|
386
|
+
def test_plantuml_subs_attributes
|
387
|
+
html = ::Asciidoctor.convert(StringIO.new(DOC_SUBS_ATTRIBUTES), backend: 'html5')
|
388
|
+
page = Nokogiri::HTML(html)
|
389
|
+
|
390
|
+
elements = page.css('img.plantuml')
|
391
|
+
|
392
|
+
assert_equal elements.size, 1
|
393
|
+
|
394
|
+
element = elements.first
|
395
|
+
|
396
|
+
assert_equal GENURL_ENCODING, element['src']
|
397
|
+
end
|
398
|
+
|
399
|
+
def test_plantuml_config_include
|
400
|
+
html = ::Asciidoctor.convert(StringIO.new(DOC_CONFIG_INCLUDE), backend: 'html5')
|
401
|
+
page = Nokogiri::HTML(html)
|
402
|
+
|
403
|
+
elements = page.css('img.plantuml')
|
404
|
+
|
405
|
+
assert_equal elements.size, 1
|
406
|
+
|
407
|
+
element = elements.first
|
408
|
+
|
409
|
+
assert_equal GENURL_CONFIG, element['src']
|
410
|
+
end
|
411
|
+
|
412
|
+
def test_plantuml_config_include_missing_file
|
413
|
+
html = ::Asciidoctor.convert(StringIO.new(DOC_CONFIG_INCLUDE_MISSING_FILE), backend: 'html5')
|
414
|
+
page = Nokogiri::HTML(html)
|
415
|
+
|
416
|
+
elements = page.css('pre.plantuml-error')
|
417
|
+
assert_equal elements.size, 1
|
418
|
+
assert_includes html, 'No such file or directory'
|
419
|
+
end
|
420
|
+
|
421
|
+
def test_plantuml_config_include_macro_block
|
422
|
+
html = ::Asciidoctor.convert(StringIO.new(DOC_CONFIG_INCLUDE_MACRO_BLOCK), backend: 'html5')
|
423
|
+
page = Nokogiri::HTML(html)
|
424
|
+
|
425
|
+
elements = page.css('img.plantuml')
|
426
|
+
|
427
|
+
assert_equal elements.size, 1
|
428
|
+
|
429
|
+
element = elements.first
|
430
|
+
|
431
|
+
assert_equal GENURL_CONFIG, element['src']
|
432
|
+
end
|
433
|
+
|
305
434
|
def test_plantuml_id_attribute
|
306
435
|
html = ::Asciidoctor.convert(StringIO.new(DOC_ID), backend: 'html5')
|
307
436
|
page = Nokogiri::HTML(html)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Horacio Sanson
|
@@ -110,6 +110,8 @@ files:
|
|
110
110
|
- lib/asciidoctor-plantuml.rb
|
111
111
|
- lib/asciidoctor_plantuml/plantuml.rb
|
112
112
|
- lib/asciidoctor_plantuml/version.rb
|
113
|
+
- test/fixtures/config.puml
|
114
|
+
- test/fixtures/test.puml
|
113
115
|
- test/test_plantuml.rb
|
114
116
|
homepage: https://github.com/hsanson/asciidoctor-plantuml
|
115
117
|
licenses:
|
@@ -136,4 +138,6 @@ signing_key:
|
|
136
138
|
specification_version: 4
|
137
139
|
summary: Asciidoctor support for PlantUML diagrams.
|
138
140
|
test_files:
|
141
|
+
- test/fixtures/config.puml
|
142
|
+
- test/fixtures/test.puml
|
139
143
|
- test/test_plantuml.rb
|