asciidoctor-diagram 1.5.2 → 1.5.4

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: d38f932148312e67e4249a2c171c71da2c796a49
4
+ data.tar.gz: c50317e4443b383f73be0b3e068364185cba7a97
5
5
  SHA512:
6
- metadata.gz: 9261c02e0ce34b5b532352d5c8816f682c4cea2e352e90c7a8ac51909ed1295da58f4b337e41a852a63469bf9280596b8d11e321d8a7587f2a8e77e38274967e
7
- data.tar.gz: 3540b311b595776f6bac442827a077fcfeefbd24e50ee8fbe58d9a756633213bd4a02336847fcda91647dd6feb2c113d701506859ec6c61dc3660b3e073d4762
6
+ metadata.gz: 9d8544bb90e946c5b20b9e675268e519cf52f9dd89a3b054b4214a9c1b3dff59d6ce9683569616c3ed9d81441dc089179cb559e1569b1c11e4d586f99d457a41
7
+ data.tar.gz: d26cbf53122d923276a543f49efe434ba8690fbb85ba0e44ced6c52bd4c24779fb110bcef1c3f03c29f5b731dfc15c4a30c06d78516742987815c70a6d6886ab
data/CHANGELOG.adoc CHANGED
@@ -1,6 +1,28 @@
1
1
  = Asciidoctor-diagram Changelog
2
2
 
3
- == Development
3
+ == 1.5.4
4
+
5
+ Enhancements::
6
+
7
+ * Add support for UMLet.
8
+ * Issue #141: Allow blockdiag fontpath to be specified via attributes
9
+
10
+ Bug Fixes::
11
+
12
+ * Issue #140: Restore PNG as default format for Graphviz diagrams
13
+
14
+ == 1.5.3
15
+
16
+ Enhancements::
17
+
18
+ * Issue #124: Improve compatibility with Cygwin
19
+ * Issue #133: Support substitutions in block macro target attribute
20
+ * Issue #135: Add support for PDF output for blockdiag and graphviz.
21
+ * Update PlantUML to revision 8053 (21/12/2016)
22
+
23
+ Bug Fixes::
24
+
25
+ * Resolve error when using WaveDromEditor.app on macOS
4
26
 
5
27
  == 1.5.2
6
28
 
data/README.adoc CHANGED
@@ -32,6 +32,7 @@ ifndef::env-site[:status:]
32
32
  :uri-rackdiag: http://blockdiag.com/en/nwdiag/index.html
33
33
  :uri-seqdiag: http://blockdiag.com/en/seqdiag/index.html
34
34
  :uri-shaape: https://github.com/christiangoltz/shaape
35
+ :uri-umlet: http://www.umlet.com/
35
36
  :uri-wavedrom: http://wavedrom.com
36
37
  :uri-wavedromeditor: https://github.com/wavedrom/wavedrom.github.io/releases
37
38
  :uri-wavedromcli: https://github.com/wavedrom/cli
@@ -103,23 +104,24 @@ Diagram in appropriate syntax
103
104
 
104
105
  The following diagram types and output formats are available:
105
106
 
106
- [cols=">,4*^",options="header"]
107
+ [cols=">,5*^",options="header"]
107
108
  |===
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}|
109
+ |Diagram Type |gif |pdf |png |svg |txt
110
+ |{uri-actdiag}[actdiag] | |{check}|{check}|{check}|
111
+ |{uri-blockdiag}[blockdiag] | |{check}|{check}|{check}|
112
+ |{uri-ditaa}[ditaa] | | |{check}| |
113
+ |{uri-erd}[erd] | | |{check}|{check}|
114
+ |{uri-dot}[graphviz] | |{check}|{check}|{check}|
115
+ |<<meme,meme>> |{check}| |{check}| |
116
+ |{uri-mermaid}[mermaid] | | |{check}|{check}|
117
+ |{uri-nwdiag}[nwdiag] | |{check}|{check}|{check}|
118
+ |{uri-packetdiag}[packetdiag]| |{check}|{check}|{check}|
119
+ |{uri-plantuml}[plantuml] | | |{check}|{check}|{check}
120
+ |{uri-rackdiag}[rackdiag] | |{check}|{check}|{check}|
121
+ |{uri-seqdiag}[seqdiag] | |{check}|{check}|{check}|
122
+ |{uri-shaape}[shaape] | | |{check}|{check}|
123
+ |{uri-umlet}[umlet] |{check}|{check}|{check}|{check}|
124
+ |{uri-wavedrom}[wavedrom] | | |{check}|{check}|
123
125
  |===
124
126
 
125
127
  The example below illustrates the structure of a basic ditaa block written directly in an AsciiDoc document.
@@ -287,6 +289,7 @@ The following table lists the tools that are required for each diagram type, the
287
289
  |rackdiag |{uri-nwdiag}[NwDiag] |`rackdiag`
288
290
  |seqdiag |{uri-seqdiag}[SeqDiag] |`seqdiag`
289
291
  |shaape |{uri-shaape}[Shaape] |`shaape`
292
+ |umlet |{uri-umlet}[Umlet] |`umlet`
290
293
  .2+|wavedrom |{uri-wavedromeditor}[WaveDrom Editor] |`wavedrom`
291
294
  |{uri-wavedromcli}[WaveDrom CLI] and {uri-phantomjs}[PhantomJS] |`wavedrom` and `phantomjs`
292
295
  |===
@@ -309,12 +312,92 @@ The target of the block macro tells the extension which image to use as backgrou
309
312
  The first two positional attributes are `top` and `bottom` and are used for the top and bottom label.
310
313
  Occurrences of `\\` surrounded by whitespace are interpreted as line breaks.
311
314
 
312
- The block macro also supports the following named attributes:
315
+ === Diagram Attributes
313
316
 
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`.
317
+ Certain diagram types allow image generation to be customized using attributes.
318
+ Each attribute can be specified either at the block level or at the document level.
319
+ This is illustrated for the blockdiag `fontpath` attribute in the example below.
320
+
321
+ ----
322
+ = Asciidoctor Diagram
323
+ :blockdiag-fontpath: /path/to/font.ttf <1>
324
+
325
+ [blockdiag] <2>
326
+ ....
327
+ ....
328
+
329
+ [blockdiag, fontpath="/path/to/otherfont.ttf"] <3>
330
+ ....
331
+ ....
332
+ ----
333
+ <1> Block level attributes can be specified at the document level by prefixing them with `<blocktype>-`
334
+ <2> The first diagram does not specify an explicit value for `fontpath` so the global value will be used
335
+ <3> The second diagram specifies a `fontpath` value which overrrides the global value
336
+
337
+ Each attribute can either be specified at the block level or at the document level.
338
+ The attribute name at the block level should be prefixed with the name of the diagram type and a dash.
339
+
340
+
341
+ ==== Blockdiag
342
+
343
+ [cols=">,<,<",options="header"]
344
+ |===
345
+ |Name |Default value |Description
346
+ |fontpath |unspecified |The path to the font that should be used by blockdiag
347
+ |===
348
+
349
+ ==== Ditaa
350
+
351
+ [cols=">,<,<",options="header"]
352
+ |===
353
+ |Name |Default value |Description
354
+ |scale |1 |A scale factor that is applied to the image.
355
+ |tabs |8 |An integer value that specifies the tab size as a number of spaces.
356
+ |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.
357
+ |antialias |true |Enables or disables anti-aliasing.
358
+ |separation |true |Prevents the separation of common edges of shapes.
359
+ |round-corners|false |Causes all corners to be rendered as round corners.
360
+ |shadows |true |Enables or disable drop shadows.
361
+ |debug |false |Renders the debug grid over the resulting image.
362
+ |fixed-slope |false |Makes sides of parallelograms and trapezoids fixed slope instead of fixed width.
363
+ |transparent |false |Makes the background of the image transparent instead of using the background color.
364
+ |===
365
+
366
+ ==== GraphViz
367
+
368
+ [cols=">,<,<",options="header"]
369
+ |===
370
+ |Name |Default value |Description
371
+ |layout |unspecified |The graphviz layout engine to use (dot -K option).
372
+ |===
373
+
374
+ ==== Meme
375
+
376
+ [cols=">,<,<",options="header"]
377
+ |===
378
+ |Name |Default value |Description
379
+ |fillColor |white |The fill color for the text.
380
+ |strokeColor |black |The outline color for the text
381
+ |strokeWidth |2 |The width of the text outline.
382
+ |font |Impact |The font face to use for the text.
383
+ |options |unspecified |a comma separate list of flags that modify the image rendering. Currently only `noupcase` is supported which disable upper casing the labels.
384
+ |===
385
+
386
+ ==== Mermaid
387
+
388
+ [cols=">,<,<",options="header"]
389
+ |===
390
+ |Name |Default value |Description
391
+ |css |unspecified |Path to a CSS file to pass to mermaid.
392
+ |ganttconfig |unspecified |Path to a gantt config file to pass to mermaid.
393
+ |sequenceconfig|unspecified |Path to a sequence config file to pass to mermaid.
394
+ |width |unspecified |The width of the generated image.
395
+ |===
396
+
397
+ ==== PlantUML
398
+
399
+ [cols=">,<,<",options="header"]
400
+ |===
401
+ |Name |Default value |Description
402
+ |config |unspecified |Path to a config file to pass to PlantUML.
403
+ |===
data/README_zh-CN.adoc CHANGED
@@ -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
@@ -106,8 +106,13 @@ module Asciidoctor
106
106
  # a '3' suffix.
107
107
  alt_cmd_name = "#{tool.downcase}3"
108
108
 
109
+ font_path = source.attr('fontpath', nil, tool.downcase)
110
+
109
111
  generate_stdin(which(parent, cmd_name, :alt_cmds => [alt_cmd_name]), format.to_s, source.to_s) do |tool_path, output_path|
110
- [tool_path, '-a', '-o', Platform.native_path(output_path), "-T#{format.to_s}", '-']
112
+ args = [tool_path, '-a', '-o', Platform.native_path(output_path), "-T#{format.to_s}"]
113
+ args << "-f#{Platform.native_path(font_path)}" if font_path
114
+ args << '-'
115
+ args
111
116
  end
112
117
  end
113
118
  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
+ [:png, :pdf, :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
@@ -0,0 +1,36 @@
1
+ require_relative '../extensions'
2
+ require_relative '../util/cli_generator'
3
+ require_relative '../util/platform'
4
+ require_relative '../util/which'
5
+
6
+ module Asciidoctor
7
+ module Diagram
8
+ # @private
9
+ module Umlet
10
+ include CliGenerator
11
+ include Which
12
+
13
+ def self.included(mod)
14
+ [:svg, :png, :pdf, :gif].each do |f|
15
+ mod.register_format(f, :image) do |parent, source|
16
+ umlet(parent, source, f)
17
+ end
18
+ end
19
+ end
20
+
21
+ def umlet(parent, source, format)
22
+ generate_file(which(parent, 'umlet'), 'uxf', format.to_s, source.to_s) do |tool_path, input_path, output_path|
23
+ [tool_path, '-action=convert', "-format=#{format.to_s}", "-filename=#{Platform.native_path(input_path)}", "-output=#{Platform.native_path(output_path)}"]
24
+ end
25
+ end
26
+ end
27
+
28
+ class UmletBlockProcessor < Extensions::DiagramBlockProcessor
29
+ include Umlet
30
+ end
31
+
32
+ class UmletBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
33
+ include Umlet
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,8 @@
1
+ require_relative 'extensions'
2
+
3
+ Asciidoctor::Extensions.register do
4
+ require_relative 'umlet/extension'
5
+
6
+ block Asciidoctor::Diagram::UmletBlockProcessor, :umlet
7
+ block_macro Asciidoctor::Diagram::UmletBlockMacroProcessor, :umlet
8
+ 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.4"
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|
@@ -7,4 +7,5 @@ require_relative 'asciidoctor-diagram/mermaid'
7
7
  require_relative 'asciidoctor-diagram/plantuml'
8
8
  require_relative 'asciidoctor-diagram/salt'
9
9
  require_relative 'asciidoctor-diagram/shaape'
10
+ require_relative 'asciidoctor-diagram/umlet'
10
11
  require_relative 'asciidoctor-diagram/wavedrom'
data/lib/plantuml.jar CHANGED
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
data/spec/test_helper.rb CHANGED
@@ -14,6 +14,7 @@ require_relative '../lib/asciidoctor-diagram/meme/extension'
14
14
  require_relative '../lib/asciidoctor-diagram/mermaid/extension'
15
15
  require_relative '../lib/asciidoctor-diagram/plantuml/extension'
16
16
  require_relative '../lib/asciidoctor-diagram/shaape/extension'
17
+ require_relative '../lib/asciidoctor-diagram/umlet/extension'
17
18
  require_relative '../lib/asciidoctor-diagram/wavedrom/extension'
18
19
 
19
20
  require_relative '../lib/asciidoctor-diagram/util/platform'
@@ -42,9 +43,24 @@ module Asciidoctor
42
43
  options = options.dup
43
44
  options[:trace] = true
44
45
  options[:attributes] ||= {}
46
+
45
47
  options[:attributes]['phantomjs_19'] = ENV['PHANTOMJS_19']
48
+
46
49
  options[:attributes]['phantomjs_2'] = ENV['PHANTOMJS_2']
50
+
51
+ fontpath = ENV['BLOCKDIAG_FONTPATH']
52
+ if fontpath
53
+ options[:attributes]['actdiag-fontpath'] = fontpath
54
+ options[:attributes]['blockdiag-fontpath'] = fontpath
55
+ options[:attributes]['seqdiag-fontpath'] = fontpath
56
+ options[:attributes]['nwdiag-fontpath'] = fontpath
57
+ options[:attributes]['rackdiag-fontpath'] = fontpath
58
+ options[:attributes]['packetdiag-fontpath'] = fontpath
59
+ options[:attributes]['seqdiag-fontpath'] = fontpath
60
+ end
61
+
47
62
  options[:attributes]['diagram-on-error'] = 'abort'
63
+
48
64
  ::Asciidoctor.load(StringIO.new(source), options.merge({:trace => true}))
49
65
  end
50
66
  end
@@ -0,0 +1,85 @@
1
+ require_relative 'test_helper'
2
+
3
+ code = <<-eos
4
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
5
+ <diagram program="umlet" version="14.2">
6
+ <zoom_level>10</zoom_level>
7
+ <element>
8
+ <id>UMLActor</id>
9
+ <coordinates>
10
+ <x>20</x>
11
+ <y>20</y>
12
+ <w>60</w>
13
+ <h>120</h>
14
+ </coordinates>
15
+ <panel_attributes>Hello
16
+ AsciiDoc</panel_attributes>
17
+ <additional_attributes/>
18
+ </element>
19
+ </diagram>
20
+ eos
21
+
22
+
23
+ describe Asciidoctor::Diagram::UmletBlockMacroProcessor do
24
+ it "should generate SVG images when format omitted" do
25
+ File.write('umlet.uxf', code)
26
+
27
+ doc = <<-eos
28
+ = Hello, Umlet!
29
+ Doc Writer <doc@example.com>
30
+
31
+ == First Section
32
+
33
+ umlet::umlet.uxf[]
34
+ eos
35
+
36
+ d = load_asciidoc doc
37
+ expect(d).to_not be_nil
38
+
39
+ b = d.find { |bl| bl.context == :image }
40
+ expect(b).to_not be_nil
41
+
42
+ expect(b.content_model).to eq :empty
43
+
44
+ target = b.attributes['target']
45
+ expect(target).to_not be_nil
46
+ expect(target).to match(/\.svg$/)
47
+ expect(File.exist?(target)).to be true
48
+
49
+ expect(b.attributes['width']).to_not be_nil
50
+ expect(b.attributes['height']).to_not be_nil
51
+ end
52
+ end
53
+
54
+
55
+ describe Asciidoctor::Diagram::UmletBlockProcessor do
56
+ it "should generate SVG images when format is omitted" do
57
+ doc = <<-eos
58
+ = Hello, Umlet!
59
+ Doc Writer <doc@example.com>
60
+
61
+ == First Section
62
+
63
+ [umlet]
64
+ ----
65
+ #{code}
66
+ ----
67
+ eos
68
+
69
+ d = load_asciidoc doc
70
+ expect(d).to_not be_nil
71
+
72
+ b = d.find { |bl| bl.context == :image }
73
+ expect(b).to_not be_nil
74
+
75
+ expect(b.content_model).to eq :empty
76
+
77
+ target = b.attributes['target']
78
+ expect(target).to_not be_nil
79
+ expect(target).to match(/\.svg$/)
80
+ expect(File.exist?(target)).to be true
81
+
82
+ expect(b.attributes['width']).to_not be_nil
83
+ expect(b.attributes['height']).to_not be_nil
84
+ end
85
+ end
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.4
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-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -104,6 +104,8 @@ files:
104
104
  - lib/asciidoctor-diagram/salt.rb
105
105
  - lib/asciidoctor-diagram/shaape.rb
106
106
  - lib/asciidoctor-diagram/shaape/extension.rb
107
+ - lib/asciidoctor-diagram/umlet.rb
108
+ - lib/asciidoctor-diagram/umlet/extension.rb
107
109
  - lib/asciidoctor-diagram/util/binaryio.rb
108
110
  - lib/asciidoctor-diagram/util/cli.rb
109
111
  - lib/asciidoctor-diagram/util/cli_generator.rb
@@ -111,6 +113,7 @@ files:
111
113
  - lib/asciidoctor-diagram/util/java.rb
112
114
  - lib/asciidoctor-diagram/util/java_jruby.rb
113
115
  - lib/asciidoctor-diagram/util/java_socket.rb
116
+ - lib/asciidoctor-diagram/util/pdf.rb
114
117
  - lib/asciidoctor-diagram/util/platform.rb
115
118
  - lib/asciidoctor-diagram/util/png.rb
116
119
  - lib/asciidoctor-diagram/util/svg.rb
@@ -130,6 +133,7 @@ files:
130
133
  - spec/plantuml_spec.rb
131
134
  - spec/shaape_spec.rb
132
135
  - spec/test_helper.rb
136
+ - spec/umlet_spec.rb
133
137
  - spec/wavedrom_spec.rb
134
138
  homepage: https://github.com/asciidoctor/asciidoctor-diagram
135
139
  licenses:
@@ -167,4 +171,5 @@ test_files:
167
171
  - spec/plantuml_spec.rb
168
172
  - spec/shaape_spec.rb
169
173
  - spec/test_helper.rb
174
+ - spec/umlet_spec.rb
170
175
  - spec/wavedrom_spec.rb