asciidoctor-diagram 1.5.12 → 1.5.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +6 -0
- data/lib/asciidoctor-diagram/ditaa/converter.rb +55 -0
- data/lib/asciidoctor-diagram/ditaa/extension.rb +7 -45
- data/lib/asciidoctor-diagram/extensions.rb +39 -2
- data/lib/asciidoctor-diagram/util/cli.rb +3 -0
- data/lib/asciidoctor-diagram/version.rb +1 -1
- data/spec/plantuml_spec.rb +54 -0
- data/spec/test_helper.rb +16 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffc1f6fe55704de14ad37b6d54292decde729e9b
|
4
|
+
data.tar.gz: e8e81c21b5918ba8337ff5340382cbe9a311ca37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2426b51df51fa6d625c4a2c2345f3157b0c8eac5cd5683d52680f2908326a2aa385483bdda8780321af7ee96276ae1dcdfb087ca3ed8859aaa7b47df9630389
|
7
|
+
data.tar.gz: 772a8642bda51b9abfba2044fa9d27d5296e5e13dd6d8e4ed7b9298dc4ee93f53e7eb18c94c04e295a407736e97b89465dcccfeaf8428d8884201150f1d414ef
|
data/CHANGELOG.adoc
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative '../util/java'
|
2
|
+
|
3
|
+
module Asciidoctor
|
4
|
+
module Diagram
|
5
|
+
module DitaaConverter
|
6
|
+
OPTIONS = {
|
7
|
+
'scale' => ->(o, v) { o << '--scale' << v if v },
|
8
|
+
'tabs' => ->(o, v) { o << '--tabs' << v if v },
|
9
|
+
'background' => ->(o, v) { o << '--background' << v if v },
|
10
|
+
'antialias' => ->(o, v) { o << '--no-antialias' if v == 'false' },
|
11
|
+
'separation' => ->(o, v) { o << '--no-separation' if v == 'false' },
|
12
|
+
'round-corners' => ->(o, v) { o << '--round-corners' if v == 'true' },
|
13
|
+
'shadows' => ->(o, v) { o << '--no-shadows' if v == 'false' },
|
14
|
+
'debug' => ->(o, v) {o << '--debug' if v == 'true' },
|
15
|
+
'fixed-slope' => ->(o, v) { o << '--fixed-slope' if v == 'true' },
|
16
|
+
'transparent' => ->(o, v) { o << '--transparent' if v == 'true' }
|
17
|
+
}.freeze
|
18
|
+
|
19
|
+
JARS = %w[ditaa-1.3.13.jar ditaamini-0.11.jar].map do |jar|
|
20
|
+
File.expand_path File.join('../..', jar), File.dirname(__FILE__)
|
21
|
+
end
|
22
|
+
Java.classpath.concat JARS
|
23
|
+
|
24
|
+
def self.convert(source, opts)
|
25
|
+
Java.load
|
26
|
+
headers = {
|
27
|
+
Accept: opts['mime_type'],
|
28
|
+
'X-Options' => to_header_options(opts)
|
29
|
+
}
|
30
|
+
send_request(source, headers)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.to_header_options opts
|
34
|
+
options = []
|
35
|
+
OPTIONS.keys.each do |key|
|
36
|
+
value = opts[key]
|
37
|
+
OPTIONS[key].call(options, value)
|
38
|
+
end
|
39
|
+
options.join(' ')
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.send_request(body, headers, url = '/ditaa')
|
43
|
+
response = Java.send_request(
|
44
|
+
url: url,
|
45
|
+
body: body,
|
46
|
+
headers: headers
|
47
|
+
)
|
48
|
+
unless response[:code] == 200
|
49
|
+
raise Java.create_error("Ditaa image generation failed", response)
|
50
|
+
end
|
51
|
+
response[:body]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -1,29 +1,12 @@
|
|
1
1
|
require 'set'
|
2
2
|
|
3
3
|
require_relative '../extensions'
|
4
|
-
require_relative '
|
4
|
+
require_relative 'converter'
|
5
5
|
|
6
6
|
module Asciidoctor
|
7
7
|
module Diagram
|
8
|
-
# @private
|
9
8
|
module Ditaa
|
10
|
-
|
11
|
-
'scale' => lambda { |o, v| o << '--scale' << v if v },
|
12
|
-
'tabs' => lambda { |o, v| o << '--tabs' << v if v },
|
13
|
-
'background' => lambda { |o, v| o << '--background' << v if v },
|
14
|
-
'antialias' => lambda { |o, v| o << '--no-antialias' if v == 'false' },
|
15
|
-
'separation' => lambda { |o, v| o << '--no-separation' if v == 'false'},
|
16
|
-
'round-corners' => lambda { |o, v| o << '--round-corners' if v == 'true'},
|
17
|
-
'shadows' => lambda { |o, v| o << '--no-shadows' if v == 'false'},
|
18
|
-
'debug' => lambda { |o, v| o << '--debug' if v == 'true'},
|
19
|
-
'fixed-slope' => lambda { |o, v| o << '--fixed-slope' if v == 'true'},
|
20
|
-
'transparent' => lambda { |o, v| o << '--transparent' if v == 'true'}
|
21
|
-
}
|
22
|
-
|
23
|
-
JARS = ['ditaa-1.3.13.jar', 'ditaamini-0.11.jar'].map do |jar|
|
24
|
-
File.expand_path File.join('../..', jar), File.dirname(__FILE__)
|
25
|
-
end
|
26
|
-
Java.classpath.concat JARS
|
9
|
+
OPTION_KEYS = DitaaConverter::OPTIONS.keys
|
27
10
|
|
28
11
|
def self.included(mod)
|
29
12
|
mod.register_format(:png, :image) do |parent, source|
|
@@ -36,35 +19,14 @@ module Asciidoctor
|
|
36
19
|
end
|
37
20
|
|
38
21
|
def ditaa(parent, source, mime_type)
|
39
|
-
Java.load
|
40
|
-
|
41
22
|
global_attributes = parent.document.attributes
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
OPTIONS.keys.each do |key|
|
23
|
+
opts = {}
|
24
|
+
opts['mime_type'] = mime_type
|
25
|
+
OPTION_KEYS.each do |key|
|
46
26
|
value = source.attributes.delete(key) || global_attributes["ditaa-option-#{key}"]
|
47
|
-
|
27
|
+
opts[key] = value if value
|
48
28
|
end
|
49
|
-
|
50
|
-
options_string = options.join(' ')
|
51
|
-
|
52
|
-
headers = {
|
53
|
-
'Accept' => mime_type,
|
54
|
-
'X-Options' => options_string
|
55
|
-
}
|
56
|
-
|
57
|
-
response = Java.send_request(
|
58
|
-
:url => '/ditaa',
|
59
|
-
:body => source.to_s,
|
60
|
-
:headers => headers
|
61
|
-
)
|
62
|
-
|
63
|
-
unless response[:code] == 200
|
64
|
-
raise Java.create_error("Ditaa image generation failed", response)
|
65
|
-
end
|
66
|
-
|
67
|
-
response[:body]
|
29
|
+
DitaaConverter.convert(source.to_s, opts)
|
68
30
|
end
|
69
31
|
end
|
70
32
|
|
@@ -282,7 +282,7 @@ module Asciidoctor
|
|
282
282
|
end
|
283
283
|
|
284
284
|
if document.nested? && value.nil?
|
285
|
-
doc_option(
|
285
|
+
doc_option(document.parent_document, key)
|
286
286
|
else
|
287
287
|
value
|
288
288
|
end
|
@@ -510,12 +510,49 @@ module Asciidoctor
|
|
510
510
|
def read_code
|
511
511
|
if @file_name
|
512
512
|
lines = File.readlines(@file_name)
|
513
|
-
lines =
|
513
|
+
lines = prepare_source_array(lines)
|
514
514
|
@parent_block.apply_subs(lines, resolve_diagram_subs).join("\n")
|
515
515
|
else
|
516
516
|
''
|
517
517
|
end
|
518
518
|
end
|
519
|
+
|
520
|
+
private
|
521
|
+
|
522
|
+
# Byte arrays for UTF-* Byte Order Marks
|
523
|
+
BOM_BYTES_UTF_8 = [0xef, 0xbb, 0xbf]
|
524
|
+
BOM_BYTES_UTF_16LE = [0xff, 0xfe]
|
525
|
+
BOM_BYTES_UTF_16BE = [0xfe, 0xff]
|
526
|
+
|
527
|
+
# Prepare the source data Array for parsing.
|
528
|
+
#
|
529
|
+
# Encodes the data to UTF-8, if necessary, and removes any trailing
|
530
|
+
# whitespace from every line.
|
531
|
+
#
|
532
|
+
# If a BOM is found at the beginning of the data, a best attempt is made to
|
533
|
+
# encode it to UTF-8 from the specified source encoding.
|
534
|
+
#
|
535
|
+
# data - the source data Array to prepare (no nil entries allowed)
|
536
|
+
#
|
537
|
+
# returns a String Array of prepared lines
|
538
|
+
def prepare_source_array data
|
539
|
+
return [] if data.empty?
|
540
|
+
if (leading_2_bytes = (leading_bytes = (first = data[0]).unpack 'C3').slice 0, 2) == BOM_BYTES_UTF_16LE
|
541
|
+
data[0] = first.byteslice 2, first.bytesize
|
542
|
+
# NOTE you can't split a UTF-16LE string using .lines when encoding is UTF-8; doing so will cause this line to fail
|
543
|
+
return data.map {|line| (line.encode ::Encoding::UTF_8, ::Encoding::UTF_16LE).rstrip }
|
544
|
+
elsif leading_2_bytes == BOM_BYTES_UTF_16BE
|
545
|
+
data[0] = first.byteslice 2, first.bytesize
|
546
|
+
return data.map {|line| (line.encode ::Encoding::UTF_8, ::Encoding::UTF_16BE).rstrip }
|
547
|
+
elsif leading_bytes == BOM_BYTES_UTF_8
|
548
|
+
data[0] = first.byteslice 3, first.bytesize
|
549
|
+
end
|
550
|
+
if first.encoding == ::Encoding::UTF_8
|
551
|
+
data.map {|line| line.rstrip }
|
552
|
+
else
|
553
|
+
data.map {|line| (line.encode ::Encoding::UTF_8).rstrip }
|
554
|
+
end
|
555
|
+
end
|
519
556
|
end
|
520
557
|
end
|
521
558
|
end
|
@@ -3,6 +3,9 @@ module Asciidoctor
|
|
3
3
|
# @private
|
4
4
|
module Cli
|
5
5
|
if RUBY_PLATFORM == "java"
|
6
|
+
# Workaround for https://github.com/jruby/jruby/issues/5565
|
7
|
+
# Kernel.spawn (and as a consequence Open3.capture3 which uses it)
|
8
|
+
# is not reliable on all versions of JRuby.
|
6
9
|
require_relative 'java'
|
7
10
|
|
8
11
|
def self.run(*args)
|
data/spec/plantuml_spec.rb
CHANGED
@@ -532,6 +532,60 @@ Foo1 -> Foo2 : To boundary
|
|
532
532
|
expect(File.exist?(File.expand_path(target, 'foo'))).to be true
|
533
533
|
end
|
534
534
|
|
535
|
+
it 'should write files to to_dir if set' do
|
536
|
+
doc = <<-eos
|
537
|
+
= Hello, PlantUML!
|
538
|
+
Doc Writer <doc@example.com>
|
539
|
+
|
540
|
+
== First Section
|
541
|
+
|
542
|
+
[plantuml, format="svg"]
|
543
|
+
----
|
544
|
+
actor Foo1
|
545
|
+
boundary Foo2
|
546
|
+
Foo1 -> Foo2 : To boundary
|
547
|
+
----
|
548
|
+
eos
|
549
|
+
|
550
|
+
d = load_asciidoc doc, {:to_dir => 'foo'}
|
551
|
+
b = d.find { |bl| bl.context == :image }
|
552
|
+
|
553
|
+
target = b.attributes['target']
|
554
|
+
expect(target).to_not be_nil
|
555
|
+
expect(File.exist?(target)).to be false
|
556
|
+
expect(File.exist?(File.expand_path(target, 'foo'))).to be true
|
557
|
+
end
|
558
|
+
|
559
|
+
it 'should write files to to_dir if set when embedded in table' do
|
560
|
+
doc = <<-eos
|
561
|
+
= Hello, PlantUML!
|
562
|
+
Doc Writer <doc@example.com>
|
563
|
+
|
564
|
+
== First Section
|
565
|
+
|
566
|
+
|===
|
567
|
+
|Type | Example
|
568
|
+
|
569
|
+
|graphviz
|
570
|
+
a|
|
571
|
+
[plantuml, format="svg"]
|
572
|
+
----
|
573
|
+
actor Foo1
|
574
|
+
boundary Foo2
|
575
|
+
Foo1 -> Foo2 : To boundary
|
576
|
+
----
|
577
|
+
|===
|
578
|
+
eos
|
579
|
+
|
580
|
+
d = load_asciidoc doc, {:to_dir => 'foo'}
|
581
|
+
b = d.find { |bl| bl.context == :image }
|
582
|
+
|
583
|
+
target = b.attributes['target']
|
584
|
+
expect(target).to_not be_nil
|
585
|
+
expect(File.exist?(target)).to be false
|
586
|
+
expect(File.exist?(File.expand_path(target, 'foo'))).to be true
|
587
|
+
end
|
588
|
+
|
535
589
|
it 'should write files to imagesoutdir if set' do
|
536
590
|
doc = <<-eos
|
537
591
|
= Hello, PlantUML!
|
data/spec/test_helper.rb
CHANGED
@@ -40,6 +40,22 @@ module Asciidoctor
|
|
40
40
|
nil
|
41
41
|
end
|
42
42
|
end
|
43
|
+
|
44
|
+
class Table
|
45
|
+
def find(&block)
|
46
|
+
rows.by_section.each do |section, rows|
|
47
|
+
rows.each do |row|
|
48
|
+
row.each do |cell|
|
49
|
+
inner_doc = cell.inner_document
|
50
|
+
if !inner_doc.nil? && found_block = cell.inner_document.find(&block)
|
51
|
+
return found_block
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
end
|
43
59
|
end
|
44
60
|
|
45
61
|
module Asciidoctor
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-diagram
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pepijn Van Eeckhoudt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-30 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: '
|
19
|
+
version: '0'
|
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: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- lib/asciidoctor-diagram/blockdiag.rb
|
91
91
|
- lib/asciidoctor-diagram/blockdiag/extension.rb
|
92
92
|
- lib/asciidoctor-diagram/ditaa.rb
|
93
|
+
- lib/asciidoctor-diagram/ditaa/converter.rb
|
93
94
|
- lib/asciidoctor-diagram/ditaa/extension.rb
|
94
95
|
- lib/asciidoctor-diagram/erd.rb
|
95
96
|
- lib/asciidoctor-diagram/erd/extension.rb
|