asciidoctor-diagram 1.5.19 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.adoc +10 -0
  3. data/README.adoc +22 -9
  4. data/examples/features.adoc +2 -2
  5. data/lib/asciidoctor-diagram.rb +1 -0
  6. data/lib/asciidoctor-diagram/a2s/converter.rb +55 -0
  7. data/lib/asciidoctor-diagram/a2s/extension.rb +6 -52
  8. data/lib/asciidoctor-diagram/blockdiag/converter.rb +37 -0
  9. data/lib/asciidoctor-diagram/blockdiag/extension.rb +9 -116
  10. data/lib/asciidoctor-diagram/bpmn.rb +7 -0
  11. data/lib/asciidoctor-diagram/bpmn/converter.rb +62 -0
  12. data/lib/asciidoctor-diagram/bpmn/extension.rb +14 -0
  13. data/lib/asciidoctor-diagram/diagram_converter.rb +19 -0
  14. data/lib/asciidoctor-diagram/diagram_processor.rb +320 -0
  15. data/lib/asciidoctor-diagram/diagram_source.rb +275 -0
  16. data/lib/asciidoctor-diagram/ditaa/converter.rb +86 -0
  17. data/lib/asciidoctor-diagram/ditaa/extension.rb +6 -71
  18. data/lib/asciidoctor-diagram/erd/converter.rb +31 -0
  19. data/lib/asciidoctor-diagram/erd/extension.rb +6 -35
  20. data/lib/asciidoctor-diagram/gnuplot/converter.rb +63 -0
  21. data/lib/asciidoctor-diagram/gnuplot/extension.rb +6 -62
  22. data/lib/asciidoctor-diagram/graphviz/converter.rb +32 -0
  23. data/lib/asciidoctor-diagram/graphviz/extension.rb +6 -35
  24. data/lib/asciidoctor-diagram/http/server.rb +127 -0
  25. data/lib/asciidoctor-diagram/lilypond/converter.rb +54 -0
  26. data/lib/asciidoctor-diagram/lilypond/extension.rb +6 -53
  27. data/lib/asciidoctor-diagram/meme/converter.rb +122 -0
  28. data/lib/asciidoctor-diagram/meme/extension.rb +5 -107
  29. data/lib/asciidoctor-diagram/mermaid/converter.rb +178 -0
  30. data/lib/asciidoctor-diagram/mermaid/extension.rb +6 -159
  31. data/lib/asciidoctor-diagram/msc/converter.rb +35 -0
  32. data/lib/asciidoctor-diagram/msc/extension.rb +6 -36
  33. data/lib/asciidoctor-diagram/nomnoml/converter.rb +25 -0
  34. data/lib/asciidoctor-diagram/nomnoml/extension.rb +6 -28
  35. data/lib/asciidoctor-diagram/plantuml/converter.rb +115 -0
  36. data/lib/asciidoctor-diagram/plantuml/extension.rb +10 -119
  37. data/lib/asciidoctor-diagram/shaape/converter.rb +25 -0
  38. data/lib/asciidoctor-diagram/shaape/extension.rb +6 -28
  39. data/lib/asciidoctor-diagram/smcat/converter.rb +44 -0
  40. data/lib/asciidoctor-diagram/smcat/extension.rb +6 -42
  41. data/lib/asciidoctor-diagram/svgbob/converter.rb +25 -0
  42. data/lib/asciidoctor-diagram/svgbob/extension.rb +6 -28
  43. data/lib/asciidoctor-diagram/syntrax/converter.rb +55 -0
  44. data/lib/asciidoctor-diagram/syntrax/extension.rb +6 -51
  45. data/lib/asciidoctor-diagram/tikz/converter.rb +56 -0
  46. data/lib/asciidoctor-diagram/tikz/extension.rb +6 -60
  47. data/lib/asciidoctor-diagram/umlet/converter.rb +24 -0
  48. data/lib/asciidoctor-diagram/umlet/extension.rb +6 -28
  49. data/lib/asciidoctor-diagram/util/java.rb +1 -1
  50. data/lib/asciidoctor-diagram/util/java_socket.rb +7 -9
  51. data/lib/asciidoctor-diagram/util/which.rb +0 -29
  52. data/lib/asciidoctor-diagram/vega/converter.rb +47 -0
  53. data/lib/asciidoctor-diagram/vega/extension.rb +6 -44
  54. data/lib/asciidoctor-diagram/version.rb +1 -1
  55. data/lib/asciidoctor-diagram/wavedrom/converter.rb +50 -0
  56. data/lib/asciidoctor-diagram/wavedrom/extension.rb +6 -54
  57. data/lib/ditaa-1.3.14.jar +0 -0
  58. data/lib/plantuml-1.3.14.jar +0 -0
  59. data/lib/plantuml.jar +0 -0
  60. data/lib/server-1.3.14.jar +0 -0
  61. data/spec/bpmn-example.xml +44 -0
  62. data/spec/bpmn_spec.rb +96 -0
  63. data/spec/mermaid_spec.rb +33 -1
  64. data/spec/plantuml_spec.rb +89 -0
  65. metadata +37 -8
  66. data/lib/asciidoctor-diagram/extensions.rb +0 -568
  67. data/lib/ditaa-1.3.13.jar +0 -0
  68. data/lib/plantuml-1.3.13.jar +0 -0
  69. data/lib/server-1.3.13.jar +0 -0
@@ -0,0 +1,86 @@
1
+ require 'set'
2
+
3
+ require_relative '../diagram_converter'
4
+ require_relative '../diagram_processor'
5
+ require_relative '../util/java'
6
+
7
+ module Asciidoctor
8
+ module Diagram
9
+ # @private
10
+ class DitaaConverter
11
+ include DiagramConverter
12
+
13
+ OPTIONS = {
14
+ :scale => lambda { |o, v| o << '--scale' << v if v },
15
+ :tabs => lambda { |o, v| o << '--tabs' << v if v },
16
+ :background => lambda { |o, v| o << '--background' << v if v },
17
+ :antialias => lambda { |o, v| o << '--no-antialias' if v == 'false' },
18
+ :separation => lambda { |o, v| o << '--no-separation' if v == 'false'},
19
+ :round_corners => lambda { |o, v| o << '--round-corners' if v == 'true'},
20
+ :shadows => lambda { |o, v| o << '--no-shadows' if v == 'false'},
21
+ :debug => lambda { |o, v| o << '--debug' if v == 'true'},
22
+ :fixed_slope => lambda { |o, v| o << '--fixed-slope' if v == 'true'},
23
+ :transparent => lambda { |o, v| o << '--transparent' if v == 'true'}
24
+ }
25
+
26
+ JARS = ['ditaa-1.3.14.jar', 'ditaamini-0.12.jar'].map do |jar|
27
+ File.expand_path File.join('../..', jar), File.dirname(__FILE__)
28
+ end
29
+ Java.classpath.concat JARS
30
+
31
+
32
+ def supported_formats
33
+ [:png, :svg]
34
+ end
35
+
36
+ def collect_options(source, name)
37
+ options = {}
38
+
39
+ OPTIONS.keys.each do |option|
40
+ attr_name = option.to_s.tr('_', '-')
41
+ options[option] = source.attr(attr_name, nil, name) || source.attr(attr_name, nil, 'ditaa-option')
42
+ end
43
+
44
+ options
45
+ end
46
+
47
+ def convert(source, format, options)
48
+ Java.load
49
+
50
+ flags = []
51
+
52
+ options.each do |option, value|
53
+ OPTIONS[option].call(flags, value)
54
+ end
55
+
56
+ options_string = flags.join(' ')
57
+
58
+ case format
59
+ when :png
60
+ mime_type = 'image/png'
61
+ when :svg
62
+ mime_type = 'image/svg+xml'
63
+ else
64
+ raise "Unsupported format: #{format}"
65
+ end
66
+
67
+ headers = {
68
+ 'Accept' => mime_type,
69
+ 'X-Options' => options_string
70
+ }
71
+
72
+ response = Java.send_request(
73
+ :url => '/ditaa',
74
+ :body => source.to_s,
75
+ :headers => headers
76
+ )
77
+
78
+ unless response[:code] == 200
79
+ raise Java.create_error("Ditaa image generation failed", response)
80
+ end
81
+
82
+ response[:body]
83
+ end
84
+ end
85
+ end
86
+ end
@@ -1,79 +1,14 @@
1
- require 'set'
2
-
3
- require_relative '../extensions'
4
- require_relative '../util/java'
1
+ require_relative 'converter'
2
+ require_relative '../diagram_processor'
5
3
 
6
4
  module Asciidoctor
7
5
  module Diagram
8
- # @private
9
- module Ditaa
10
- OPTIONS = {
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.12.jar'].map do |jar|
24
- File.expand_path File.join('../..', jar), File.dirname(__FILE__)
25
- end
26
- Java.classpath.concat JARS
27
-
28
- def self.included(mod)
29
- mod.register_format(:png, :image) do |parent, source|
30
- ditaa(parent, source, 'image/png')
31
- end
32
-
33
- mod.register_format(:svg, :image) do |parent, source|
34
- ditaa(parent, source, 'image/svg+xml')
35
- end
36
- end
37
-
38
- def ditaa(parent, source, mime_type)
39
- Java.load
40
-
41
- global_attributes = parent.document.attributes
42
-
43
- options = []
44
-
45
- OPTIONS.keys.each do |key|
46
- value = source.attributes.delete(key) || global_attributes["ditaa-option-#{key}"]
47
- OPTIONS[key].call(options, value)
48
- 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]
68
- end
69
- end
70
-
71
- class DitaaBlockProcessor < Extensions::DiagramBlockProcessor
72
- include Ditaa
6
+ class DitaaBlockProcessor < DiagramBlockProcessor
7
+ use_converter DitaaConverter
73
8
  end
74
9
 
75
- class DitaaBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
76
- include Ditaa
10
+ class DitaaBlockMacroProcessor < DiagramBlockMacroProcessor
11
+ use_converter DitaaConverter
77
12
  end
78
13
  end
79
14
  end
@@ -0,0 +1,31 @@
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 ErdConverter
9
+ include DiagramConverter
10
+ include CliGenerator
11
+
12
+
13
+ def supported_formats
14
+ [:png, :svg]
15
+ end
16
+
17
+ def convert(source, format, options)
18
+ erd_path = source.find_command('erd')
19
+ dot_path = source.find_command('dot', :alt_attrs => ['graphvizdot'])
20
+
21
+ dot_code = generate_stdin(erd_path, format.to_s, source.to_s) do |tool_path, output_path|
22
+ [tool_path, '-o', Platform.native_path(output_path), '-f', 'dot']
23
+ end
24
+
25
+ generate_stdin(dot_path, format.to_s, dot_code) do |tool_path, output_path|
26
+ [tool_path, "-o#{Platform.native_path(output_path)}", "-T#{format.to_s}"]
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,43 +1,14 @@
1
- require_relative '../extensions'
2
- require_relative '../util/cli_generator'
3
- require_relative '../util/platform'
4
- require_relative '../util/which'
1
+ require_relative 'converter'
2
+ require_relative '../diagram_processor'
5
3
 
6
4
  module Asciidoctor
7
5
  module Diagram
8
- # @private
9
- module Erd
10
- include CliGenerator
11
- include Which
12
-
13
- def self.included(mod)
14
- [:png, :svg].each do |f|
15
- mod.register_format(f, :image) do |parent, source|
16
- erd(parent, source, f)
17
- end
18
- end
19
- end
20
-
21
- def erd(parent, source, format)
22
- erd_path = which(parent, 'erd')
23
- dot_path = which(parent, 'dot', :alt_attrs => ['graphvizdot'])
24
-
25
- dot_code = generate_stdin(erd_path, format.to_s, source.to_s) do |tool_path, output_path|
26
- [tool_path, '-o', Platform.native_path(output_path), '-f', 'dot']
27
- end
28
-
29
- generate_stdin(dot_path, format.to_s, dot_code) do |tool_path, output_path|
30
- [tool_path, "-o#{Platform.native_path(output_path)}", "-T#{format.to_s}"]
31
- end
32
- end
33
- end
34
-
35
- class ErdBlockProcessor < Extensions::DiagramBlockProcessor
36
- include Erd
6
+ class ErdBlockProcessor < DiagramBlockProcessor
7
+ use_converter ErdConverter
37
8
  end
38
9
 
39
- class ErdBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
40
- include Erd
10
+ class ErdBlockMacroProcessor < DiagramBlockMacroProcessor
11
+ use_converter ErdConverter
41
12
  end
42
13
  end
43
14
  end
@@ -0,0 +1,63 @@
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 GnuplotConverter
9
+ include DiagramConverter
10
+ include CliGenerator
11
+
12
+
13
+ def supported_formats
14
+ [:png, :svg, :gif, :txt, :literal]
15
+ end
16
+
17
+ def collect_options(source, name)
18
+ {
19
+ :width => source.attr('width', nil, name),
20
+ :height => source.attr('height', nil, name),
21
+ :transparent => source.attr('transparent', nil, name),
22
+ :crop => source.attr('crop', nil, name),
23
+ :font => source.attr('font', nil, name),
24
+ :fontscale => source.attr('fontscale', nil, name),
25
+ :background => source.attr('background', nil, name),
26
+ }
27
+ end
28
+
29
+ def convert(source, format, options)
30
+ if format == :txt || format == :literal
31
+ terminal = 'dumb'
32
+ else
33
+ terminal = format.to_s
34
+ end
35
+ code = "set term #{terminal}"
36
+
37
+ width = options[:width]
38
+ height = options[:height]
39
+ code << " size #{width},#{height}" unless width.nil? or height.nil?
40
+
41
+ transparent = options[:transparent]
42
+ code << (transparent ? " transparent" : " notransparent") unless transparent.nil?
43
+
44
+ crop = options[:crop]
45
+ code << (crop ? " crop" : " nocrop") unless crop.nil?
46
+
47
+ font = options[:font]
48
+ code << %( font "#{font}") unless font.nil?
49
+
50
+ font_scale = options[:fontscale]
51
+ code << " fontscale #{font_scale}" unless font_scale.nil?
52
+
53
+ background = options[:background]
54
+ code << %( background "#{background}") unless background.nil?
55
+
56
+ code << "\n"
57
+ code << source.to_s
58
+
59
+ generate_stdin_stdout(source.find_command('gnuplot'), code)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -1,70 +1,14 @@
1
- require_relative '../extensions'
2
- require_relative '../util/cli_generator'
3
- require_relative '../util/platform'
4
- require_relative '../util/which'
1
+ require_relative 'converter'
2
+ require_relative '../diagram_processor'
5
3
 
6
4
  module Asciidoctor
7
5
  module Diagram
8
- # @private
9
- module Gnuplot
10
- include CliGenerator
11
- include Which
12
-
13
- def self.included(mod)
14
- [:png, :svg, :gif].each do |f|
15
- mod.register_format(f, :image) do |parent, source|
16
- gnuplot(parent, source, f)
17
- end
18
- end
19
-
20
- mod.register_format(:txt, :literal) do |parent, source|
21
- gnuplot(parent, source, :txt)
22
- end
23
- end
24
-
25
- def gnuplot(parent, source, format)
26
- inherit_prefix = name
27
-
28
- width = source.attr("width", nil, inherit_prefix)
29
- height = source.attr("height", nil, inherit_prefix)
30
-
31
- if format == :txt
32
- format = 'dumb'
33
- end
34
-
35
- code = "set term #{format}"
36
- code << " size #{width},#{height}" unless width.nil? or height.nil?
37
-
38
- transparent = source.attr("transparent", nil, inherit_prefix)
39
- code << (transparent ? " transparent" : " notransparent") unless transparent.nil?
40
-
41
- crop = source.attr("crop", nil, inherit_prefix)
42
- code << (crop ? " crop" : " nocrop") unless crop.nil?
43
-
44
- font = source.attr("font", nil, inherit_prefix)
45
- code << %( font "#{font}") unless font.nil?
46
-
47
- font_scale = source.attr("fontscale", nil, inherit_prefix)
48
- code << " fontscale #{font_scale}" unless font_scale.nil?
49
-
50
- background = source.attr("background", nil, inherit_prefix)
51
- code << %( background "#{background}") unless background.nil?
52
-
53
- code << "\n"
54
- code << source.to_s
55
- generate_stdin_stdout(which(parent, 'gnuplot'), code) do |tool_path|
56
- [tool_path]
57
- end
58
-
59
- end
60
- end
61
-
62
- class GnuplotBlockProcessor < Extensions::DiagramBlockProcessor
63
- include Gnuplot
6
+ class GnuplotBlockProcessor < DiagramBlockProcessor
7
+ use_converter GnuplotConverter
64
8
  end
65
9
 
66
- class GnuplotBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
67
- include Gnuplot
10
+ class GnuplotBlockMacroProcessor < DiagramBlockMacroProcessor
11
+ use_converter GnuplotConverter
68
12
  end
69
13
  end
70
14
  end
@@ -0,0 +1,32 @@
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 GraphvizConverter
9
+ include DiagramConverter
10
+ include CliGenerator
11
+
12
+ def supported_formats
13
+ [:png, :pdf, :svg]
14
+ end
15
+
16
+ def collect_options(source, name)
17
+ {:layout => source.attr('layout', nil, name)}
18
+ end
19
+
20
+ def convert(source, format, options)
21
+ generate_stdin(source.find_command('dot', :alt_attrs => ['graphvizdot']), format.to_s, source.to_s) do |tool_path, output_path|
22
+ args = [tool_path, "-o#{Platform.native_path(output_path)}", "-T#{format.to_s}"]
23
+
24
+ layout = options[:layout]
25
+ args << "-K#{layout}" if layout
26
+
27
+ args
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,43 +1,14 @@
1
- require_relative '../extensions'
2
- require_relative '../util/cli_generator'
3
- require_relative '../util/platform'
4
- require_relative '../util/which'
1
+ require_relative 'converter'
2
+ require_relative '../diagram_processor'
5
3
 
6
4
  module Asciidoctor
7
5
  module Diagram
8
- # @private
9
- module Graphviz
10
- include CliGenerator
11
- include Which
12
-
13
- def self.included(mod)
14
- [:png, :pdf, :svg].each do |f|
15
- mod.register_format(f, :image) do |parent, source|
16
- graphviz(parent, source, f)
17
- end
18
- end
19
- end
20
-
21
- def graphviz(parent, source, format)
22
- inherit_prefix = name
23
-
24
- generate_stdin(which(parent, 'dot', :alt_attrs => ['graphvizdot']), format.to_s, source.to_s) do |tool_path, output_path|
25
- args = [tool_path, "-o#{Platform.native_path(output_path)}", "-T#{format.to_s}"]
26
-
27
- layout = source.attr('layout', nil, inherit_prefix)
28
- args << "-K#{layout}" if layout
29
-
30
- args
31
- end
32
- end
33
- end
34
-
35
- class GraphvizBlockProcessor < Extensions::DiagramBlockProcessor
36
- include Graphviz
6
+ class GraphvizBlockProcessor < DiagramBlockProcessor
7
+ use_converter GraphvizConverter
37
8
  end
38
9
 
39
- class GraphvizBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
40
- include Graphviz
10
+ class GraphvizBlockMacroProcessor < DiagramBlockMacroProcessor
11
+ use_converter GraphvizConverter
41
12
  end
42
13
  end
43
14
  end