asciidoctor-diagram 1.5.2 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7c8a0442a43c4f2b062c9a2875db9bfe487ebfe
4
- data.tar.gz: e5ed8001a95d21ff5461ab9adf71b679dcdeb8c5
3
+ metadata.gz: ed682b9f1a5ebc023f78291b9cb575ab954a7c98
4
+ data.tar.gz: fb35b25a74669f7eb1540a2733b7c667ba0f2859
5
5
  SHA512:
6
- metadata.gz: 9261c02e0ce34b5b532352d5c8816f682c4cea2e352e90c7a8ac51909ed1295da58f4b337e41a852a63469bf9280596b8d11e321d8a7587f2a8e77e38274967e
7
- data.tar.gz: 3540b311b595776f6bac442827a077fcfeefbd24e50ee8fbe58d9a756633213bd4a02336847fcda91647dd6feb2c113d701506859ec6c61dc3660b3e073d4762
6
+ metadata.gz: 29d512423d17e0cd4bb3c6f4ef21816e5716ad07e11df2059961c50a667d15a963521f6fe24b5702852d2610fededad4ab4b699aab5be52efed428e507deff6a
7
+ data.tar.gz: 21829e5be06344ea24a6a48c43968d71a8c2f51c4828acaf456b97d04f80141a2fc83cb731829dfdf7ef52682966c6b30891e5d9f823fcdc4f23558302339b95
@@ -1,6 +1,17 @@
1
1
  = Asciidoctor-diagram Changelog
2
2
 
3
- == Development
3
+ == 1.5.3
4
+
5
+ Enhancements::
6
+
7
+ * Issue #124: Improve compatibility with Cygwin
8
+ * Issue #133: Support substitutions in block macro target attribute
9
+ * Issue #135: Add support for PDF output for blockdiag and graphviz.
10
+ * Update PlantUML to revision 8053 (21/12/2016)
11
+
12
+ Bug Fixes::
13
+
14
+ * Resolve error when using WaveDromEditor.app on macOS
4
15
 
5
16
  == 1.5.2
6
17
 
@@ -103,23 +103,23 @@ Diagram in appropriate syntax
103
103
 
104
104
  The following diagram types and output formats are available:
105
105
 
106
- [cols=">,4*^",options="header"]
106
+ [cols=">,5*^",options="header"]
107
107
  |===
108
- |Diagram Type |gif |png |svg |txt
109
- |{uri-actdiag}[actdiag] | |{check}|{check}|
110
- |{uri-blockdiag}[blockdiag] | |{check}|{check}|
111
- |{uri-ditaa}[ditaa] | |{check}| |
112
- |{uri-erd}[erd] | |{check}|{check}|
113
- |{uri-dot}[graphviz] | |{check}|{check}|
114
- |<<meme,meme>> |{check}|{check}| |
115
- |{uri-mermaid}[mermaid] | |{check}|{check}|
116
- |{uri-nwdiag}[nwdiag] | |{check}|{check}|
117
- |{uri-packetdiag}[packetdiag]| |{check}|{check}|
118
- |{uri-plantuml}[plantuml] | |{check}|{check}|{check}
119
- |{uri-rackdiag}[rackdiag] | |{check}|{check}|
120
- |{uri-seqdiag}[seqdiag] | |{check}|{check}|
121
- |{uri-shaape}[shaape] | |{check}|{check}|
122
- |{uri-wavedrom}[wavedrom] | |{check}|{check}|
108
+ |Diagram Type |gif |pdf |png |svg |txt
109
+ |{uri-actdiag}[actdiag] | |{check}|{check}|{check}|
110
+ |{uri-blockdiag}[blockdiag] | |{check}|{check}|{check}|
111
+ |{uri-ditaa}[ditaa] | | |{check}| |
112
+ |{uri-erd}[erd] | | |{check}|{check}|
113
+ |{uri-dot}[graphviz] | |{check}|{check}|{check}|
114
+ |<<meme,meme>> |{check}| |{check}| |
115
+ |{uri-mermaid}[mermaid] | | |{check}|{check}|
116
+ |{uri-nwdiag}[nwdiag] | |{check}|{check}|{check}|
117
+ |{uri-packetdiag}[packetdiag]| |{check}|{check}|{check}|
118
+ |{uri-plantuml}[plantuml] | | |{check}|{check}|{check}
119
+ |{uri-rackdiag}[rackdiag] | |{check}|{check}|{check}|
120
+ |{uri-seqdiag}[seqdiag] | |{check}|{check}|{check}|
121
+ |{uri-shaape}[shaape] | | |{check}|{check}|
122
+ |{uri-wavedrom}[wavedrom] | | |{check}|{check}|
123
123
  |===
124
124
 
125
125
  The example below illustrates the structure of a basic ditaa block written directly in an AsciiDoc document.
@@ -309,12 +309,62 @@ The target of the block macro tells the extension which image to use as backgrou
309
309
  The first two positional attributes are `top` and `bottom` and are used for the top and bottom label.
310
310
  Occurrences of `\\` surrounded by whitespace are interpreted as line breaks.
311
311
 
312
- The block macro also supports the following named attributes:
312
+ === Diagram Attributes
313
313
 
314
- . `fillColor`: the fill color for the text. Defaults to `white`.
315
- . `strokeColor`: the outline color for the text. Defaults to `black`.
316
- . `strokeWidth`: the width of the text outline. Defaults to `2`.
317
- . `font`: the font face to use for the text. Defaults to `Impact`.
318
- . `options`: a comma separate list of flags that modify the image rendering. Currently only `noupcase` is supported which disable upper casing the labels.
319
- . `target` (3rd positional attribute): the basename of the file to generate. If not specified an auto-generated name will be used.
320
- . `format` (4th positional attribute): the output image format. The meme extension supports `png` and `gif`.
314
+ Certain diagram types allow image generation to be customized using attributes.
315
+
316
+ ==== Ditaa
317
+
318
+ [cols=">,<,<",options="header"]
319
+ |===
320
+ |Name |Default value |Description
321
+ |scale |1 |A scale factor that is applied to the image.
322
+ |tabs |8 |An integer value that specifies the tab size as a number of spaces.
323
+ |background |FFFFFF |The background colour of the image. The format should be a six-digit hexadecimal number (as in HTML, FF0000 for red). Pass an eight-digit hex to define transparency.
324
+ |antialias |true |Enables or disables anti-aliasing.
325
+ |separation |true |Prevents the separation of common edges of shapes.
326
+ |round-corners|false |Causes all corners to be rendered as round corners.
327
+ |shadows |true |Enables or disable drop shadows.
328
+ |debug |false |Renders the debug grid over the resulting image.
329
+ |fixed-slope |false |Makes sides of parallelograms and trapezoids fixed slope instead of fixed width.
330
+ |transparent |false |Makes the background of the image transparent instead of using the background color.
331
+ |===
332
+
333
+ ==== GraphViz
334
+
335
+ [cols=">,<,<",options="header"]
336
+ |===
337
+ |Name |Default value |Description
338
+ |layout |unspecified |The graphviz layout engine to use (dot -K option).
339
+ |===
340
+
341
+ ==== Meme
342
+
343
+ [cols=">,<,<",options="header"]
344
+ |===
345
+ |Name |Default value |Description
346
+ |fillColor |white |The fill color for the text.
347
+ |strokeColor |black |The outline color for the text
348
+ |strokeWidth |2 |The width of the text outline.
349
+ |font |Impact |The font face to use for the text.
350
+ |options |unspecified |a comma separate list of flags that modify the image rendering. Currently only `noupcase` is supported which disable upper casing the labels.
351
+ |===
352
+
353
+ ==== Mermaid
354
+
355
+ [cols=">,<,<",options="header"]
356
+ |===
357
+ |Name |Default value |Description
358
+ |css |unspecified |Path to a CSS file to pass to mermaid.
359
+ |ganttconfig |unspecified |Path to a gantt config file to pass to mermaid.
360
+ |sequenceconfig|unspecified |Path to a sequence config file to pass to mermaid.
361
+ |width |unspecified |The width of the generated image.
362
+ |===
363
+
364
+ ==== PlantUML
365
+
366
+ [cols=">,<,<",options="header"]
367
+ |===
368
+ |Name |Default value |Description
369
+ |config |unspecified |Path to a config file to pass to PlantUML.
370
+ |===
@@ -21,6 +21,7 @@ ifndef::env-site[:status:]
21
21
  :uri-blockdiag: http://blockdiag.com
22
22
  :uri-ditaa: http://ditaa.sourceforge.net/
23
23
  :uri-dot: http://www.graphviz.org/content/dot-language
24
+ :uri-erd: https://github.com/BurntSushi/erd
24
25
  :uri-graphviz: http://www.graphviz.org
25
26
  :uri-imagemagick: http://www.imagemagick.org
26
27
  :uri-java: http://java.sun.com
@@ -115,6 +116,7 @@ gem 'asciidoctor-diagram', '~> 1.4.0'
115
116
  |{uri-actdiag}[actdiag] | |{check}|{check}|
116
117
  |{uri-blockdiag}[blockdiag] | |{check}|{check}|
117
118
  |{uri-ditaa}[ditaa] | |{check}| |
119
+ |{uri-erd}[erd] | |{check}|{check}|
118
120
  |{uri-dot}[graphviz] | |{check}|{check}|
119
121
  |<<meme,meme>> |{check}|{check}| |
120
122
  |{uri-mermaid}[mermaid] | |{check}|{check}|
@@ -238,7 +240,7 @@ require 'asciidoctor-diagram'
238
240
  require 'asciidoctor-diagram/<extension_name>'
239
241
  ----
240
242
 
241
- `<extension_name>` 可以是 `blockdiag`、`ditaa`、`graphviz`、`meme`、`mermaid`、`plantuml`、`shaape` 或 `wavedrom`。
243
+ `<extension_name>` 可以是 `blockdiag`、`ditaa`、`erd`、`graphviz`、`meme`、`mermaid`、`plantuml`、`shaape` 或 `wavedrom`。
242
244
 
243
245
  加载一个或多个这些文件将为所有需要处理的文档自动注册这些扩展。
244
246
 
@@ -289,6 +291,7 @@ Asciidoctor Diagram 依赖外部工具来生成图片。
289
291
  |actdiag |{uri-actdiag}[ActDiag] |`actdiag`
290
292
  |blockdiag |{uri-blockdiag}[BlockDiag] |`blockdiag`
291
293
  |ditaa |{uri-java}[Java] |`java`
294
+ |erd |{uri-erd}[Erd] |`erd`
292
295
  |graphviz |{uri-graphviz}[GraphViz] |`dot` 或 `graphvizdot`
293
296
  |meme |{uri-imagemagick}[ImageMagick] |`convert` 和 `identify`
294
297
  |mermaid |{uri-mermaid}[Mermaid] |`mermaid`
@@ -77,7 +77,7 @@ module Asciidoctor
77
77
  init = Proc.new do
78
78
  include ::Asciidoctor::Diagram::BlockDiag
79
79
 
80
- [:png, :svg].each do |f|
80
+ [:png, :pdf, :svg].each do |f|
81
81
  register_format(f, :image) do |p, c|
82
82
  blockdiag(name, p, c, f)
83
83
  end
@@ -6,6 +6,7 @@ require 'fileutils'
6
6
  require_relative 'version'
7
7
  require_relative 'util/java'
8
8
  require_relative 'util/gif'
9
+ require_relative 'util/pdf'
9
10
  require_relative 'util/png'
10
11
  require_relative 'util/svg'
11
12
 
@@ -26,7 +27,7 @@ module Asciidoctor
26
27
  #
27
28
  # Examples
28
29
  #
29
- # register_format(:png, :image ) do |parent, source|
30
+ # register_format(:png, :image ) do |parent_block, source|
30
31
  # File.read(source.to_s)
31
32
  # end
32
33
  def register_format(format, type, &block)
@@ -74,6 +75,10 @@ module Asciidoctor
74
75
  :png => {
75
76
  :encoding => Encoding::ASCII_8BIT,
76
77
  :decoder => PNG
78
+ },
79
+ :pdf => {
80
+ :encoding => Encoding::ASCII_8BIT,
81
+ :decoder => PDF
77
82
  }
78
83
  }
79
84
 
@@ -133,7 +138,7 @@ module Asciidoctor
133
138
  # Creates a DiagramSource object for the block or block macro being processed. Classes using this
134
139
  # mixin must implement this method.
135
140
  #
136
- # @param parent [Asciidoctor::AbstractBlock] the parent asciidoc block of the block or block macro being processed
141
+ # @param parent_block [Asciidoctor::AbstractBlock] the parent asciidoc block of the block or block macro being processed
137
142
  # @param reader_or_target [Asciidoctor::Reader, String] a reader that provides the contents of a block or the
138
143
  # target value of a block macro
139
144
  # @param attributes [Hash] the attributes of the block or block macro
@@ -141,7 +146,7 @@ module Asciidoctor
141
146
  # @return [DiagramSource] an object that implements the interface described by DiagramSource
142
147
  #
143
148
  # @abstract
144
- def create_source(parent, reader_or_target, attributes)
149
+ def create_source(parent_block, reader_or_target, attributes)
145
150
  raise NotImplementedError.new
146
151
  end
147
152
 
@@ -264,8 +269,8 @@ module Asciidoctor
264
269
  # Creates a ReaderSource from the given reader.
265
270
  #
266
271
  # @return [ReaderSource] a ReaderSource
267
- def create_source(parent, reader, attributes)
268
- ReaderSource.new(parent, reader, attributes)
272
+ def create_source(parent_block, reader, attributes)
273
+ ReaderSource.new(parent_block, reader, attributes)
269
274
  end
270
275
  end
271
276
 
@@ -281,7 +286,8 @@ module Asciidoctor
281
286
  #
282
287
  # @return [FileSource] a FileSource
283
288
  def create_source(parent, target, attributes)
284
- FileSource.new(parent, target.empty? ? nil : parent.normalize_system_path(target, parent.attr('docdir')), attributes)
289
+ target = parent.sub_attributes(target, :attribute_missing => 'warn') if target
290
+ FileSource.new(parent, target, attributes)
285
291
  end
286
292
  end
287
293
 
@@ -308,11 +314,12 @@ module Asciidoctor
308
314
  #
309
315
  # @param name [String, Symbol] the name of the attribute to lookup
310
316
  # @param default_value [Object] the value to return if the attribute is not found
311
- # @inherit [Boolean] indicates whether to check for the attribute on the AsciiDoctor::Document if not found on this node
317
+ # @inherit [Boolean, String] indicates whether to check for the attribute on the AsciiDoctor::Document if not found on this node.
318
+ # When a non-nil String is given the an attribute name "#{inherit}-#{name}" is looked for on the document.
312
319
  #
313
320
  # @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
314
321
  # @abstract
315
- def attr(name, default_value = nil, inherit = true)
322
+ def attr(name, default_value = nil, inherit = nil)
316
323
  raise NotImplementedError.new
317
324
  end
318
325
 
@@ -354,8 +361,8 @@ module Asciidoctor
354
361
 
355
362
  attr_reader :attributes
356
363
 
357
- def initialize(parent, attributes)
358
- @parent = parent
364
+ def initialize(parent_block, attributes)
365
+ @parent_block = parent_block
359
366
  @attributes = attributes
360
367
  end
361
368
 
@@ -366,11 +373,18 @@ module Asciidoctor
366
373
  def attr(name, default_value=nil, inherit=nil)
367
374
  name = name.to_s if ::Symbol === name
368
375
 
369
- if inherit
370
- @attributes[name] || @parent.attr(name, default_value, true)
371
- else
372
- @attributes[name] || default_value
376
+ value = @attributes[name]
377
+
378
+ if value.nil? && inherit
379
+ case inherit
380
+ when String
381
+ value = @parent_block.attr("#{inherit}-#{name}", default_value, true)
382
+ else
383
+ value = @parent_block.attr(name, default_value, true)
384
+ end
373
385
  end
386
+
387
+ value || default_value
374
388
  end
375
389
 
376
390
  def should_process?(image_file, image_metadata)
@@ -388,7 +402,7 @@ module Asciidoctor
388
402
  protected
389
403
  def resolve_diagram_subs
390
404
  if @attributes.key? 'subs'
391
- subs = @parent.resolve_block_subs @attributes['subs'], nil, 'diagram'
405
+ subs = @parent_block.resolve_block_subs @attributes['subs'], nil, 'diagram'
392
406
  subs.empty? ? nil : subs
393
407
  else
394
408
  nil
@@ -411,8 +425,8 @@ module Asciidoctor
411
425
  class ReaderSource < BasicSource
412
426
  include DiagramSource
413
427
 
414
- def initialize(parent, reader, attributes)
415
- super(parent, attributes)
428
+ def initialize(parent_block, reader, attributes)
429
+ super(parent_block, attributes)
416
430
  @reader = reader
417
431
  end
418
432
 
@@ -421,14 +435,14 @@ module Asciidoctor
421
435
  end
422
436
 
423
437
  def code
424
- @code ||= @parent.apply_subs(@reader.lines, resolve_diagram_subs).join("\n")
438
+ @code ||= @parent_block.apply_subs(@reader.lines, resolve_diagram_subs).join("\n")
425
439
  end
426
440
  end
427
441
 
428
442
  # A diagram source that retrieves the code for a diagram from an external source file.
429
443
  class FileSource < BasicSource
430
- def initialize(parent, file_name, attributes)
431
- super(parent, attributes)
444
+ def initialize(parent_block, file_name, attributes)
445
+ super(parent_block, attributes)
432
446
  @file_name = file_name
433
447
  end
434
448
 
@@ -458,7 +472,7 @@ module Asciidoctor
458
472
  if @file_name
459
473
  lines = File.readlines(@file_name)
460
474
  lines = ::Asciidoctor::Helpers.normalize_lines(lines)
461
- @parent.apply_subs(lines, resolve_diagram_subs).join("\n")
475
+ @parent_block.apply_subs(lines, resolve_diagram_subs).join("\n")
462
476
  else
463
477
  ''
464
478
  end
@@ -11,7 +11,7 @@ module Asciidoctor
11
11
  include Which
12
12
 
13
13
  def self.included(mod)
14
- [:png, :svg].each do |f|
14
+ [:pdf, :png, :svg].each do |f|
15
15
  mod.register_format(f, :image) do |parent, source|
16
16
  graphviz(parent, source, f)
17
17
  end
@@ -22,7 +22,7 @@ module Asciidoctor
22
22
  generate_stdin(which(parent, 'dot', :alt_attrs => ['graphvizdot']), format.to_s, source.to_s) do |tool_path, output_path|
23
23
  args = [tool_path, "-o#{Platform.native_path(output_path)}", "-T#{format.to_s}"]
24
24
 
25
- layout = source.attr('layout')
25
+ layout = source.attr('layout', nil, 'graphviz')
26
26
  args << "-K#{layout}" if layout
27
27
 
28
28
  args
@@ -18,22 +18,22 @@ module Asciidoctor
18
18
  end
19
19
  end
20
20
 
21
- def meme(p, c, format)
22
- convert = which(p, 'convert')
23
- identify = which(p, 'identify')
21
+ def meme(parent_block, source, format)
22
+ convert = which(parent_block, 'convert')
23
+ identify = which(parent_block, 'identify')
24
24
 
25
- bg_img = c.attr('background')
25
+ bg_img = source.attr('background', nil, 'meme')
26
26
  raise "background attribute is required" unless bg_img
27
27
 
28
- bg_img = p.normalize_system_path(bg_img, p.attr('imagesdir'))
28
+ bg_img = parent_block.normalize_system_path(bg_img, parent_block.attr('imagesdir'))
29
29
 
30
- top_label = c.attr('top')
31
- bottom_label = c.attr('bottom')
32
- fill_color = c.attr('fillColor', 'white')
33
- stroke_color = c.attr('strokeColor', 'black')
34
- stroke_width = c.attr('strokeWidth', '2')
35
- font = c.attr('font', 'Impact')
36
- options = c.attr('options', '').split(',')
30
+ top_label = source.attr('top')
31
+ bottom_label = source.attr('bottom')
32
+ fill_color = source.attr('fillColor', 'white', 'meme')
33
+ stroke_color = source.attr('strokeColor', 'black', 'meme')
34
+ stroke_width = source.attr('strokeWidth', '2', 'meme')
35
+ font = source.attr('font', 'Impact', 'meme')
36
+ options = source.attr('options', '', 'meme').split(',')
37
37
  noupcase = options.include?('noupcase')
38
38
 
39
39
  dimensions = Cli.run(identify, '-format', '%w %h', bg_img).match(/(?<w>\d+) (?<h>\d+)/)
@@ -19,18 +19,28 @@ module Asciidoctor
19
19
  end
20
20
  end
21
21
 
22
- def mermaid(parent, source, format)
23
- mermaid = which(parent, 'mermaid')
22
+ def mermaid(parent_block, source, format)
23
+ mermaid = which(parent_block, 'mermaid')
24
24
  @is_mermaid_v6 ||= ::Asciidoctor::Diagram::Cli.run(mermaid, '--version').split('.')[0].to_i >= 6
25
25
  # Mermaid >= 6.0.0 requires PhantomJS 2.1; older version required 1.9
26
- phantomjs = which(parent, 'phantomjs', :alt_attrs => [@is_mermaid_v6 ? 'phantomjs_2' : 'phantomjs_19'])
26
+ phantomjs = which(parent_block, 'phantomjs', :alt_attrs => [@is_mermaid_v6 ? 'phantomjs_2' : 'phantomjs_19'])
27
27
 
28
- seq_config = source.attr('sequenceConfig', nil, true)
28
+ css = source.attr('css', nil, 'mermaid')
29
+ if css
30
+ css = parent_block.normalize_system_path(css, source.base_dir)
31
+ end
32
+
33
+ gantt_config = source.attr('ganttConfig', nil, 'mermaid') || source.attr('ganttconfig', nil, 'mermaid')
34
+ if gantt_config
35
+ gantt_config = parent_block.normalize_system_path(gantt_config, source.base_dir)
36
+ end
37
+
38
+ seq_config = source.attr('sequenceConfig', nil, 'mermaid') || source.attr('sequenceconfig', nil, 'mermaid')
29
39
  if seq_config
30
- seq_config = parent.normalize_system_path(seq_config, source.base_dir)
40
+ seq_config = parent_block.normalize_system_path(seq_config, source.base_dir)
31
41
  end
32
42
 
33
- width = source.attr('width')
43
+ width = source.attr('width', nil, 'mermaid')
34
44
 
35
45
  generate_file(mermaid, 'mmd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
36
46
  output_dir = File.dirname(output_path)
@@ -38,6 +48,14 @@ module Asciidoctor
38
48
 
39
49
  args = [tool_path, '--phantomPath', Platform.native_path(phantomjs), "--#{format.to_s}", '-o', Platform.native_path(output_dir)]
40
50
 
51
+ if css
52
+ args << '--css' << Platform.native_path(css)
53
+ end
54
+
55
+ if gantt_config
56
+ args << '--gantt_config' << Platform.native_path(gantt_config)
57
+ end
58
+
41
59
  if seq_config
42
60
  args << '--sequenceConfig' << Platform.native_path(seq_config)
43
61
  end
@@ -15,23 +15,23 @@ module Asciidoctor
15
15
  end
16
16
  Java.classpath.concat JARS
17
17
 
18
- def plantuml(parent, source, tag, mime_type)
18
+ def plantuml(parent_block, source, tag, mime_type)
19
19
  Java.load
20
20
 
21
- code = preprocess_code(parent, source, tag)
21
+ code = preprocess_code(parent_block, source, tag)
22
22
 
23
23
  headers = {
24
24
  'Accept' => mime_type
25
25
  }
26
26
 
27
- config_file = parent.attr('plantumlconfig', nil, true)
27
+ config_file = source.attr('plantumlconfig', nil, true) || source.attr('config', nil, 'plantuml')
28
28
  if config_file
29
- headers['X-PlantUML-Config'] = File.expand_path(config_file, parent.attr('docdir', nil, true))
29
+ headers['X-PlantUML-Config'] = File.expand_path(config_file, source.attr('docdir', nil, true))
30
30
  end
31
31
 
32
- dot = which(parent, 'dot', :alt_attrs => ['graphvizdot'], :raise_on_error => false)
32
+ dot = which(parent_block, 'dot', :alt_attrs => ['graphvizdot'], :raise_on_error => false)
33
33
  if dot
34
- headers['X-Graphviz'] = dot
34
+ headers['X-Graphviz'] = ::Asciidoctor::Diagram::Platform.host_os_path(dot)
35
35
  end
36
36
 
37
37
  response = Java.send_request(
@@ -78,14 +78,14 @@ module Asciidoctor
78
78
  end
79
79
 
80
80
  def self.included(mod)
81
- mod.register_format(:png, :image) do |parent, source|
82
- plantuml(parent, source, mod.tag, 'image/png')
81
+ mod.register_format(:png, :image) do |parent_block, source|
82
+ plantuml(parent_block, source, mod.tag, 'image/png')
83
83
  end
84
- mod.register_format(:svg, :image) do |parent, source|
85
- plantuml(parent, source, mod.tag, 'image/svg+xml')
84
+ mod.register_format(:svg, :image) do |parent_block, source|
85
+ plantuml(parent_block, source, mod.tag, 'image/svg+xml')
86
86
  end
87
- mod.register_format(:txt, :literal) do |parent, source|
88
- plantuml(parent, source, mod.tag, 'text/plain;charset=utf-8')
87
+ mod.register_format(:txt, :literal) do |parent_block, source|
88
+ plantuml(parent_block, source, mod.tag, 'text/plain;charset=utf-8')
89
89
  end
90
90
  end
91
91
  end
@@ -15,18 +15,7 @@ module Asciidoctor
15
15
  args = []
16
16
  args << '-Djava.awt.headless=true'
17
17
  args << '-cp'
18
- # special case for cygwin, it requires path translation for java to work
19
- if ::Asciidoctor::Diagram::Platform.os_variant == :cygwin
20
- cygpath = ::Asciidoctor::Diagram::Which.which('cygpath')
21
- if cygpath != nil
22
- args << classpath.flatten.map { |jar| ::Asciidoctor::Diagram::Cli.run(cygpath, '-w', jar).strip }.join(";")
23
- else
24
- puts 'cygwin warning: cygpath not found'
25
- args << classpath.flatten.join(File::PATH_SEPARATOR)
26
- end
27
- else
28
- args << classpath.flatten.join(File::PATH_SEPARATOR)
29
- end
18
+ args << classpath.flatten.map { |jar| ::Asciidoctor::Diagram::Platform.host_os_path(jar).strip }.join(::Asciidoctor::Diagram::Platform.host_os_path_separator)
30
19
  args << 'org.asciidoctor.diagram.CommandServer'
31
20
 
32
21
  @server = IO.popen([java, *args])
@@ -0,0 +1,10 @@
1
+ module Asciidoctor
2
+ module Diagram
3
+ # @private
4
+ module PDF
5
+ def self.get_image_size(_)
6
+ nil
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,4 +1,6 @@
1
1
  require 'rbconfig'
2
+ require_relative 'cli'
3
+ require_relative 'which'
2
4
 
3
5
  module Asciidoctor
4
6
  module Diagram
@@ -11,24 +13,42 @@ module Asciidoctor
11
13
  os_info[:os_variant]
12
14
  end
13
15
 
16
+ def self.file_separator
17
+ os_info[:file_sep]
18
+ end
19
+
20
+ def self.host_os_file_separator
21
+ os_info[:host_os_file_sep]
22
+ end
23
+
14
24
  def self.path_separator
15
25
  os_info[:path_sep]
16
26
  end
17
27
 
28
+ def self.host_os_path_separator
29
+ os_info[:host_os_path_sep]
30
+ end
31
+
18
32
  def self.os_info
19
33
  @os ||= (
20
34
  host_os = RbConfig::CONFIG['host_os']
21
35
 
22
- path_sep = '/'
36
+ file_sep = '/'
37
+ host_os_file_sep = nil
23
38
  variant = nil
39
+ path_sep = ::File::PATH_SEPARATOR
40
+ host_os_path_sep = nil
41
+
24
42
  case host_os
25
- when /(mswin|bccwin|wince|emc)/i
43
+ when /(msys|mingw|mswin|bccwin|wince|emc)/i
26
44
  os = :windows
27
45
  variant = $1.downcase.to_sym
28
- path_sep = '\\'
29
- when /(msys|mingw|cygwin)/i
46
+ file_sep = '\\'
47
+ when /(cygwin)/i
30
48
  os = :windows
31
49
  variant = $1.downcase.to_sym
50
+ host_os_file_sep = '\\'
51
+ host_os_path_sep = ';'
32
52
  when /darwin|mac os/i
33
53
  os = :macosx
34
54
  when /linux/i
@@ -37,7 +57,12 @@ module Asciidoctor
37
57
  os = :unix
38
58
  end
39
59
  {
40
- :os => os, :os_variant => variant || os, :path_sep => path_sep
60
+ :os => os,
61
+ :os_variant => variant || os,
62
+ :file_sep => file_sep,
63
+ :host_os_file_sep => host_os_file_sep || file_sep,
64
+ :path_sep => path_sep,
65
+ :host_os_path_sep => host_os_path_sep || path_sep
41
66
  }
42
67
  )
43
68
  end
@@ -45,13 +70,28 @@ module Asciidoctor
45
70
  def self.native_path(path)
46
71
  return path if path.nil?
47
72
 
48
- path_sep = path_separator
49
- if path_sep != '/'
50
- path.to_s.gsub('/', path_sep)
73
+ sep = file_separator
74
+ if sep != '/'
75
+ path.to_s.gsub('/', sep)
51
76
  else
52
77
  path.to_s
53
78
  end
54
79
  end
80
+
81
+ def self.host_os_path(path)
82
+ # special case for cygwin, it requires path translation for java to work
83
+ if os_variant == :cygwin
84
+ cygpath = ::Asciidoctor::Diagram::Which.which('cygpath')
85
+ if cygpath != nil
86
+ ::Asciidoctor::Diagram::Cli.run(cygpath, '-w', path)
87
+ else
88
+ puts 'cygwin warning: cygpath not found'
89
+ native_path(path)
90
+ end
91
+ else
92
+ native_path(path)
93
+ end
94
+ end
55
95
  end
56
96
  end
57
97
  end
@@ -17,7 +17,7 @@ module Asciidoctor
17
17
  end
18
18
 
19
19
  def which(parent_block, cmd, options = {})
20
- attr_names = options.fetch(:alt_attrs, []) + [cmd]
20
+ attr_names = options[:attrs] || options.fetch(:alt_attrs, []) + [cmd]
21
21
  cmd_names = [cmd] + options.fetch(:alt_cmds, [])
22
22
 
23
23
  cmd_var = '@' + attr_names[0]
@@ -1,5 +1,5 @@
1
1
  module Asciidoctor
2
2
  module Diagram
3
- VERSION = "1.5.2"
3
+ VERSION = "1.5.3"
4
4
  end
5
5
  end
@@ -28,12 +28,12 @@ module Asciidoctor
28
28
  end
29
29
  else
30
30
  if ::Asciidoctor::Diagram::Platform.os == :macosx
31
- wavedrom = which(parent, 'WaveDromEditor.app', :alt_attrs => ['wavedrom'], :path => ['/Applications'])
31
+ wavedrom = which(parent, 'WaveDromEditor.app', :attrs => ['WaveDromEditorApp'],:path => ['/Applications'])
32
32
  if wavedrom
33
33
  wavedrom = File.join(wavedrom, 'Contents/MacOS/nwjs')
34
34
  end
35
35
  else
36
- wavedrom = which(parent, 'WaveDromEditor', :alt_attrs => ['wavedrom'])
36
+ wavedrom = which(parent, 'WaveDromEditor')
37
37
  end
38
38
 
39
39
  generate_file(wavedrom, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
Binary file
@@ -99,6 +99,36 @@ Doc Writer <doc@example.com>
99
99
  expect(b.attributes['height']).to_not be_nil
100
100
  end
101
101
 
102
+ it "should generate PDF files when format is set to 'pdf'" do
103
+ doc = <<-eos
104
+ = Hello, BlockDiag!
105
+ Doc Writer <doc@example.com>
106
+
107
+ == First Section
108
+
109
+ [blockdiag, format="pdf"]
110
+ ----
111
+ #{code}
112
+ ----
113
+ eos
114
+
115
+ d = load_asciidoc doc
116
+ expect(d).to_not be_nil
117
+
118
+ b = d.find { |bl| bl.context == :image }
119
+ expect(b).to_not be_nil
120
+
121
+ expect(b.content_model).to eq :empty
122
+
123
+ target = b.attributes['target']
124
+ expect(target).to_not be_nil
125
+ expect(target).to match(/\.pdf/)
126
+ expect(File.exist?(target)).to be true
127
+
128
+ expect(b.attributes['width']).to be_nil
129
+ expect(b.attributes['height']).to be_nil
130
+ end
131
+
102
132
  it "should raise an error when when format is set to an invalid value" do
103
133
  doc = <<-eos
104
134
  = Hello, BlockDiag!
@@ -107,6 +107,41 @@ plantuml::plantuml.txt[format="svg", subs=attributes+]
107
107
  expect(content).to include('ChildClass')
108
108
  end
109
109
 
110
+ it 'should support substitutions in the target attribute' do
111
+ code = <<-eos
112
+ class {parent-class}
113
+ class {child-class}
114
+ {parent-class} <|-- {child-class}
115
+ eos
116
+
117
+ File.write('plantuml.txt', code)
118
+
119
+ doc = <<-eos
120
+ = Hello, PlantUML!
121
+ Doc Writer <doc@example.com>
122
+ :file: plantuml
123
+ :parent-class: ParentClass
124
+ :child-class: ChildClass
125
+
126
+ == First Section
127
+
128
+ plantuml::{file}.txt[format="svg", subs=attributes+]
129
+ eos
130
+
131
+ d = load_asciidoc doc, :attributes => {'backend' => 'html5'}
132
+ expect(d).to_not be_nil
133
+
134
+ b = d.find { |bl| bl.context == :image }
135
+ expect(b).to_not be_nil
136
+
137
+ target = b.attributes['target']
138
+ expect(File.exist?(target)).to be true
139
+
140
+ content = File.read(target)
141
+ expect(content).to include('ParentClass')
142
+ expect(content).to include('ChildClass')
143
+ end
144
+
110
145
  it 'should resolve !include directives with relative paths' do
111
146
  included = <<-eos
112
147
  interface List
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-diagram
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pepijn Van Eeckhoudt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-14 00:00:00.000000000 Z
11
+ date: 2017-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -111,6 +111,7 @@ files:
111
111
  - lib/asciidoctor-diagram/util/java.rb
112
112
  - lib/asciidoctor-diagram/util/java_jruby.rb
113
113
  - lib/asciidoctor-diagram/util/java_socket.rb
114
+ - lib/asciidoctor-diagram/util/pdf.rb
114
115
  - lib/asciidoctor-diagram/util/platform.rb
115
116
  - lib/asciidoctor-diagram/util/png.rb
116
117
  - lib/asciidoctor-diagram/util/svg.rb