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
@@ -1,36 +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 Nomnoml
10
- include CliGenerator
11
- include Which
12
-
13
- def self.included(mod)
14
- [:svg].each do |f|
15
- mod.register_format(f, :image) do |parent, source|
16
- nomnoml(parent, source, f)
17
- end
18
- end
19
- end
20
-
21
- def nomnoml(parent, source, format)
22
- generate_file(which(parent, 'nomnoml'), 'nomnoml', format.to_s, source.to_s) do |tool_path, input_path, output_path|
23
- [tool_path, Platform.native_path(input_path), Platform.native_path(output_path)]
24
- end
25
- end
26
- end
27
-
28
- class NomnomlBlockProcessor < Extensions::DiagramBlockProcessor
29
- include Nomnoml
6
+ class NomnomlBlockProcessor < DiagramBlockProcessor
7
+ use_converter NomnomlConverter
30
8
  end
31
9
 
32
- class NomnomlBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
33
- include Nomnoml
10
+ class NomnomlBlockMacroProcessor < DiagramBlockMacroProcessor
11
+ use_converter NomnomlConverter
34
12
  end
35
13
  end
36
14
  end
@@ -0,0 +1,115 @@
1
+ require_relative '../diagram_converter'
2
+ require 'uri'
3
+
4
+ module Asciidoctor
5
+ module Diagram
6
+ # @private
7
+ class PlantUmlConverter
8
+ include DiagramConverter
9
+
10
+ JARS = [
11
+ 'plantuml-1.3.14.jar',
12
+ 'plantuml.jar',
13
+ 'jlatexmath-minimal-1.0.5.jar',
14
+ 'batik-all-1.10.jar'
15
+ ].map do |jar|
16
+ File.expand_path File.join('../..', jar), File.dirname(__FILE__)
17
+ end
18
+ Java.classpath.concat JARS
19
+
20
+ def supported_formats
21
+ [:png, :svg, :txt]
22
+ end
23
+
24
+ def collect_options(source, name)
25
+ {
26
+ :config => source.attr('plantumlconfig', nil, true) || source.attr('config', nil, name)
27
+ }
28
+ end
29
+
30
+ def convert(source, format, options)
31
+ Java.load
32
+
33
+ code = preprocess_code(source, self.class.tag)
34
+
35
+ case format
36
+ when :png
37
+ mime_type = 'image/png'
38
+ when :svg
39
+ mime_type = 'image/svg+xml'
40
+ when :txt
41
+ mime_type = 'text/plain;charset=utf-8'
42
+ else
43
+ raise "Unsupported format: #{format}"
44
+ end
45
+
46
+ headers = {
47
+ 'Accept' => mime_type
48
+ }
49
+
50
+ config_file = options[:config]
51
+ if config_file
52
+ headers['X-PlantUML-Config'] = File.expand_path(config_file, source.base_dir)
53
+ end
54
+
55
+ dot = source.find_command('dot', :alt_attrs => ['graphvizdot'], :raise_on_error => false)
56
+ if dot
57
+ headers['X-Graphviz'] = ::Asciidoctor::Diagram::Platform.host_os_path(dot)
58
+ end
59
+
60
+ response = Java.send_request(
61
+ :url => '/plantuml',
62
+ :body => code,
63
+ :headers => headers
64
+ )
65
+
66
+ unless response[:code] == 200
67
+ raise Java.create_error("PlantUML image generation failed", response)
68
+ end
69
+
70
+ response[:body]
71
+ end
72
+
73
+ def preprocess_code(source, tag)
74
+ code = source.to_s
75
+
76
+ code = "@start#{tag}\n#{code}\n@end#{tag}" unless code.index("@start") && code.index("@end")
77
+
78
+ code.gsub!(/(?<=<img:)[^>]+(?=>)/) do |match|
79
+ resolve_path(match, source, source.attr('imagesdir'))
80
+ end
81
+
82
+ code.gsub!(/(?:(?<=!include\s)|(?<=!includesub\s))\s*[^<][^!\n\r]+/) do |match|
83
+ resolve_path(match.lstrip, source, source.base_dir)
84
+ end
85
+
86
+ code
87
+ end
88
+
89
+ def resolve_path(path, source, base_dir)
90
+ if path =~ ::URI::ABS_URI
91
+ uri = ::URI.parse(path)
92
+ if uri.scheme == 'file'
93
+ source.resolve_path(uri.path, base_dir)
94
+ else
95
+ path
96
+ end
97
+ else
98
+ source.resolve_path(path, base_dir)
99
+ end
100
+ end
101
+ end
102
+
103
+ class UmlConverter < PlantUmlConverter
104
+ def self.tag
105
+ 'uml'
106
+ end
107
+ end
108
+
109
+ class SaltConverter < PlantUmlConverter
110
+ def self.tag
111
+ 'salt'
112
+ end
113
+ end
114
+ end
115
+ end
@@ -1,131 +1,22 @@
1
- require_relative '../extensions'
2
- require_relative '../util/which'
3
- require 'uri'
1
+ require_relative 'converter'
2
+ require_relative '../diagram_processor'
4
3
 
5
4
  module Asciidoctor
6
5
  module Diagram
7
- # @private
8
- module PlantUml
9
- include Which
10
-
11
- private
12
-
13
- JARS = [
14
- 'plantuml-1.3.13.jar',
15
- 'plantuml.jar',
16
- 'jlatexmath-minimal-1.0.5.jar',
17
- 'batik-all-1.10.jar'
18
- ].map do |jar|
19
- File.expand_path File.join('../..', jar), File.dirname(__FILE__)
20
- end
21
- Java.classpath.concat JARS
22
-
23
- def plantuml(parent_block, source, tag, mime_type)
24
- Java.load
25
-
26
- inherit_prefix = name
27
- code = preprocess_code(parent_block, source, tag)
28
-
29
- headers = {
30
- 'Accept' => mime_type
31
- }
32
-
33
- config_file = source.attr('plantumlconfig', nil, true) || source.attr('config', nil, inherit_prefix)
34
- if config_file
35
- headers['X-PlantUML-Config'] = File.expand_path(config_file, source.attr('docdir', nil, true))
36
- end
37
-
38
- dot = which(parent_block, 'dot', :alt_attrs => ['graphvizdot'], :raise_on_error => false)
39
- if dot
40
- headers['X-Graphviz'] = ::Asciidoctor::Diagram::Platform.host_os_path(dot)
41
- end
42
-
43
- response = Java.send_request(
44
- :url => '/plantuml',
45
- :body => code,
46
- :headers => headers
47
- )
48
-
49
- unless response[:code] == 200
50
- raise Java.create_error("PlantUML image generation failed", response)
51
- end
52
-
53
- response[:body]
54
- end
55
-
56
- def preprocess_code(parent, source, tag)
57
- code = source.to_s
58
- base_dir = source.base_dir
59
-
60
- code = "@start#{tag}\n#{code}\n@end#{tag}" unless code.index("@start") && code.index("@end")
61
-
62
- code.gsub!(/(?<=<img:)[^>]+(?=>)/) do |match|
63
- resolve_path(match, parent, parent.attr('imagesdir'))
64
- end
65
-
66
- code.gsub!(/(?:(?<=!include\s)|(?<=!includesub\s))\s*[^<][^!\n\r]+/) do |match|
67
- resolve_path(match.lstrip, parent, base_dir)
68
- end
69
-
70
- code
71
- end
72
-
73
- def resolve_path(path, parent, base_dir)
74
- if path =~ ::URI::ABS_URI
75
- uri = ::URI.parse(path)
76
- if uri.scheme == 'file'
77
- parent.normalize_system_path(uri.path, base_dir)
78
- else
79
- parent.normalize_web_path(path)
80
- end
81
- else
82
- parent.normalize_system_path(path, base_dir)
83
- end
84
- end
85
-
86
- def self.included(mod)
87
- mod.register_format(:png, :image) do |parent_block, source|
88
- plantuml(parent_block, source, mod.tag, 'image/png')
89
- end
90
- mod.register_format(:svg, :image) do |parent_block, source|
91
- plantuml(parent_block, source, mod.tag, 'image/svg+xml')
92
- end
93
- mod.register_format(:txt, :literal) do |parent_block, source|
94
- plantuml(parent_block, source, mod.tag, 'text/plain;charset=utf-8')
95
- end
96
- end
6
+ class PlantUmlBlockProcessor < DiagramBlockProcessor
7
+ use_converter UmlConverter
97
8
  end
98
9
 
99
- class PlantUmlBlockProcessor < Extensions::DiagramBlockProcessor
100
- def self.tag
101
- 'uml'
102
- end
103
-
104
- include PlantUml
10
+ class PlantUmlBlockMacroProcessor < DiagramBlockMacroProcessor
11
+ use_converter UmlConverter
105
12
  end
106
13
 
107
- class PlantUmlBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
108
- def self.tag
109
- 'uml'
110
- end
111
-
112
- include PlantUml
14
+ class SaltBlockProcessor < DiagramBlockProcessor
15
+ use_converter SaltConverter
113
16
  end
114
17
 
115
- class SaltBlockProcessor < Extensions::DiagramBlockProcessor
116
- def self.tag
117
- 'salt'
118
- end
119
-
120
- include PlantUml
121
- end
122
-
123
- class SaltBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
124
- def self.tag
125
- 'salt'
126
- end
127
-
128
- include PlantUml
18
+ class SaltBlockMacroProcessor < DiagramBlockMacroProcessor
19
+ use_converter SaltConverter
129
20
  end
130
21
  end
131
22
  end
@@ -0,0 +1,25 @@
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 ShaapeConverter
9
+ include DiagramConverter
10
+ include CliGenerator
11
+
12
+
13
+ def supported_formats
14
+ [:png, :svg]
15
+ end
16
+
17
+
18
+ def convert(source, format, options)
19
+ generate_stdin(source.find_command('shaape'), format.to_s, source.to_s) do |tool_path, output_path|
20
+ [tool_path, '-o', Platform.native_path(output_path), '-t', format.to_s, '-']
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,36 +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 Shaape
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
- shaape(parent, source, f)
17
- end
18
- end
19
- end
20
-
21
- def shaape(parent, source, format)
22
- generate_stdin(which(parent, 'shaape'), format.to_s, source.to_s) do |tool_path, output_path|
23
- [tool_path, '-o', Platform.native_path(output_path), '-t', format.to_s, '-']
24
- end
25
- end
26
- end
27
-
28
- class ShaapeBlockProcessor < Extensions::DiagramBlockProcessor
29
- include Shaape
6
+ class ShaapeBlockProcessor < DiagramBlockProcessor
7
+ use_converter ShaapeConverter
30
8
  end
31
9
 
32
- class ShaapeBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
33
- include Shaape
10
+ class ShaapeBlockMacroProcessor < DiagramBlockMacroProcessor
11
+ use_converter ShaapeConverter
34
12
  end
35
13
  end
36
14
  end
@@ -0,0 +1,44 @@
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 SmcatConverter
9
+ include DiagramConverter
10
+ include CliGenerator
11
+
12
+
13
+ def supported_formats
14
+ [:svg]
15
+ end
16
+
17
+ def collect_options(source, name)
18
+ {
19
+ :direction => source.attr('direction', nil, name),
20
+ :engine => source.attr('engine', nil, name)
21
+ }
22
+ end
23
+
24
+ def convert(source, format, options)
25
+ direction = options[:direction]
26
+ engine = options[:engine]
27
+
28
+ generate_stdin(source.find_command('smcat'), format.to_s, source.to_s) do |tool_path, output_path|
29
+ args = [tool_path, '-o', Platform.native_path(output_path), '-T', format.to_s]
30
+ if direction
31
+ args << '-d' << direction
32
+ end
33
+
34
+ if engine
35
+ args << '-E' << engine
36
+ end
37
+
38
+ args << '-'
39
+ args
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,50 +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 Smcat
10
- include CliGenerator
11
- include Which
12
-
13
- def self.included(mod)
14
- [:svg].each do |f|
15
- mod.register_format(f, :image) do |parent, source|
16
- smcat(parent, source, f)
17
- end
18
- end
19
- end
20
-
21
- def smcat(parent, source, format)
22
- inherit_prefix = name
23
- direction = source.attr('direction', nil, inherit_prefix)
24
- engine = source.attr('engine', nil, inherit_prefix)
25
-
26
- generate_stdin(which(parent, 'smcat'), format.to_s, source.to_s) do |tool_path, output_path|
27
- args = [tool_path, '-o', Platform.native_path(output_path), '-T', format.to_s]
28
- if direction
29
- args << '-d' << direction
30
- end
31
-
32
- if engine
33
- args << '-E' << engine
34
- end
35
-
36
- args << '-'
37
- args
38
- end
39
- end
40
- end
41
-
42
- class SmcatBlockProcessor < Extensions::DiagramBlockProcessor
43
- include Smcat
6
+ class SmcatBlockProcessor < DiagramBlockProcessor
7
+ use_converter SmcatConverter
44
8
  end
45
9
 
46
- class SmcatBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
47
- include Smcat
10
+ class SmcatBlockMacroProcessor < DiagramBlockMacroProcessor
11
+ use_converter SmcatConverter
48
12
  end
49
13
  end
50
14
  end