asciidoctor-diagram 1.5.18 → 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.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +75 -0
  3. data/README.adoc +98 -23
  4. data/examples/features.adoc +2 -2
  5. data/lib/asciidoctor-diagram.rb +8 -0
  6. data/lib/asciidoctor-diagram/a2s/converter.rb +59 -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/bytefield.rb +7 -0
  14. data/lib/asciidoctor-diagram/bytefield/converter.rb +26 -0
  15. data/lib/asciidoctor-diagram/bytefield/extension.rb +14 -0
  16. data/lib/asciidoctor-diagram/diagram_converter.rb +23 -0
  17. data/lib/asciidoctor-diagram/diagram_processor.rb +357 -0
  18. data/lib/asciidoctor-diagram/diagram_source.rb +322 -0
  19. data/lib/asciidoctor-diagram/ditaa/converter.rb +90 -0
  20. data/lib/asciidoctor-diagram/ditaa/extension.rb +6 -71
  21. data/lib/asciidoctor-diagram/dpic.rb +7 -0
  22. data/lib/asciidoctor-diagram/dpic/converter.rb +30 -0
  23. data/lib/asciidoctor-diagram/dpic/extension.rb +14 -0
  24. data/lib/asciidoctor-diagram/erd/converter.rb +31 -0
  25. data/lib/asciidoctor-diagram/erd/extension.rb +6 -35
  26. data/lib/asciidoctor-diagram/gnuplot.rb +7 -0
  27. data/lib/asciidoctor-diagram/gnuplot/converter.rb +63 -0
  28. data/lib/asciidoctor-diagram/gnuplot/extension.rb +14 -0
  29. data/lib/asciidoctor-diagram/graphviz/converter.rb +32 -0
  30. data/lib/asciidoctor-diagram/graphviz/extension.rb +6 -35
  31. data/lib/asciidoctor-diagram/http/converter.rb +99 -0
  32. data/lib/asciidoctor-diagram/http/server.rb +132 -0
  33. data/lib/asciidoctor-diagram/lilypond.rb +7 -0
  34. data/lib/asciidoctor-diagram/lilypond/converter.rb +54 -0
  35. data/lib/asciidoctor-diagram/lilypond/extension.rb +14 -0
  36. data/lib/asciidoctor-diagram/meme/converter.rb +122 -0
  37. data/lib/asciidoctor-diagram/meme/extension.rb +5 -107
  38. data/lib/asciidoctor-diagram/mermaid/converter.rb +179 -0
  39. data/lib/asciidoctor-diagram/mermaid/extension.rb +6 -159
  40. data/lib/asciidoctor-diagram/msc/converter.rb +35 -0
  41. data/lib/asciidoctor-diagram/msc/extension.rb +6 -36
  42. data/lib/asciidoctor-diagram/nomnoml/converter.rb +25 -0
  43. data/lib/asciidoctor-diagram/nomnoml/extension.rb +6 -28
  44. data/lib/asciidoctor-diagram/pikchr.rb +7 -0
  45. data/lib/asciidoctor-diagram/pikchr/converter.rb +26 -0
  46. data/lib/asciidoctor-diagram/pikchr/extension.rb +14 -0
  47. data/lib/asciidoctor-diagram/plantuml/converter.rb +117 -0
  48. data/lib/asciidoctor-diagram/plantuml/extension.rb +10 -119
  49. data/lib/asciidoctor-diagram/shaape/converter.rb +25 -0
  50. data/lib/asciidoctor-diagram/shaape/extension.rb +6 -28
  51. data/lib/asciidoctor-diagram/smcat.rb +7 -0
  52. data/lib/asciidoctor-diagram/smcat/converter.rb +44 -0
  53. data/lib/asciidoctor-diagram/smcat/extension.rb +14 -0
  54. data/lib/asciidoctor-diagram/svgbob/converter.rb +49 -0
  55. data/lib/asciidoctor-diagram/svgbob/extension.rb +6 -28
  56. data/lib/asciidoctor-diagram/symbolator.rb +7 -0
  57. data/lib/asciidoctor-diagram/symbolator/converter.rb +23 -0
  58. data/lib/asciidoctor-diagram/symbolator/extension.rb +14 -0
  59. data/lib/asciidoctor-diagram/syntrax/converter.rb +58 -0
  60. data/lib/asciidoctor-diagram/syntrax/extension.rb +6 -51
  61. data/lib/asciidoctor-diagram/tikz/converter.rb +56 -0
  62. data/lib/asciidoctor-diagram/tikz/extension.rb +6 -60
  63. data/lib/asciidoctor-diagram/umlet/converter.rb +24 -0
  64. data/lib/asciidoctor-diagram/umlet/extension.rb +6 -28
  65. data/lib/asciidoctor-diagram/util/cli.rb +14 -3
  66. data/lib/asciidoctor-diagram/util/cli_generator.rb +19 -1
  67. data/lib/asciidoctor-diagram/util/gif.rb +2 -2
  68. data/lib/asciidoctor-diagram/util/java.rb +1 -1
  69. data/lib/asciidoctor-diagram/util/java_socket.rb +7 -9
  70. data/lib/asciidoctor-diagram/util/pdf.rb +2 -2
  71. data/lib/asciidoctor-diagram/util/png.rb +2 -2
  72. data/lib/asciidoctor-diagram/util/svg.rb +46 -19
  73. data/lib/asciidoctor-diagram/util/which.rb +0 -29
  74. data/lib/asciidoctor-diagram/vega/converter.rb +47 -0
  75. data/lib/asciidoctor-diagram/vega/extension.rb +6 -44
  76. data/lib/asciidoctor-diagram/version.rb +1 -1
  77. data/lib/asciidoctor-diagram/wavedrom/converter.rb +50 -0
  78. data/lib/asciidoctor-diagram/wavedrom/extension.rb +6 -46
  79. data/lib/ditaa-1.3.15.jar +0 -0
  80. data/lib/ditaamini-0.12.jar +0 -0
  81. data/lib/plantuml-1.3.15.jar +0 -0
  82. data/lib/plantuml.jar +0 -0
  83. data/lib/server-1.3.15.jar +0 -0
  84. data/spec/a2s_spec.rb +2 -140
  85. data/spec/blockdiag_spec.rb +2 -200
  86. data/spec/bpmn_spec.rb +56 -0
  87. data/spec/bytefield_spec.rb +92 -0
  88. data/spec/ditaa_spec.rb +37 -143
  89. data/spec/dpic_spec.rb +19 -0
  90. data/spec/erd_spec.rb +2 -199
  91. data/spec/gnuplot_spec.rb +225 -0
  92. data/spec/graphviz_spec.rb +6 -145
  93. data/spec/lilypond_spec.rb +13 -0
  94. data/spec/mermaid_spec.rb +35 -200
  95. data/spec/msc_spec.rb +2 -199
  96. data/spec/nomnoml_spec.rb +4 -142
  97. data/spec/pikchr_spec.rb +51 -0
  98. data/spec/plantuml_spec.rb +24 -507
  99. data/spec/shaape_spec.rb +9 -221
  100. data/spec/shared_examples.rb +552 -0
  101. data/spec/smcat_spec.rb +26 -0
  102. data/spec/svgbob_spec.rb +2 -140
  103. data/spec/symbolator_spec.rb +23 -0
  104. data/spec/syntrax_spec.rb +5 -215
  105. data/spec/test_helper.rb +1 -18
  106. data/spec/tikz_spec.rb +4 -24
  107. data/spec/umlet_spec.rb +2 -58
  108. data/spec/vega_spec.rb +4 -117
  109. data/spec/wavedrom_spec.rb +2 -199
  110. metadata +73 -11
  111. data/lib/asciidoctor-diagram/extensions.rb +0 -568
  112. data/lib/ditaa-1.3.13.jar +0 -0
  113. data/lib/ditaamini-0.11.jar +0 -0
  114. data/lib/plantuml-1.3.13.jar +0 -0
  115. data/lib/server-1.3.13.jar +0 -0
@@ -0,0 +1,322 @@
1
+ require 'asciidoctor/logging'
2
+ require_relative 'util/which'
3
+
4
+ module Asciidoctor
5
+ module Diagram
6
+ # This module describes the duck-typed interface that diagram sources must implement. Implementations
7
+ # may include this module but it is not required.
8
+ module DiagramSource
9
+ include Asciidoctor::Logging
10
+
11
+ def diagram_type
12
+ raise NotImplementedError.new
13
+ end
14
+
15
+ def image_name
16
+ raise NotImplementedError.new
17
+ end
18
+
19
+ # @return [String] the String representation of the source code for the diagram
20
+ # @abstract
21
+ def code
22
+ raise NotImplementedError.new
23
+ end
24
+
25
+ def global_attr(name, default_value = nil)
26
+ attr(name) || attr(name, default_value, 'diagram')
27
+ end
28
+
29
+ # Get the value for the specified attribute. First look in the attributes on
30
+ # this document and return the value of the attribute if found. Otherwise, if
31
+ # this document is a child of the Document document, look in the attributes of the
32
+ # Document document and return the value of the attribute if found. Otherwise,
33
+ # return the default value, which defaults to nil.
34
+ #
35
+ # @param name [String, Symbol, Array] the name(s) of the attribute to lookup
36
+ # @param default_value [Object] the value to return if the attribute is not found
37
+ # @inherit [Boolean, String] indicates whether to check for the attribute on the AsciiDoctor::Document if not found on this document.
38
+ # When a non-nil String is given the an attribute name "#{inherit}-#{name}" is looked for on the document.
39
+ #
40
+ # @return the value of the attribute or the default value if the attribute is not found in the attributes of this node or the document node
41
+ # @abstract
42
+ def attr(name, default_value = nil, inherit = diagram_type)
43
+ raise NotImplementedError.new
44
+ end
45
+
46
+ # @return [String] the base directory against which relative paths in this diagram should be resolved
47
+ # @abstract
48
+ def base_dir
49
+ attr('docdir', nil, true) || Dir.pwd
50
+ end
51
+
52
+ # Alias for code
53
+ def to_s
54
+ code
55
+ end
56
+
57
+ # Determines if the diagram should be regenerated or not. The default implementation of this method simply
58
+ # returns true.
59
+ #
60
+ # @param image_file [String] the path to the previously generated version of the image
61
+ # @param image_metadata [Hash] the image metadata Hash that was stored during the previous diagram generation pass
62
+ # @return [Boolean] true if the diagram should be regenerated; false otherwise
63
+ def should_process?(image_file, image_metadata)
64
+ true
65
+ end
66
+
67
+ # Creates an image metadata Hash that will be stored to disk alongside the generated image file. The contents
68
+ # of this Hash are reread during subsequent document processing and then passed to the should_process? method
69
+ # where it can be used to determine if the diagram should be regenerated or not.
70
+ # The default implementation returns an empty Hash.
71
+ # @return [Hash] a Hash containing metadata
72
+ def create_image_metadata
73
+ {}
74
+ end
75
+
76
+ def config
77
+ raise NotImplementedError.new
78
+ end
79
+
80
+ def find_command(cmd, options = {})
81
+ attr_names = options[:attrs] || options.fetch(:alt_attrs, []) + [cmd]
82
+ cmd_names = [cmd] + options.fetch(:alt_cmds, [])
83
+
84
+ cmd_var = 'cmd-' + attr_names[0]
85
+
86
+ if config.key? cmd_var
87
+ cmd_path = config[cmd_var]
88
+ else
89
+ logger.debug "Finding '#{cmd}' in attributes"
90
+ cmd_path = attr_names.map { |attr_name|
91
+ attr = attr(attr_name, nil, true)
92
+ if logger.debug? && attr
93
+ logger.debug "Found value '#{attr}' in attribute '#{attr_name}'" if attr
94
+ end
95
+ attr
96
+ }
97
+ .reject { |attr| attr.nil? }
98
+ .map { |attr|
99
+ expanded = File.expand_path(attr)
100
+ if logger.debug? && attr != expanded
101
+ logger.debug "Expanded '#{attr}' to '#{expanded}'"
102
+ end
103
+ expanded
104
+ }
105
+ .select { |path|
106
+ executable = File.executable?(path)
107
+ if logger.debug?
108
+ logger.debug "Is '#{path}' executable? #{executable}"
109
+ end
110
+ executable
111
+ }
112
+ .first
113
+
114
+ unless cmd_path
115
+ logger.debug "Finding '#{cmd}' in environment"
116
+ cmd_path = cmd_names.map { |c|
117
+ path = ::Asciidoctor::Diagram::Which.which(c, :path => options[:path])
118
+ if logger.debug? && path
119
+ logger.debug "Found '#{path}' in environment"
120
+ end
121
+ path
122
+ }
123
+ .reject { |path| path.nil? }
124
+ .first
125
+ end
126
+
127
+ config[cmd_var] = cmd_path
128
+
129
+ if cmd_path.nil? && options.fetch(:raise_on_error, true)
130
+ raise "Could not find the #{cmd_names.map { |c| "'#{c}'" }.join(', ')} executable in PATH; add it to the PATH or specify its location using the '#{attr_names[0]}' document attribute"
131
+ end
132
+ end
133
+
134
+ cmd_path
135
+ end
136
+
137
+ def resolve_path target, start = base_dir
138
+ raise NotImplementedError.new
139
+ end
140
+ end
141
+
142
+ # Base class for diagram source implementations that uses an md5 checksum of the source code of a diagram to
143
+ # determine if it has been updated or not.
144
+ class BasicSource
145
+ include DiagramSource
146
+
147
+ attr_reader :attributes
148
+
149
+ def initialize(block_processor, parent_block, attributes)
150
+ @block_processor = block_processor
151
+ @parent_block = parent_block
152
+ @attributes = attributes
153
+ end
154
+
155
+ def diagram_type
156
+ @block_processor.name.downcase
157
+ end
158
+
159
+ def resolve_path target, start = base_dir
160
+ @parent_block.normalize_system_path(target, start)
161
+ end
162
+
163
+ def config
164
+ @block_processor.config
165
+ end
166
+
167
+ def image_name
168
+ attr('target', 'diag-' + checksum)
169
+ end
170
+
171
+ def attr(name, default_value = nil, inherit = diagram_type)
172
+ name = name.to_s if ::Symbol === name
173
+ name = [name] unless name.is_a?(Enumerable)
174
+
175
+ value = name.lazy.map { |n| @attributes[n] }.reject { |v| v.nil? }.first
176
+
177
+ if value.nil? && inherit
178
+ inherited_values = name.lazy.map do |n|
179
+ case inherit
180
+ when String, Symbol
181
+ @parent_block.attr("#{inherit.to_s}-#{n}", default_value, true)
182
+ else
183
+ @parent_block.attr(n, default_value, inherit)
184
+ end
185
+ end
186
+ value = inherited_values.reject { |v| v.nil? }.first
187
+ end
188
+
189
+ value || default_value
190
+ end
191
+
192
+ def should_process?(image_file, image_metadata)
193
+ image_metadata[:checksum] != checksum
194
+ end
195
+
196
+ def create_image_metadata
197
+ {:checksum => checksum}
198
+ end
199
+
200
+ def checksum
201
+ @checksum ||= compute_checksum(code)
202
+ end
203
+
204
+ protected
205
+
206
+ def resolve_diagram_subs
207
+ if @attributes.key? 'subs'
208
+ @parent_block.resolve_block_subs @attributes['subs'], nil, 'diagram'
209
+ else
210
+ []
211
+ end
212
+ end
213
+
214
+ private
215
+
216
+ def compute_checksum(code)
217
+ md5 = Digest::MD5.new
218
+ md5 << code
219
+ @attributes.each do |k, v|
220
+ md5 << k.to_s if k
221
+ md5 << v.to_s if v
222
+ end
223
+ md5.hexdigest
224
+ end
225
+ end
226
+
227
+ # A diagram source that retrieves the code for the diagram from the contents of a block.
228
+ class ReaderSource < BasicSource
229
+ include DiagramSource
230
+
231
+ def initialize(block_processor, parent_block, reader, attributes)
232
+ super(block_processor, parent_block, attributes)
233
+ @reader = reader
234
+ end
235
+
236
+ def code
237
+ @code ||= @parent_block.apply_subs(@reader.lines, resolve_diagram_subs).join("\n")
238
+ end
239
+ end
240
+
241
+ # A diagram source that retrieves the code for a diagram from an external source file.
242
+ class FileSource < BasicSource
243
+ def initialize(block_processor, parent_block, file_name, attributes)
244
+ super(block_processor, parent_block, attributes)
245
+ @file_name = file_name
246
+ end
247
+
248
+ def base_dir
249
+ if @file_name
250
+ File.dirname(@file_name)
251
+ else
252
+ super
253
+ end
254
+ end
255
+
256
+ def image_name
257
+ if @attributes['target']
258
+ super
259
+ elsif @file_name
260
+ File.basename(@file_name, File.extname(@file_name))
261
+ else
262
+ checksum
263
+ end
264
+ end
265
+
266
+ def should_process?(image_file, image_metadata)
267
+ (@file_name && File.mtime(@file_name) > File.mtime(image_file)) || super
268
+ end
269
+
270
+ def code
271
+ @code ||= read_code
272
+ end
273
+
274
+ def read_code
275
+ if @file_name
276
+ lines = File.readlines(@file_name)
277
+ lines = prepare_source_array(lines)
278
+ @parent_block.apply_subs(lines, resolve_diagram_subs).join("\n")
279
+ else
280
+ ''
281
+ end
282
+ end
283
+
284
+ private
285
+
286
+ # Byte arrays for UTF-* Byte Order Marks
287
+ BOM_BYTES_UTF_8 = [0xef, 0xbb, 0xbf]
288
+ BOM_BYTES_UTF_16LE = [0xff, 0xfe]
289
+ BOM_BYTES_UTF_16BE = [0xfe, 0xff]
290
+
291
+ # Prepare the source data Array for parsing.
292
+ #
293
+ # Encodes the data to UTF-8, if necessary, and removes any trailing
294
+ # whitespace from every line.
295
+ #
296
+ # If a BOM is found at the beginning of the data, a best attempt is made to
297
+ # encode it to UTF-8 from the specified source encoding.
298
+ #
299
+ # data - the source data Array to prepare (no nil entries allowed)
300
+ #
301
+ # returns a String Array of prepared lines
302
+ def prepare_source_array data
303
+ return [] if data.empty?
304
+ if (leading_2_bytes = (leading_bytes = (first = data[0]).unpack 'C3').slice 0, 2) == BOM_BYTES_UTF_16LE
305
+ data[0] = first.byteslice 2, first.bytesize
306
+ # NOTE you can't split a UTF-16LE string using .lines when encoding is UTF-8; doing so will cause this line to fail
307
+ return data.map {|line| (line.encode ::Encoding::UTF_8, ::Encoding::UTF_16LE).rstrip}
308
+ elsif leading_2_bytes == BOM_BYTES_UTF_16BE
309
+ data[0] = first.byteslice 2, first.bytesize
310
+ return data.map {|line| (line.encode ::Encoding::UTF_8, ::Encoding::UTF_16BE).rstrip}
311
+ elsif leading_bytes == BOM_BYTES_UTF_8
312
+ data[0] = first.byteslice 3, first.bytesize
313
+ end
314
+ if first.encoding == ::Encoding::UTF_8
315
+ data.map {|line| line.rstrip}
316
+ else
317
+ data.map {|line| (line.encode ::Encoding::UTF_8).rstrip}
318
+ end
319
+ end
320
+ end
321
+ end
322
+ end
@@ -0,0 +1,90 @@
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.15.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)
37
+ options = {}
38
+
39
+ OPTIONS.keys.each do |option|
40
+ attr_name = option.to_s.tr('_', '-')
41
+ options[option] = source.attr(attr_name) || source.attr(attr_name, nil, 'ditaa-option')
42
+ end
43
+
44
+ options
45
+ end
46
+
47
+ def native_scaling?
48
+ true
49
+ end
50
+
51
+ def convert(source, format, options)
52
+ Java.load
53
+
54
+ flags = []
55
+
56
+ options.each do |option, value|
57
+ OPTIONS[option].call(flags, value)
58
+ end
59
+
60
+ options_string = flags.join(' ')
61
+
62
+ case format
63
+ when :png
64
+ mime_type = 'image/png'
65
+ when :svg
66
+ mime_type = 'image/svg+xml'
67
+ else
68
+ raise "Unsupported format: #{format}"
69
+ end
70
+
71
+ headers = {
72
+ 'Accept' => mime_type,
73
+ 'X-Options' => options_string
74
+ }
75
+
76
+ response = Java.send_request(
77
+ :url => '/ditaa',
78
+ :body => source.to_s,
79
+ :headers => headers
80
+ )
81
+
82
+ unless response[:code] == 200
83
+ raise Java.create_error("Ditaa image generation failed", response)
84
+ end
85
+
86
+ response[:body]
87
+ end
88
+ end
89
+ end
90
+ 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.11.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