asciidoctor-diagram 2.0.2 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +25 -0
- data/README.adoc +13 -4
- data/lib/asciidoctor-diagram.rb +3 -0
- data/lib/asciidoctor-diagram/a2s/converter.rb +10 -6
- data/lib/asciidoctor-diagram/blockdiag/converter.rb +1 -1
- data/lib/asciidoctor-diagram/bpmn/converter.rb +3 -3
- data/lib/asciidoctor-diagram/diagram_converter.rb +5 -1
- data/lib/asciidoctor-diagram/diagram_processor.rb +64 -38
- data/lib/asciidoctor-diagram/diagram_source.rb +64 -17
- data/lib/asciidoctor-diagram/ditaa/converter.rb +6 -2
- data/lib/asciidoctor-diagram/dpic.rb +7 -0
- data/lib/asciidoctor-diagram/dpic/converter.rb +30 -0
- data/lib/asciidoctor-diagram/dpic/extension.rb +14 -0
- data/lib/asciidoctor-diagram/gnuplot/converter.rb +8 -8
- data/lib/asciidoctor-diagram/graphviz/converter.rb +2 -2
- data/lib/asciidoctor-diagram/http/converter.rb +25 -5
- data/lib/asciidoctor-diagram/http/server.rb +10 -5
- data/lib/asciidoctor-diagram/lilypond/converter.rb +2 -2
- data/lib/asciidoctor-diagram/meme/converter.rb +7 -7
- data/lib/asciidoctor-diagram/mermaid/converter.rb +16 -15
- data/lib/asciidoctor-diagram/msc/converter.rb +2 -2
- data/lib/asciidoctor-diagram/pikchr.rb +7 -0
- data/lib/asciidoctor-diagram/pikchr/converter.rb +26 -0
- data/lib/asciidoctor-diagram/pikchr/extension.rb +14 -0
- data/lib/asciidoctor-diagram/plantuml/converter.rb +3 -3
- data/lib/asciidoctor-diagram/smcat/converter.rb +3 -3
- data/lib/asciidoctor-diagram/svgbob/converter.rb +2 -2
- data/lib/asciidoctor-diagram/symbolator.rb +7 -0
- data/lib/asciidoctor-diagram/symbolator/converter.rb +23 -0
- data/lib/asciidoctor-diagram/symbolator/extension.rb +14 -0
- data/lib/asciidoctor-diagram/syntrax/converter.rb +9 -6
- data/lib/asciidoctor-diagram/util/cli_generator.rb +18 -0
- data/lib/asciidoctor-diagram/util/gif.rb +2 -2
- data/lib/asciidoctor-diagram/util/pdf.rb +2 -2
- data/lib/asciidoctor-diagram/util/png.rb +2 -2
- data/lib/asciidoctor-diagram/util/svg.rb +46 -19
- data/lib/asciidoctor-diagram/vega/converter.rb +2 -2
- data/lib/asciidoctor-diagram/version.rb +1 -1
- data/spec/a2s_spec.rb +2 -140
- data/spec/blockdiag_spec.rb +2 -200
- data/spec/bpmn_spec.rb +52 -92
- data/spec/bytefield_spec.rb +2 -140
- data/spec/ditaa_spec.rb +5 -143
- data/spec/dpic_spec.rb +19 -0
- data/spec/erd_spec.rb +2 -199
- data/spec/gnuplot_spec.rb +2 -255
- data/spec/graphviz_spec.rb +6 -145
- data/spec/lilypond_spec.rb +2 -140
- data/spec/mermaid_spec.rb +2 -199
- data/spec/msc_spec.rb +2 -199
- data/spec/nomnoml_spec.rb +4 -142
- data/spec/pikchr_spec.rb +51 -0
- data/spec/plantuml_spec.rb +6 -578
- data/spec/shaape_spec.rb +9 -221
- data/spec/shared_examples.rb +552 -0
- data/spec/smcat_spec.rb +2 -140
- data/spec/svgbob_spec.rb +2 -140
- data/spec/symbolator_spec.rb +23 -0
- data/spec/syntrax_spec.rb +5 -215
- data/spec/test_helper.rb +1 -22
- data/spec/tikz_spec.rb +4 -24
- data/spec/umlet_spec.rb +2 -58
- data/spec/vega_spec.rb +4 -117
- data/spec/wavedrom_spec.rb +2 -199
- metadata +20 -6
- data/spec/bpmn-example.xml +0 -44
@@ -33,17 +33,21 @@ module Asciidoctor
|
|
33
33
|
[:png, :svg]
|
34
34
|
end
|
35
35
|
|
36
|
-
def collect_options(source
|
36
|
+
def collect_options(source)
|
37
37
|
options = {}
|
38
38
|
|
39
39
|
OPTIONS.keys.each do |option|
|
40
40
|
attr_name = option.to_s.tr('_', '-')
|
41
|
-
options[option] = source.attr(attr_name
|
41
|
+
options[option] = source.attr(attr_name) || source.attr(attr_name, nil, 'ditaa-option')
|
42
42
|
end
|
43
43
|
|
44
44
|
options
|
45
45
|
end
|
46
46
|
|
47
|
+
def native_scaling?
|
48
|
+
true
|
49
|
+
end
|
50
|
+
|
47
51
|
def convert(source, format, options)
|
48
52
|
Java.load
|
49
53
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative '../diagram_converter'
|
2
|
+
require_relative '../util/cli_generator'
|
3
|
+
require_relative '../util/platform'
|
4
|
+
|
5
|
+
module Asciidoctor
|
6
|
+
module Diagram
|
7
|
+
# @private
|
8
|
+
class DpicConverter
|
9
|
+
include DiagramConverter
|
10
|
+
include CliGenerator
|
11
|
+
|
12
|
+
|
13
|
+
def supported_formats
|
14
|
+
[:svg]
|
15
|
+
end
|
16
|
+
|
17
|
+
def convert(source, format, options)
|
18
|
+
dpic_path = source.find_command('dpic')
|
19
|
+
|
20
|
+
code = source.to_s
|
21
|
+
code.prepend ".PS\n" unless code.start_with?(".PS\n")
|
22
|
+
code << "\n.PE" unless code.start_with?("\n.PE")
|
23
|
+
|
24
|
+
generate_file_stdout(dpic_path, format.to_s, code) do |tool_path, input_path|
|
25
|
+
[tool_path, "-v", "-z", input_path]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative 'converter'
|
2
|
+
require_relative '../diagram_processor'
|
3
|
+
|
4
|
+
module Asciidoctor
|
5
|
+
module Diagram
|
6
|
+
class DpicBlockProcessor < DiagramBlockProcessor
|
7
|
+
use_converter DpicConverter
|
8
|
+
end
|
9
|
+
|
10
|
+
class DpicBlockMacroProcessor < DiagramBlockMacroProcessor
|
11
|
+
use_converter DpicConverter
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -14,15 +14,15 @@ module Asciidoctor
|
|
14
14
|
[:png, :svg, :gif, :txt, :literal]
|
15
15
|
end
|
16
16
|
|
17
|
-
def collect_options(source
|
17
|
+
def collect_options(source)
|
18
18
|
{
|
19
|
-
:width => source.attr('width'
|
20
|
-
:height => source.attr('height'
|
21
|
-
:transparent => source.attr('transparent'
|
22
|
-
:crop => source.attr('crop'
|
23
|
-
:font => source.attr('font'
|
24
|
-
:fontscale => source.attr('fontscale'
|
25
|
-
:background => source.attr('background'
|
19
|
+
:width => source.attr('width'),
|
20
|
+
:height => source.attr('height'),
|
21
|
+
:transparent => source.attr('transparent'),
|
22
|
+
:crop => source.attr('crop'),
|
23
|
+
:font => source.attr('font'),
|
24
|
+
:fontscale => source.attr('fontscale'),
|
25
|
+
:background => source.attr('background'),
|
26
26
|
}
|
27
27
|
end
|
28
28
|
|
@@ -51,6 +51,7 @@ module Asciidoctor
|
|
51
51
|
path << '/' unless path.end_with? '/'
|
52
52
|
path << format.to_s
|
53
53
|
path << '/' << data
|
54
|
+
uri.path = path
|
54
55
|
when :kroki_io
|
55
56
|
compressed = Zlib.deflate(code, Zlib::BEST_COMPRESSION)
|
56
57
|
data = Base64.urlsafe_encode64(compressed)
|
@@ -60,17 +61,36 @@ module Asciidoctor
|
|
60
61
|
path << options[:block_name].to_s
|
61
62
|
path << '/' << format.to_s
|
62
63
|
path << '/' << data
|
64
|
+
uri.path = path
|
63
65
|
else
|
64
66
|
raise "Unsupported server type: " + @type
|
65
67
|
end
|
66
68
|
|
69
|
+
get_uri(uri)
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def get_uri(uri, attempt = 1)
|
75
|
+
if attempt >= 10
|
76
|
+
raise "Too many redirects"
|
77
|
+
end
|
78
|
+
|
67
79
|
Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme.downcase == 'https') do |http|
|
68
|
-
response = http.request_get path
|
80
|
+
response = http.request_get uri.path
|
69
81
|
case response
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
82
|
+
when Net::HTTPSuccess
|
83
|
+
response.body
|
84
|
+
when Net::HTTPRedirection then
|
85
|
+
location = response['Location']
|
86
|
+
new_uri = URI.parse(location)
|
87
|
+
if new_uri.relative?
|
88
|
+
get_uri(uri + location, attempt + 1)
|
89
|
+
else
|
90
|
+
get_uri(new_uri, attempt + 1)
|
91
|
+
end
|
92
|
+
else
|
93
|
+
response.value
|
74
94
|
end
|
75
95
|
end
|
76
96
|
end
|
@@ -67,15 +67,15 @@ module Asciidoctor
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
def render_diagram(type, accepts,
|
70
|
+
def render_diagram(type, accepts, source, attributes)
|
71
71
|
converter = get_converter(type.downcase.to_sym)
|
72
72
|
return [500, "Unsupported diagram type #{type}"] unless converter
|
73
73
|
|
74
74
|
format = converter.supported_formats.find {|f| accepts.call(f)}
|
75
75
|
return [500, "Could not determine supported output format"] unless format
|
76
76
|
|
77
|
-
source = ServerSource.new(
|
78
|
-
options = converter.collect_options(source
|
77
|
+
source = ServerSource.new(type.downcase, source, attributes)
|
78
|
+
options = converter.collect_options(source)
|
79
79
|
diagram = converter.convert(source, format, options)
|
80
80
|
|
81
81
|
content_type to_mime_type(format)
|
@@ -86,12 +86,17 @@ module Asciidoctor
|
|
86
86
|
class ServerSource
|
87
87
|
include Asciidoctor::Diagram::DiagramSource
|
88
88
|
|
89
|
-
def initialize(source, attributes)
|
89
|
+
def initialize(name, source, attributes)
|
90
|
+
@name = name
|
90
91
|
@source = source
|
91
92
|
@attributes = attributes
|
92
93
|
end
|
93
94
|
|
94
|
-
def
|
95
|
+
def diagram_type
|
96
|
+
@name
|
97
|
+
end
|
98
|
+
|
99
|
+
def attr(name, default_value = nil, inherit = diagram_type)
|
95
100
|
@attributes[name] || default_value
|
96
101
|
end
|
97
102
|
|
@@ -15,20 +15,20 @@ module Asciidoctor
|
|
15
15
|
end
|
16
16
|
|
17
17
|
|
18
|
-
def collect_options(source
|
19
|
-
bg_img = source.attr('background'
|
18
|
+
def collect_options(source)
|
19
|
+
bg_img = source.attr('background')
|
20
20
|
raise "background attribute is required" unless bg_img
|
21
21
|
|
22
|
-
options = source.attr('options', ''
|
22
|
+
options = source.attr('options', '').split(',')
|
23
23
|
|
24
24
|
{
|
25
25
|
:bg_img => bg_img,
|
26
26
|
:top_label => source.attr('top'),
|
27
27
|
:bottom_label => source.attr('bottom'),
|
28
|
-
:fill_color => source.attr('fillcolor',
|
29
|
-
:stroke_color => source.attr('strokecolor',
|
30
|
-
:stroke_width => source.attr('strokewidth',
|
31
|
-
:font => source.attr('font', 'Impact'
|
28
|
+
:fill_color => source.attr(['fillcolor', 'fill-color']),
|
29
|
+
:stroke_color => source.attr(['strokecolor', 'stroke-color']),
|
30
|
+
:stroke_width => source.attr(['strokewidth', 'stroke-width']),
|
31
|
+
:font => source.attr('font', 'Impact'),
|
32
32
|
:noupcase => options.include?('noupcase'),
|
33
33
|
}
|
34
34
|
end
|
@@ -15,18 +15,18 @@ module Asciidoctor
|
|
15
15
|
[:png, :svg]
|
16
16
|
end
|
17
17
|
|
18
|
-
def collect_options(source
|
18
|
+
def collect_options(source)
|
19
19
|
options = {}
|
20
20
|
|
21
|
-
options[:css] = source.attr('css'
|
22
|
-
options[:gantt_config] = source.attr('ganttconfig',
|
23
|
-
options[:seq_config] = source.attr('sequenceconfig',
|
24
|
-
options[:width] = source.attr('width'
|
25
|
-
options[:height] = source.attr('height'
|
26
|
-
options[:theme] = source.attr('theme'
|
27
|
-
options[:background] = source.attr('background'
|
28
|
-
options[:config] = source.attr('config'
|
29
|
-
options[:puppeteer_config] = source.attr('puppeteerconfig',
|
21
|
+
options[:css] = source.attr('css')
|
22
|
+
options[:gantt_config] = source.attr(['ganttconfig', 'gantt-config'])
|
23
|
+
options[:seq_config] = source.attr(['sequenceconfig', 'sequence-config'])
|
24
|
+
options[:width] = source.attr('width')
|
25
|
+
options[:height] = source.attr('height')
|
26
|
+
options[:theme] = source.attr('theme')
|
27
|
+
options[:background] = source.attr('background')
|
28
|
+
options[:config] = source.attr('config')
|
29
|
+
options[:puppeteer_config] = source.attr(['puppeteerconfig', 'puppeteer-config'])
|
30
30
|
|
31
31
|
options
|
32
32
|
end
|
@@ -57,7 +57,8 @@ module Asciidoctor
|
|
57
57
|
opts[:width] = options[:width]
|
58
58
|
|
59
59
|
mmdc = source.find_command('mmdc', :raise_on_error => false)
|
60
|
-
|
60
|
+
node = source.find_command('node', :raise_on_error => false)
|
61
|
+
if mmdc && node
|
61
62
|
opts[:height] = options[:height]
|
62
63
|
opts[:theme] = options[:theme]
|
63
64
|
opts[:background] = options[:background]
|
@@ -65,7 +66,7 @@ module Asciidoctor
|
|
65
66
|
if config
|
66
67
|
opts[:config] = source.resolve_path(config)
|
67
68
|
end
|
68
|
-
run_mmdc(mmdc, source, format, opts)
|
69
|
+
run_mmdc(node, mmdc, source, format, opts)
|
69
70
|
else
|
70
71
|
mermaid = source.find_command('mermaid')
|
71
72
|
run_mermaid(mermaid, source, format, opts)
|
@@ -73,9 +74,9 @@ module Asciidoctor
|
|
73
74
|
end
|
74
75
|
|
75
76
|
private
|
76
|
-
def run_mmdc(mmdc, source, format, options = {})
|
77
|
-
generate_file(
|
78
|
-
args = [tool_path, '-i', Platform.native_path(input_path), '-o', Platform.native_path(output_path)]
|
77
|
+
def run_mmdc(node, mmdc, source, format, options = {})
|
78
|
+
generate_file(node, 'mmd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
|
79
|
+
args = [tool_path, '--unhandled-rejections=strict', mmdc, '-i', Platform.native_path(input_path), '-o', Platform.native_path(output_path)]
|
79
80
|
|
80
81
|
if options[:css]
|
81
82
|
args << '--cssFile' << Platform.native_path(options[:css])
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative '../diagram_converter'
|
2
|
+
require_relative '../util/cli_generator'
|
3
|
+
require_relative '../util/platform'
|
4
|
+
|
5
|
+
module Asciidoctor
|
6
|
+
module Diagram
|
7
|
+
# @private
|
8
|
+
class PikchrConverter
|
9
|
+
include DiagramConverter
|
10
|
+
include CliGenerator
|
11
|
+
|
12
|
+
|
13
|
+
def supported_formats
|
14
|
+
[:svg]
|
15
|
+
end
|
16
|
+
|
17
|
+
def convert(source, format, options)
|
18
|
+
pikchr_path = source.find_command('pikchr')
|
19
|
+
|
20
|
+
generate_file_stdout(pikchr_path, format.to_s, source.to_s) do |tool_path, input_path|
|
21
|
+
[tool_path, "--svg-only", input_path]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative 'converter'
|
2
|
+
require_relative '../diagram_processor'
|
3
|
+
|
4
|
+
module Asciidoctor
|
5
|
+
module Diagram
|
6
|
+
class PikchrBlockProcessor < DiagramBlockProcessor
|
7
|
+
use_converter PikchrConverter
|
8
|
+
end
|
9
|
+
|
10
|
+
class PikchrBlockMacroProcessor < DiagramBlockMacroProcessor
|
11
|
+
use_converter PikchrConverter
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -21,9 +21,9 @@ module Asciidoctor
|
|
21
21
|
[:png, :svg, :txt, :atxt, :utxt]
|
22
22
|
end
|
23
23
|
|
24
|
-
def collect_options(source
|
24
|
+
def collect_options(source)
|
25
25
|
{
|
26
|
-
:config => source.attr('plantumlconfig', nil, true) || source.attr('config'
|
26
|
+
:config => source.attr('plantumlconfig', nil, true) || source.attr('config')
|
27
27
|
}
|
28
28
|
end
|
29
29
|
|
@@ -78,7 +78,7 @@ module Asciidoctor
|
|
78
78
|
code = "@start#{tag}\n#{code}\n@end#{tag}" unless code.index("@start") && code.index("@end")
|
79
79
|
|
80
80
|
code.gsub!(/(?<=<img:)[^>]+(?=>)/) do |match|
|
81
|
-
resolve_path(match, source, source.attr('imagesdir'))
|
81
|
+
resolve_path(match, source, source.attr('imagesdir', nil, false))
|
82
82
|
end
|
83
83
|
|
84
84
|
code.gsub!(/(?:(?<=!include\s)|(?<=!includesub\s))\s*[^<][^!\n\r]+/) do |match|
|
@@ -14,10 +14,10 @@ module Asciidoctor
|
|
14
14
|
[:svg]
|
15
15
|
end
|
16
16
|
|
17
|
-
def collect_options(source
|
17
|
+
def collect_options(source)
|
18
18
|
{
|
19
|
-
:direction => source.attr('direction'
|
20
|
-
:engine => source.attr('engine'
|
19
|
+
:direction => source.attr('direction'),
|
20
|
+
:engine => source.attr('engine')
|
21
21
|
}
|
22
22
|
end
|
23
23
|
|
@@ -21,12 +21,12 @@ module Asciidoctor
|
|
21
21
|
:scale => lambda { |o, v| o << '--scale' << v if v }
|
22
22
|
}
|
23
23
|
|
24
|
-
def collect_options(source
|
24
|
+
def collect_options(source)
|
25
25
|
options = {}
|
26
26
|
|
27
27
|
OPTIONS.keys.each do |option|
|
28
28
|
attr_name = option.to_s.tr('_', '-')
|
29
|
-
options[option] = source.attr(attr_name
|
29
|
+
options[option] = source.attr(attr_name) || source.attr(attr_name, nil, 'svgbob-option')
|
30
30
|
end
|
31
31
|
|
32
32
|
options
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative '../diagram_converter'
|
2
|
+
require_relative '../util/cli_generator'
|
3
|
+
require_relative '../util/platform'
|
4
|
+
|
5
|
+
module Asciidoctor
|
6
|
+
module Diagram
|
7
|
+
# @private
|
8
|
+
class SymbolatorConverter
|
9
|
+
include DiagramConverter
|
10
|
+
include CliGenerator
|
11
|
+
|
12
|
+
def supported_formats
|
13
|
+
[:png, :pdf, :svg]
|
14
|
+
end
|
15
|
+
|
16
|
+
def convert(source, format, options)
|
17
|
+
generate_stdin(source.find_command('symbolator'), format.to_s, source.to_s) do |tool_path, output_path|
|
18
|
+
[tool_path, "-i-", "-o#{Platform.native_path(output_path)}", "-f#{format.to_s}"]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|