asciidoctor-diagram 2.2.3 → 3.0.0

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 (114) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +159 -0
  3. data/README.adoc +17 -13
  4. data/lib/asciidoctor-diagram/a2s/converter.rb +7 -2
  5. data/lib/asciidoctor-diagram/barcode/converter.rb +83 -78
  6. data/lib/asciidoctor-diagram/blockdiag/converter.rb +12 -2
  7. data/lib/asciidoctor-diagram/bpmn/converter.rb +4 -1
  8. data/lib/asciidoctor-diagram/bytefield/converter.rb +4 -1
  9. data/lib/asciidoctor-diagram/d2/converter.rb +57 -0
  10. data/lib/asciidoctor-diagram/d2/extension.rb +18 -0
  11. data/lib/asciidoctor-diagram/d2.rb +8 -0
  12. data/lib/asciidoctor-diagram/dbml/converter.rb +27 -0
  13. data/lib/asciidoctor-diagram/dbml/extension.rb +18 -0
  14. data/lib/asciidoctor-diagram/dbml.rb +8 -0
  15. data/lib/asciidoctor-diagram/diagram_processor.rb +49 -9
  16. data/lib/asciidoctor-diagram/diagram_source.rb +35 -33
  17. data/lib/asciidoctor-diagram/diagrams/converter.rb +4 -1
  18. data/lib/asciidoctor-diagram/ditaa/converter.rb +15 -7
  19. data/lib/asciidoctor-diagram/ditaa/ditaa-2.2.0.jar +0 -0
  20. data/lib/asciidoctor-diagram/dpic/converter.rb +4 -1
  21. data/lib/asciidoctor-diagram/erd/converter.rb +5 -2
  22. data/lib/asciidoctor-diagram/gnuplot/converter.rb +7 -1
  23. data/lib/asciidoctor-diagram/graphviz/converter.rb +4 -1
  24. data/lib/asciidoctor-diagram/graphviz_py/converter.rb +4 -1
  25. data/lib/asciidoctor-diagram/http/converter.rb +16 -7
  26. data/lib/asciidoctor-diagram/http/server.rb +2 -2
  27. data/lib/asciidoctor-diagram/lilypond/converter.rb +3 -2
  28. data/lib/asciidoctor-diagram/meme/converter.rb +29 -3
  29. data/lib/asciidoctor-diagram/mermaid/converter.rb +4 -2
  30. data/lib/asciidoctor-diagram/msc/converter.rb +6 -2
  31. data/lib/asciidoctor-diagram/nomnoml/converter.rb +4 -1
  32. data/lib/asciidoctor-diagram/penrose/converter.rb +53 -0
  33. data/lib/asciidoctor-diagram/penrose/extension.rb +18 -0
  34. data/lib/asciidoctor-diagram/penrose.rb +8 -0
  35. data/lib/asciidoctor-diagram/pikchr/converter.rb +4 -1
  36. data/lib/asciidoctor-diagram/pintora/converter.rb +60 -0
  37. data/lib/asciidoctor-diagram/pintora/extension.rb +18 -0
  38. data/lib/asciidoctor-diagram/pintora.rb +8 -0
  39. data/lib/asciidoctor-diagram/plantuml/converter.rb +256 -43
  40. data/lib/asciidoctor-diagram/plantuml/plantuml-2.2.4.jar +0 -0
  41. data/lib/asciidoctor-diagram/shaape/converter.rb +4 -1
  42. data/lib/asciidoctor-diagram/smcat/converter.rb +5 -1
  43. data/lib/asciidoctor-diagram/structurizr/converter.rb +69 -0
  44. data/lib/asciidoctor-diagram/structurizr/extension.rb +52 -0
  45. data/lib/asciidoctor-diagram/structurizr/renderers.rb +63 -0
  46. data/lib/asciidoctor-diagram/structurizr/structurizr-2.2.2.jar +0 -0
  47. data/lib/asciidoctor-diagram/structurizr.rb +7 -0
  48. data/lib/asciidoctor-diagram/svgbob/converter.rb +6 -2
  49. data/lib/asciidoctor-diagram/symbolator/converter.rb +4 -1
  50. data/lib/asciidoctor-diagram/syntrax/converter.rb +72 -17
  51. data/lib/asciidoctor-diagram/syntrax/syntrax-2.2.0.jar +0 -0
  52. data/lib/asciidoctor-diagram/tikz/converter.rb +5 -2
  53. data/lib/asciidoctor-diagram/umlet/converter.rb +4 -1
  54. data/lib/asciidoctor-diagram/util/base64.rb +25 -0
  55. data/lib/asciidoctor-diagram/util/cli.rb +11 -3
  56. data/lib/asciidoctor-diagram/util/cli_generator.rb +1 -0
  57. data/lib/asciidoctor-diagram/util/java.rb +15 -7
  58. data/lib/asciidoctor-diagram/util/java_jruby.rb +14 -0
  59. data/lib/asciidoctor-diagram/util/java_socket.rb +4 -0
  60. data/lib/asciidoctor-diagram/util/server-2.2.3.jar +0 -0
  61. data/lib/asciidoctor-diagram/util/svg.rb +5 -3
  62. data/lib/asciidoctor-diagram/vega/converter.rb +5 -3
  63. data/lib/asciidoctor-diagram/version.rb +1 -1
  64. data/lib/asciidoctor-diagram/wavedrom/converter.rb +38 -24
  65. data/lib/asciidoctor-diagram.rb +5 -0
  66. metadata +32 -115
  67. data/Rakefile +0 -9
  68. data/docs/antora.yml +0 -3
  69. data/docs/modules/ROOT/images/asciidoctor-diagram-classes.png +0 -0
  70. data/docs/modules/ROOT/images/asciidoctor-diagram-process.png +0 -0
  71. data/docs/modules/ROOT/pages/index.adoc +0 -21
  72. data/docs/modules/ROOT/partials/advanced.adoc +0 -365
  73. data/docs/modules/ROOT/partials/create_diagram.adoc +0 -134
  74. data/docs/modules/ROOT/partials/generate.adoc +0 -15
  75. data/docs/modules/ROOT/partials/installation.adoc +0 -19
  76. data/docs/modules/ROOT/partials/uris.adoc +0 -41
  77. data/examples/Gemfile +0 -3
  78. data/examples/README.adoc +0 -18
  79. data/examples/design.adoc +0 -78
  80. data/examples/features.adoc +0 -189
  81. data/lib/asciidoctor-diagram/ditaa/ditaa-1.3.21.jar +0 -0
  82. data/lib/asciidoctor-diagram/plantuml/plantuml-1.3.21.jar +0 -0
  83. data/lib/asciidoctor-diagram/util/server-1.3.21.jar +0 -0
  84. data/spec/a2s_spec.rb +0 -33
  85. data/spec/barcode_spec.rb +0 -176
  86. data/spec/blockdiag_spec.rb +0 -20
  87. data/spec/bpmn_spec.rb +0 -60
  88. data/spec/bytefield_spec.rb +0 -96
  89. data/spec/diagrams_spec.rb +0 -27
  90. data/spec/ditaa_spec.rb +0 -191
  91. data/spec/dpic_spec.rb +0 -23
  92. data/spec/erd_spec.rb +0 -96
  93. data/spec/gnuplot_spec.rb +0 -229
  94. data/spec/graphviz_py_spec.rb +0 -33
  95. data/spec/graphviz_spec.rb +0 -24
  96. data/spec/lilypond_spec.rb +0 -17
  97. data/spec/man.jpg +0 -0
  98. data/spec/meme_spec.rb +0 -67
  99. data/spec/mermaid_spec.rb +0 -198
  100. data/spec/msc_spec.rb +0 -37
  101. data/spec/nomnoml_spec.rb +0 -36
  102. data/spec/pikchr_spec.rb +0 -73
  103. data/spec/plantuml_spec.rb +0 -772
  104. data/spec/shaape_spec.rb +0 -20
  105. data/spec/shared_examples.rb +0 -764
  106. data/spec/smcat_spec.rb +0 -30
  107. data/spec/svgbob_spec.rb +0 -33
  108. data/spec/symbolator_spec.rb +0 -27
  109. data/spec/syntrax_spec.rb +0 -22
  110. data/spec/test_helper.rb +0 -113
  111. data/spec/tikz_spec.rb +0 -181
  112. data/spec/umlet_spec.rb +0 -32
  113. data/spec/vega_spec.rb +0 -133
  114. data/spec/wavedrom_spec.rb +0 -21
@@ -0,0 +1,8 @@
1
+ require 'asciidoctor/extensions'
2
+ require_relative 'penrose/extension'
3
+
4
+ Asciidoctor::Extensions.register do
5
+ block Asciidoctor::Diagram::PenroseBlockProcessor, :penrose
6
+ block_macro Asciidoctor::Diagram::PenroseBlockMacroProcessor, :penrose
7
+ inline_macro Asciidoctor::Diagram::PenroseInlineMacroProcessor, :penrose
8
+ end
@@ -18,7 +18,10 @@ module Asciidoctor
18
18
  pikchr_path = source.find_command('pikchr')
19
19
 
20
20
  output = generate_file_stdout(pikchr_path, format.to_s, source.to_s) do |tool_path, input_path|
21
- [tool_path, "--svg-only", input_path]
21
+ {
22
+ :args => [tool_path, "--svg-only", input_path],
23
+ :chdir => source.base_dir
24
+ }
22
25
  end
23
26
 
24
27
  if output.start_with? '<svg'
@@ -0,0 +1,60 @@
1
+ require_relative '../diagram_converter'
2
+ require_relative '../util/cli'
3
+ require_relative '../util/cli_generator'
4
+ require_relative '../util/platform'
5
+
6
+ module Asciidoctor
7
+ module Diagram
8
+ # @private
9
+ class PintoraConverter
10
+ include DiagramConverter
11
+ include CliGenerator
12
+
13
+
14
+ def supported_formats
15
+ [:png, :svg]
16
+ end
17
+
18
+ def collect_options(source)
19
+ options = {}
20
+
21
+ options[:width] = source.attr('width')
22
+ options[:theme] = source.attr('theme')
23
+ options[:background_color] = source.attr('background-color')
24
+ options[:pixel_ratio] = source.attr('pixel-ratio')
25
+
26
+ options
27
+ end
28
+
29
+ def convert(source, format, options)
30
+ pintora = source.find_command('pintora')
31
+
32
+ generate_file(pintora, 'pintora', format.to_s, source.to_s) do |tool_path, input_path, output_path|
33
+ args = [tool_path, 'render', '-i', Platform.native_path(input_path), '-o', Platform.native_path(output_path)]
34
+
35
+
36
+ if options[:width]
37
+ args << '-w' << options[:width]
38
+ end
39
+
40
+ if options[:theme]
41
+ args << '-t' << options[:theme]
42
+ end
43
+
44
+ if options[:pixel_ratio]
45
+ args << '-p' << options[:pixel_ratio]
46
+ end
47
+
48
+ if options[:background_color]
49
+ args << '-b' << options[:background_color]
50
+ end
51
+
52
+ {
53
+ :args => args,
54
+ :chdir => source.base_dir
55
+ }
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,18 @@
1
+ require_relative 'converter'
2
+ require_relative '../diagram_processor'
3
+
4
+ module Asciidoctor
5
+ module Diagram
6
+ class PintoraBlockProcessor < DiagramBlockProcessor
7
+ use_converter PintoraConverter
8
+ end
9
+
10
+ class PintoraBlockMacroProcessor < DiagramBlockMacroProcessor
11
+ use_converter PintoraConverter
12
+ end
13
+
14
+ class PintoraInlineMacroProcessor < DiagramInlineMacroProcessor
15
+ use_converter PintoraConverter
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ require 'asciidoctor/extensions'
2
+ require_relative 'pintora/extension'
3
+
4
+ Asciidoctor::Extensions.register do
5
+ block Asciidoctor::Diagram::PintoraBlockProcessor, :pintora
6
+ block_macro Asciidoctor::Diagram::PintoraBlockMacroProcessor, :pintora
7
+ inline_macro Asciidoctor::Diagram::PintoraInlineMacroProcessor, :pintora
8
+ end
@@ -1,4 +1,7 @@
1
1
  require_relative '../diagram_converter'
2
+ require_relative '../util/java'
3
+ require_relative '../util/cli'
4
+ require_relative '../util/cli_generator'
2
5
  require 'delegate'
3
6
  require 'uri'
4
7
 
@@ -7,25 +10,37 @@ module Asciidoctor
7
10
  # @private
8
11
  class PlantUmlConverter
9
12
  include DiagramConverter
13
+ include CliGenerator
10
14
 
11
- CLASSPATH_ENV = 'DIAGRAM_PLANTUML_CLASSPATH'
15
+ CLASSPATH_ENV = Java.environment_variable('DIAGRAM_PLANTUML_CLASSPATH')
12
16
  LIB_DIR = File.expand_path('../..', File.dirname(__FILE__))
13
- PLANTUML_JARS = if ENV.has_key?(CLASSPATH_ENV)
14
- ENV[CLASSPATH_ENV].split(File::PATH_SEPARATOR)
17
+ PLANTUML_JARS = if CLASSPATH_ENV
18
+ CLASSPATH_ENV.split(File::PATH_SEPARATOR)
15
19
  else
16
20
  begin
17
21
  require 'asciidoctor-diagram/plantuml/classpath'
18
22
  ::Asciidoctor::Diagram::PlantUmlClasspath::JAR_FILES
19
23
  rescue LoadError
20
- raise "Could not load PlantUML. Eiter require 'asciidoctor-diagram-plantuml' or specify the location of the PlantUML JAR(s) using the 'DIAGRAM_PLANTUML_CLASSPATH' environment variable."
24
+ nil
21
25
  end
22
26
  end
23
27
 
24
- Java.classpath.concat Dir[File.join(File.dirname(__FILE__), '*.jar')].freeze
25
- Java.classpath.concat PLANTUML_JARS
28
+ if PLANTUML_JARS
29
+ Java.classpath.concat Dir[File.join(File.dirname(__FILE__), '*.jar')].freeze
30
+ Java.classpath.concat PLANTUML_JARS
31
+ end
32
+
33
+ def self.find_plantuml_native(source)
34
+ source.find_command(
35
+ 'plantuml-full',
36
+ :raise_on_error => false,
37
+ :attrs => ['plantuml-native'],
38
+ :alt_cmds => ['plantuml-headless']
39
+ )
40
+ end
26
41
 
27
42
  def wrap_source(source)
28
- PlantUMLPreprocessedSource.new(source, self.class.tag)
43
+ PlantUMLPreprocessedSource.new(source, self)
29
44
  end
30
45
 
31
46
  def supported_formats
@@ -33,12 +48,62 @@ module Asciidoctor
33
48
  end
34
49
 
35
50
  def collect_options(source)
36
- {
37
- :size_limit => source.attr('size-limit', '4096')
51
+ options = {
52
+ :size_limit => source.attr('size-limit', '4096'),
38
53
  }
54
+
55
+ options[:smetana] = true if source.opt('smetana')
56
+
57
+ theme = source.attr('theme', nil)
58
+ options[:theme] = theme if theme
59
+
60
+ options[:debug] = true if source.opt('debug')
61
+
62
+ options
63
+ end
64
+
65
+ def should_preprocess(source)
66
+ source.attr('preprocess', 'true') == 'true'
39
67
  end
40
68
 
41
69
  def convert(source, format, options)
70
+ plantuml_native = PlantUmlConverter.find_plantuml_native(source)
71
+ if plantuml_native
72
+ convert_native(plantuml_native, source, format, options)
73
+ elsif PLANTUML_JARS
74
+ convert_http(source, format, options)
75
+ else
76
+ raise "Could not load PlantUML. Either require 'asciidoctor-diagram-plantuml' " \
77
+ "or specify the location of the PlantUML JAR(s) using the 'DIAGRAM_PLANTUML_CLASSPATH' environment variable. " \
78
+ "Alternatively a PlantUML binary can be provided (plantuml-native in $PATH)."
79
+ end
80
+ end
81
+
82
+ def add_common_headers(headers, source)
83
+ base_dir = source.base_dir
84
+
85
+ config_file = source.attr('plantumlconfig', nil, true) || source.attr('config')
86
+ if config_file
87
+ headers['X-PlantUML-Config'] = File.expand_path(config_file, base_dir)
88
+ end
89
+
90
+ headers['X-PlantUML-Basedir'] = Platform.native_path(File.expand_path(base_dir))
91
+
92
+ include_dir = source.attr('includedir')
93
+ if include_dir
94
+ headers['X-PlantUML-IncludeDir'] = Platform.native_path(File.expand_path(include_dir, base_dir))
95
+ end
96
+ end
97
+
98
+ def add_theme_header(headers, theme)
99
+ headers['X-PlantUML-Theme'] = theme if theme
100
+ end
101
+
102
+ def add_size_limit_header(headers, limit)
103
+ headers['X-PlantUML-SizeLimit'] = limit if limit
104
+ end
105
+
106
+ def convert_http(source, format, options)
42
107
  Java.load
43
108
 
44
109
  code = source.code
@@ -57,30 +122,139 @@ module Asciidoctor
57
122
  end
58
123
 
59
124
  headers = {
60
- 'Accept' => mime_type
125
+ 'Accept' => mime_type
61
126
  }
62
127
 
63
- size_limit = options[:size_limit]
64
- if size_limit
65
- headers['X-PlantUML-SizeLimit'] = size_limit
128
+ unless should_preprocess(source)
129
+ add_common_headers(headers, source)
66
130
  end
67
131
 
132
+ add_theme_header(headers, options[:theme])
133
+ add_size_limit_header(headers, options[:size_limit])
134
+
68
135
  dot = source.find_command('dot', :alt_attrs => ['graphvizdot'], :raise_on_error => false)
69
- if dot
136
+ if options[:smetana] || !dot
137
+ headers['X-Graphviz'] = 'smetana'
138
+ else
70
139
  headers['X-Graphviz'] = ::Asciidoctor::Diagram::Platform.host_os_path(dot)
71
140
  end
72
141
 
142
+ if options[:debug]
143
+ headers['X-PlantUML-Debug'] = 'true'
144
+ end
145
+
73
146
  response = Java.send_request(
74
- :url => '/plantuml',
75
- :body => code,
76
- :headers => headers
147
+ :url => '/plantuml',
148
+ :body => code,
149
+ :headers => headers
77
150
  )
78
151
 
79
152
  unless response[:code] == 200
80
153
  raise Java.create_error("PlantUML image generation failed", response)
81
154
  end
82
155
 
83
- response[:body]
156
+ if response[:headers]['content-type'] =~ /multipart\/form-data;\s*boundary=(.*)/
157
+ boundary = $1
158
+ parts = {}
159
+
160
+ multipart_data = StringIO.new(response[:body])
161
+ while true
162
+ multipart_data.readline
163
+ marker = multipart_data.readline
164
+ if marker.start_with? "--#{boundary}--"
165
+ break
166
+ elsif marker.start_with? "--#{boundary}"
167
+ part = Java.parse_body(multipart_data)
168
+ if part[:headers]['content-disposition'] =~ /form-data;\s*name="([^"]*)"/
169
+ if $1 == 'image'
170
+ parts[:result] = part[:body]
171
+ else
172
+ parts[:extra] ||= {}
173
+ parts[:extra][$1] = part[:body]
174
+ end
175
+ else
176
+ raise "Unexpected multipart content disposition"
177
+ end
178
+ else
179
+ raise "Unexpected multipart boundary"
180
+ end
181
+ end
182
+
183
+ parts
184
+ else
185
+ response[:body]
186
+ end
187
+ end
188
+
189
+ def add_theme_arg(args, theme)
190
+ if theme
191
+ args << '-theme' << theme
192
+ end
193
+ end
194
+
195
+ def add_common_args(args, source)
196
+ base_dir = File.expand_path(source.base_dir)
197
+ args << '-filedir'
198
+ args << base_dir
199
+
200
+ config_file = source.attr('plantumlconfig', nil, true) || source.attr('config')
201
+ if config_file
202
+ args << '-config'
203
+ args << File.expand_path(config_file, base_dir)
204
+ end
205
+
206
+ include_dir = source.attr('includedir')
207
+ if include_dir
208
+ args << "-Dplantuml.include.path=#{Platform.native_path(File.expand_path(include_dir, base_dir))}"
209
+ end
210
+ end
211
+
212
+ def convert_native(plantuml, source, format, options)
213
+ code = source.code
214
+
215
+ args = []
216
+ env = {}
217
+
218
+ args << case format
219
+ when :png
220
+ '-tpng'
221
+ when :svg
222
+ '-tsvg'
223
+ when :txt, :utxt
224
+ '-tutxt'
225
+ when :atxt
226
+ '-ttxt'
227
+ else
228
+ raise "Unsupported format: #{format}"
229
+ end
230
+
231
+ add_common_args(args, source)
232
+ add_theme_arg(args, options[:theme])
233
+
234
+ if options[:size_limit]
235
+ env['PLANTUML_LIMIT_SIZE'] = options[:size_limit]
236
+ end
237
+
238
+ dot = source.find_command('dot', :alt_attrs => ['graphvizdot'], :raise_on_error => false)
239
+ if options[:smetana] || !dot
240
+ args << '-Playout=smetana'
241
+ else
242
+ args << '-graphvizdot'
243
+ args << ::Asciidoctor::Diagram::Platform.host_os_path(dot)
244
+ end
245
+
246
+ generate_stdin_stdout(plantuml, code) do |tool, _|
247
+ cmd = [tool]
248
+ cmd << '-pipe'
249
+ cmd << '-failfast2'
250
+ cmd << '-stdrpt:1'
251
+ cmd.concat args
252
+
253
+ {
254
+ :args => cmd,
255
+ :env => env
256
+ }
257
+ end
84
258
  end
85
259
  end
86
260
 
@@ -97,9 +271,11 @@ module Asciidoctor
97
271
  end
98
272
 
99
273
  class PlantUMLPreprocessedSource < SimpleDelegator
100
- def initialize(source, tag)
274
+ include CliGenerator
275
+
276
+ def initialize(source, converter)
101
277
  super(source)
102
- @tag = tag
278
+ @converter = converter
103
279
  end
104
280
 
105
281
  def code
@@ -107,44 +283,81 @@ module Asciidoctor
107
283
  end
108
284
 
109
285
  def load_code
286
+ code = __getobj__.code
287
+
288
+ tag = @converter.class.tag
289
+ code = "@start#{tag}\n#{code}\n@end#{tag}" unless code.index("@start") && code.index("@end")
290
+
291
+ if @converter.should_preprocess(self)
292
+ plantuml_native = PlantUmlConverter.find_plantuml_native(self)
293
+ if plantuml_native
294
+ code = preprocess_native(plantuml_native, code)
295
+ else
296
+ code = preprocess_http(code)
297
+ end
298
+ end
299
+
300
+ code
301
+ end
302
+
303
+ private
304
+
305
+ def preprocess_http(code)
110
306
  Java.load
111
307
 
112
- code = __getobj__.code
308
+ headers = {}
309
+ @converter.add_common_headers(headers, self)
310
+ @converter.add_theme_header(headers, @converter.collect_options(self)[:theme])
311
+
312
+ response = Java.send_request(
313
+ :url => '/plantumlpreprocessor',
314
+ :body => code,
315
+ :headers => headers
316
+ )
317
+
318
+ unless response[:code] == 200
319
+ raise Java.create_error("PlantUML preprocessing failed", response)
320
+ end
113
321
 
114
- code = "@start#{@tag}\n#{code}\n@end#{@tag}" unless code.index("@start") && code.index("@end")
322
+ code = response[:body]
323
+ code.force_encoding(Encoding::UTF_8)
324
+ end
115
325
 
116
- should_preprocess = attr('preprocess', 'true') == 'true'
326
+ def preprocess_native(plantuml, code)
327
+ generate_stdin_stdout(plantuml, code) do |tool, _|
328
+ cmd = [tool]
329
+ cmd << '-pipe'
330
+ cmd << '-preproc'
331
+ cmd << '-failfast2'
332
+ cmd << '-stdrpt:1'
117
333
 
118
- if should_preprocess
119
- headers = {}
334
+ @converter.add_common_args(cmd, self)
335
+ @converter.add_theme_arg(cmd, @converter.collect_options(self)[:theme])
120
336
 
121
- config_file = attr('plantumlconfig', nil, true) || attr('config')
337
+ base_dir = File.expand_path(self.base_dir)
338
+ cmd << '-filedir'
339
+ cmd << base_dir
340
+
341
+ config_file = self.attr('plantumlconfig', nil, true) || self.attr('config')
122
342
  if config_file
123
- headers['X-PlantUML-Config'] = File.expand_path(config_file, base_dir)
343
+ cmd << '-config'
344
+ cmd << File.expand_path(config_file, base_dir)
124
345
  end
125
346
 
126
- headers['X-PlantUML-Basedir'] = Platform.native_path(File.expand_path(base_dir))
127
-
128
- include_dir = attr('includedir')
347
+ include_dir = self.attr('includedir')
129
348
  if include_dir
130
- headers['X-PlantUML-IncludeDir'] = Platform.native_path(File.expand_path(include_dir, base_dir))
349
+ cmd << "-Dplantuml.include.path=#{Platform.native_path(File.expand_path(include_dir, base_dir))}"
131
350
  end
132
351
 
133
- response = Java.send_request(
134
- :url => '/plantumlpreprocessor',
135
- :body => code,
136
- :headers => headers
137
- )
138
-
139
- unless response[:code] == 200
140
- raise Java.create_error("PlantUML preprocessing failed", response)
352
+ theme = @converter.collect_options(self)[:theme]
353
+ if theme
354
+ cmd << '-theme' << theme
141
355
  end
142
356
 
143
- code = response[:body]
144
- code.force_encoding(Encoding::UTF_8)
357
+ {
358
+ :args => cmd
359
+ }
145
360
  end
146
-
147
- code
148
361
  end
149
362
  end
150
363
  end
@@ -17,7 +17,10 @@ module Asciidoctor
17
17
 
18
18
  def convert(source, format, options)
19
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, '-']
20
+ {
21
+ :args => [tool_path, '-o', Platform.native_path(output_path), '-t', format.to_s, '-'],
22
+ :chdir => source.base_dir
23
+ }
21
24
  end
22
25
  end
23
26
  end
@@ -36,7 +36,11 @@ module Asciidoctor
36
36
  end
37
37
 
38
38
  args << '-'
39
- args
39
+
40
+ {
41
+ :args => args,
42
+ :chdir => source.base_dir
43
+ }
40
44
  end
41
45
  end
42
46
  end
@@ -0,0 +1,69 @@
1
+ require 'set'
2
+
3
+ require_relative '../diagram_converter'
4
+ require_relative '../diagram_processor'
5
+ require_relative '../plantuml/converter'
6
+ require_relative '../util/java'
7
+
8
+ module Asciidoctor
9
+ module Diagram
10
+ # @private
11
+ class StructurizrConverter
12
+ include DiagramConverter
13
+
14
+ CLASSPATH_ENV = Java.environment_variable('DIAGRAM_STRUCTURIZR_CLASSPATH')
15
+ CLI_HOME_ENV = Java.environment_variable('DIAGRAM_STRUCTURIZRCLI_HOME')
16
+ STRUCTURIZR_JARS = if CLASSPATH_ENV
17
+ CLASSPATH_ENV.split(File::PATH_SEPARATOR)
18
+ elsif CLI_HOME_ENV
19
+ lib_dir = File.expand_path('lib', CLI_HOME_ENV)
20
+ Dir[File.join(lib_dir, '*.jar')]
21
+ else
22
+ nil
23
+ end
24
+
25
+ if STRUCTURIZR_JARS
26
+ Java.classpath.concat Dir[File.join(File.dirname(__FILE__), '*.jar')]
27
+ Java.classpath.concat STRUCTURIZR_JARS
28
+ end
29
+
30
+ def supported_formats
31
+ [:txt]
32
+ end
33
+
34
+ def collect_options(source)
35
+ {
36
+ :view => source.attr('view'),
37
+ :renderer => Renderers.get_renderer_type(source)
38
+ }
39
+ end
40
+
41
+ def convert(source, format, options)
42
+ unless STRUCTURIZR_JARS
43
+ raise "Could not load Structurizr. Specify the location of the Structurizr JAR(s) using the 'DIAGRAM_STRUCTURIZRCLI_HOME' or DIAGRAM_STRUCTURIZR_CLASSPATH' environment variable."
44
+ end
45
+
46
+ Java.load
47
+
48
+ headers = {
49
+ 'Accept' => Renderers.mime_type(options[:renderer])
50
+ }
51
+ headers['X-Structurizr-View'] = options[:view] if options[:view]
52
+ headers['X-Structurizr-IncludeDir'] = Platform.native_path(source.base_dir)
53
+
54
+
55
+ response = Java.send_request(
56
+ :url => '/structurizr',
57
+ :body => source.code,
58
+ :headers => headers
59
+ )
60
+
61
+ unless response[:code] == 200
62
+ raise Java.create_error("Structurizr code generation failed", response)
63
+ end
64
+
65
+ response[:body].force_encoding(Encoding::UTF_8)
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,52 @@
1
+ require_relative 'converter'
2
+ require_relative 'renderers.rb'
3
+ require_relative '../diagram_processor'
4
+
5
+ module Asciidoctor
6
+ module Diagram
7
+
8
+ class StructurizrConvertBlockProcessor < DiagramBlockProcessor
9
+ use_converter StructurizrConverter
10
+ end
11
+
12
+ class StructurizrBlockProcessor < Asciidoctor::Extensions::BlockProcessor
13
+ DiagramBlockProcessor.inherited(self)
14
+
15
+ def initialize(name = nil, config = nil)
16
+ super
17
+ @structurizr = StructurizrConvertBlockProcessor.new(name)
18
+ @renderers = Renderers.new(name)
19
+ end
20
+
21
+ def process parent, reader, attributes
22
+ structurizr_attrs = attributes.dup
23
+ structurizr_attrs['format'] = 'txt'
24
+
25
+ renderer_block = @structurizr.process(parent, reader, structurizr_attrs)
26
+ @renderers.get_renderer(BasicSource.new(self, parent, attributes)).process(parent, renderer_block, attributes)
27
+ end
28
+ end
29
+
30
+ class StructurizrConvertBlockMacroProcessor < DiagramBlockMacroProcessor
31
+ use_converter StructurizrConverter
32
+ end
33
+
34
+ class StructurizrBlockMacroProcessor < Asciidoctor::Extensions::BlockMacroProcessor
35
+ DiagramBlockMacroProcessor.inherited(self)
36
+
37
+ def initialize(name = nil, config = nil)
38
+ super
39
+ @structurizr = StructurizrConvertBlockMacroProcessor.new(name)
40
+ @renderers = Renderers.new(name)
41
+ end
42
+
43
+ def process parent, target, attributes
44
+ structurizr_attrs = attributes.dup
45
+ structurizr_attrs['format'] = 'txt'
46
+
47
+ renderer_block = @structurizr.process(parent, target, structurizr_attrs)
48
+ @renderers.get_renderer(BasicSource.new(self, parent, attributes)).process(parent, renderer_block, attributes)
49
+ end
50
+ end
51
+ end
52
+ end