asciidoctor-diagram 2.0.2 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +25 -0
  3. data/README.adoc +13 -4
  4. data/lib/asciidoctor-diagram.rb +3 -0
  5. data/lib/asciidoctor-diagram/a2s/converter.rb +10 -6
  6. data/lib/asciidoctor-diagram/blockdiag/converter.rb +1 -1
  7. data/lib/asciidoctor-diagram/bpmn/converter.rb +3 -3
  8. data/lib/asciidoctor-diagram/diagram_converter.rb +5 -1
  9. data/lib/asciidoctor-diagram/diagram_processor.rb +64 -38
  10. data/lib/asciidoctor-diagram/diagram_source.rb +64 -17
  11. data/lib/asciidoctor-diagram/ditaa/converter.rb +6 -2
  12. data/lib/asciidoctor-diagram/dpic.rb +7 -0
  13. data/lib/asciidoctor-diagram/dpic/converter.rb +30 -0
  14. data/lib/asciidoctor-diagram/dpic/extension.rb +14 -0
  15. data/lib/asciidoctor-diagram/gnuplot/converter.rb +8 -8
  16. data/lib/asciidoctor-diagram/graphviz/converter.rb +2 -2
  17. data/lib/asciidoctor-diagram/http/converter.rb +25 -5
  18. data/lib/asciidoctor-diagram/http/server.rb +10 -5
  19. data/lib/asciidoctor-diagram/lilypond/converter.rb +2 -2
  20. data/lib/asciidoctor-diagram/meme/converter.rb +7 -7
  21. data/lib/asciidoctor-diagram/mermaid/converter.rb +16 -15
  22. data/lib/asciidoctor-diagram/msc/converter.rb +2 -2
  23. data/lib/asciidoctor-diagram/pikchr.rb +7 -0
  24. data/lib/asciidoctor-diagram/pikchr/converter.rb +26 -0
  25. data/lib/asciidoctor-diagram/pikchr/extension.rb +14 -0
  26. data/lib/asciidoctor-diagram/plantuml/converter.rb +3 -3
  27. data/lib/asciidoctor-diagram/smcat/converter.rb +3 -3
  28. data/lib/asciidoctor-diagram/svgbob/converter.rb +2 -2
  29. data/lib/asciidoctor-diagram/symbolator.rb +7 -0
  30. data/lib/asciidoctor-diagram/symbolator/converter.rb +23 -0
  31. data/lib/asciidoctor-diagram/symbolator/extension.rb +14 -0
  32. data/lib/asciidoctor-diagram/syntrax/converter.rb +9 -6
  33. data/lib/asciidoctor-diagram/util/cli_generator.rb +18 -0
  34. data/lib/asciidoctor-diagram/util/gif.rb +2 -2
  35. data/lib/asciidoctor-diagram/util/pdf.rb +2 -2
  36. data/lib/asciidoctor-diagram/util/png.rb +2 -2
  37. data/lib/asciidoctor-diagram/util/svg.rb +46 -19
  38. data/lib/asciidoctor-diagram/vega/converter.rb +2 -2
  39. data/lib/asciidoctor-diagram/version.rb +1 -1
  40. data/spec/a2s_spec.rb +2 -140
  41. data/spec/blockdiag_spec.rb +2 -200
  42. data/spec/bpmn_spec.rb +52 -92
  43. data/spec/bytefield_spec.rb +2 -140
  44. data/spec/ditaa_spec.rb +5 -143
  45. data/spec/dpic_spec.rb +19 -0
  46. data/spec/erd_spec.rb +2 -199
  47. data/spec/gnuplot_spec.rb +2 -255
  48. data/spec/graphviz_spec.rb +6 -145
  49. data/spec/lilypond_spec.rb +2 -140
  50. data/spec/mermaid_spec.rb +2 -199
  51. data/spec/msc_spec.rb +2 -199
  52. data/spec/nomnoml_spec.rb +4 -142
  53. data/spec/pikchr_spec.rb +51 -0
  54. data/spec/plantuml_spec.rb +6 -578
  55. data/spec/shaape_spec.rb +9 -221
  56. data/spec/shared_examples.rb +552 -0
  57. data/spec/smcat_spec.rb +2 -140
  58. data/spec/svgbob_spec.rb +2 -140
  59. data/spec/symbolator_spec.rb +23 -0
  60. data/spec/syntrax_spec.rb +5 -215
  61. data/spec/test_helper.rb +1 -22
  62. data/spec/tikz_spec.rb +4 -24
  63. data/spec/umlet_spec.rb +2 -58
  64. data/spec/vega_spec.rb +4 -117
  65. data/spec/wavedrom_spec.rb +2 -199
  66. metadata +20 -6
  67. data/spec/bpmn-example.xml +0 -44
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09488e585ecab52e38188d04020d60aa17873bea47c3043055f8f59770f9d1aa'
4
- data.tar.gz: ab9eab53cc00fc988ccd4518ac62e91f815ea06cfc3d3615824a24d63efb07a7
3
+ metadata.gz: 6929d068c82dc319a53dbcbc30da263e8356923fe2f92e6c4794f166c61b0252
4
+ data.tar.gz: 15b20dbe24d572cf174114d3e7cfa6146aa8bb7d46403de6c08284f6819d6e15
5
5
  SHA512:
6
- metadata.gz: 7e75194b60961b932b7ca141448948c92404db4557b83611c28786de97fb7b36e30d434189815729a4aab79620dd6a1e90d7eb0281c1a5a3a66356730f319892
7
- data.tar.gz: d7b8c2f8d8678e6299dd309292cc524d704830d6a882ae9228620d466862f0e37c9b1540a57090641f04f3499fcfcbf46f08933febfaa0dbb15579d33c3d1c64
6
+ metadata.gz: 04bec237f4f0529bd12324a1794bb0cd863a82ec27b867572e0f14ff93dbbce4e1e553e48f43fe04fbf1c31cf9af6eaab4e5b7933fb6b820988eade9031653d4
7
+ data.tar.gz: 392c0d5e97b6527bb21019f146732a8028681362c5dc19c8c572b2dc06a2c1f528a06d9d3236e292c8166f9acca3be1892bcb35eb0591a3e1c4a40ce10ff9e06
@@ -1,5 +1,30 @@
1
1
  = Asciidoctor-diagram Changelog
2
2
 
3
+ == 2.0.4
4
+
5
+ Enhancements::
6
+
7
+ * Issue #110: Added support for an experimental attribute `diagram-autoimagesdir` that sets per image node `imagesdir` values.
8
+
9
+ Bug Fixes::
10
+
11
+ * Issue #292: A regression in 2.0.3 caused SVG diagrams to get a zero width and height when documents were regenerated.
12
+
13
+ == 2.0.3
14
+
15
+ Enhancements::
16
+
17
+ * Issue #261: Ensure generated SVG diagrams always specify a view box
18
+ * Issue #284: Add support for HTTP redirect responses when using a rendering server
19
+ * Issue #290: Add support for Pikchr
20
+ * Add support for dpic
21
+ * Add support for Symboloator (@gsmecher)
22
+
23
+ Bug Fixes::
24
+
25
+ * Issue #247: Fix `svg-type`/`diagram-svg-type`.
26
+ * Issue #257: Avoid potential hangs when generating Mermaid diagrams
27
+
3
28
  == 2.0.2
4
29
 
5
30
  Enhancements::
@@ -21,18 +21,20 @@ ifndef::env-site[:status:]
21
21
  :uri-bpmn: https://github.com/gtudan/bpmn-js-cmd
22
22
  :uri-bytefield: https://github.com/Deep-Symmetry/bytefield-svg
23
23
  :uri-ditaa: http://ditaa.sourceforge.net/
24
+ :uri-dpic: https://gitlab.com/aplevich/dpic
24
25
  :uri-dot: https://graphviz.gitlab.io/_pages/doc/info/lang.html
25
26
  :uri-erd: https://github.com/BurntSushi/erd
26
27
  :uri-gnuplot: http://gnuplot.info
27
28
  :uri-graphviz: https://graphviz.gitlab.io
28
29
  :uri-imagemagick: http://www.imagemagick.org
29
30
  :uri-java: http://java.sun.com
30
- :uri-mermaid: https://github.com/mermaidjs/mermaid.cli
31
+ :uri-mermaid: https://github.com/mermaid-js/mermaid-cli
31
32
  :uri-mscgen: http://www.mcternan.me.uk/mscgen/
32
33
  :uri-nomnoml: http://nomnoml.com
33
34
  :uri-nwdiag: http://blockdiag.com/en/nwdiag/index.html
34
35
  :uri-packetdiag: http://blockdiag.com/en/nwdiag/index.html
35
36
  :uri-phantomjs: http://phantomjs.org
37
+ :uri-pikchr: https://pikchr.org
36
38
  :uri-plantuml: http://plantuml.sourceforge.net
37
39
  :uri-py-plantuml: https://code.google.com/p/asciidoc-plantuml/
38
40
  :uri-rackdiag: http://blockdiag.com/en/nwdiag/index.html
@@ -40,6 +42,7 @@ ifndef::env-site[:status:]
40
42
  :uri-shaape: https://github.com/christiangoltz/shaape
41
43
  :uri-smcat: https://github.com/sverweij/state-machine-cat
42
44
  :uri-svgbob: https://github.com/ivanceras/svgbobrus
45
+ :uri-symbolator: https://github.com/kevinpt/symbolator
43
46
  :uri-syntrax: https://kevinpt.github.io/syntrax/
44
47
  :uri-umlet: http://www.umlet.com/
45
48
  :uri-vega: https://vega.github.io/vega/
@@ -50,7 +53,7 @@ ifndef::env-site[:status:]
50
53
 
51
54
  Asciidoctor Diagram is a set of Asciidoctor extensions that enable you to add diagrams, which you describe using plain text, to your AsciiDoc document.
52
55
 
53
- The extensions supports the {uri-a2s}[AsciiToSVG], BlockDiag ({uri-blockdiag}[BlockDiag], {uri-seqdiag}[SeqDiag], {uri-actdiag}[ActDiag], {uri-nwdiag}[NwDiag]), {uri-bytefield}[Bytefield-SVG], {uri-ditaa}[Ditaa], {uri-erd}[Erd], {uri-gnuplot}[Gnuplot], {uri-dot}[GraphViz], {uri-mermaid}[Mermaid], {uri-mscgen}[Msc], {uri-nomnoml}[Nomnoml], {uri-plantuml}[PlantUML], {uri-shaape}[Shaape], {uri-smcat}[State Machine Cat], {uri-svgbob}[SvgBob], {uri-syntrax}[Syntrax], {uri-umlet}[UMLet], {uri-vega}[Vega], {uri-vegalite}[Vega-Lite] and {uri-wavedrom}[WaveDrom] syntax.
56
+ The extensions supports the {uri-a2s}[AsciiToSVG], BlockDiag ({uri-blockdiag}[BlockDiag], {uri-seqdiag}[SeqDiag], {uri-actdiag}[ActDiag], {uri-nwdiag}[NwDiag]), {uri-bytefield}[Bytefield-SVG], {uri-ditaa}[Ditaa], {uri-dpic}[dpic], {uri-erd}[Erd], {uri-gnuplot}[Gnuplot], {uri-dot}[GraphViz], {uri-mermaid}[Mermaid], {uri-mscgen}[Msc], {uri-nomnoml}[Nomnoml], {uri-pikchr}[Pikchr], {uri-plantuml}[PlantUML], {uri-shaape}[Shaape], {uri-smcat}[State Machine Cat], {uri-svgbob}[SvgBob], {uri-symbolator}[Symbolator], {uri-syntrax}[Syntrax], {uri-umlet}[UMLet], {uri-vega}[Vega], {uri-vegalite}[Vega-Lite] and {uri-wavedrom}[WaveDrom] syntax.
54
57
 
55
58
  Each extension runs the diagram processor to generate an SVG, PNG, or TXT file from the input text.
56
59
  The generated file is then inserted into your converted document.
@@ -126,6 +129,7 @@ The following diagram types and output formats are available:
126
129
  |{uri-bpmn}[bpmn] | |{check}|{check}|{check}|
127
130
  |{uri-bytefield}[bytefield] | | | |{check}|
128
131
  |{uri-ditaa}[ditaa] | | |{check}|{check}|
132
+ |{uri-dpic}[dpic] | | | |{check}|
129
133
  |{uri-erd}[erd] | | |{check}|{check}|
130
134
  |{uri-gnuplot}[gnuplot] |{check}| |{check}|{check}|{check}
131
135
  |{uri-dot}[graphviz] | |{check}|{check}|{check}|
@@ -135,12 +139,14 @@ The following diagram types and output formats are available:
135
139
  |{uri-nomnoml}[nomnoml] | | | |{check}|
136
140
  |{uri-nwdiag}[nwdiag] | |{check}|{check}|{check}|
137
141
  |{uri-packetdiag}[packetdiag]| |{check}|{check}|{check}|
142
+ |{uri-pikchr}[pikchr] | | | |{check}|
138
143
  |{uri-plantuml}[plantuml] | | |{check}|{check}|{check}
139
144
  |{uri-rackdiag}[rackdiag] | |{check}|{check}|{check}|
140
145
  |{uri-seqdiag}[seqdiag] | |{check}|{check}|{check}|
141
146
  |{uri-shaape}[shaape] | | |{check}|{check}|
142
147
  |{uri-smcat}[smcat] | | | |{check}|
143
148
  |{uri-svgbob}[svgbob] | | | |{check}|
149
+ |{uri-symbolator}[symbolator]| |{check}|{check}|{check}|
144
150
  |{uri-syntrax}[syntrax] | |{check}|{check}|{check}|
145
151
  |{uri-umlet}[umlet] |{check}|{check}|{check}|{check}|
146
152
  |{uri-vega}[vega] | | |{check}|{check}|
@@ -257,7 +263,7 @@ or load and register each extension individually.
257
263
  require 'asciidoctor-diagram/<extension_name>'
258
264
  ----
259
265
 
260
- `<extension_name>` can be one of `a2s`, `blockdiag`, `bytefield`, `ditaa`, `erd`, `gnuplot`, `graphviz`, `meme`, `mermaid`, `msc`, `plantuml`, `shaape`, `smcat`, `svgbob`, `syntrax`, `umlet`, `vega` or `wavedrom`.
266
+ `<extension_name>` can be one of `a2s`, `blockdiag`, `bytefield`, `ditaa`, `dpic`, `erd`, `gnuplot`, `graphviz`, `meme`, `mermaid`, `msc`, `pikchr`, `plantuml`, `shaape`, `smcat`, `svgbob`, `syntrax`, `umlet`, `vega` or `wavedrom`.
261
267
 
262
268
  Requiring one or more of these files will automatically register the extensions for all processed documents.
263
269
 
@@ -306,21 +312,24 @@ The following table lists the tools that are required for each diagram type, the
306
312
  |bpmn |{uri-bpmn}[bpmn-js-cmd] |`bpmn`
307
313
  |bytefield |{uri-bytefield}[bytefield-svg] |`bytefield-svg`
308
314
  |ditaa |{uri-java}[Java] |`java`
315
+ |dpic |{uri-dpic}[dpic] |`dpic`
309
316
  |erd |{uri-erd}[Erd] |`erd`
310
317
  |gnuplot |{uri-gnuplot}[Gnuplot] |`gnuplot`
311
318
  |graphviz |{uri-graphviz}[GraphViz] |`dot` or `graphvizdot`
312
319
  |meme |{uri-imagemagick}[ImageMagick] |`convert` and `identify`
313
- |mermaid |{uri-mermaid}[Mermaid.cli] |`mermaid`
320
+ |mermaid |{uri-mermaid}[Mermaid.cli] |`mmdc`
314
321
  |msc |{uri-mscgen}[Mscgen] |`mscgen`
315
322
  |nomnoml |{uri-nomnoml}[Nomnoml] |`nomnoml`
316
323
  |nwdiag |{uri-nwdiag}[NwDiag] |`nwdiag`
317
324
  |packetdiag |{uri-nwdiag}[NwDiag] |`packetdiag`
325
+ |pikchr |{uri-pikchr}[Pikchr] |`pikchr`
318
326
  |plantuml |{uri-java}[Java] |`java`
319
327
  |rackdiag |{uri-nwdiag}[NwDiag] |`rackdiag`
320
328
  |seqdiag |{uri-seqdiag}[SeqDiag] |`seqdiag`
321
329
  |shaape |{uri-shaape}[Shaape] |`shaape`
322
330
  |smcat |{uri-smcat}[State Machine Cat] |`smcat`
323
331
  |svgbob |{uri-svgbob}[SvgBob] |`svgbob`
332
+ |symbolator |{uri-symbolator}[Symbolator] |`symbolator`
324
333
  |syntrax |{uri-syntrax}[Syntrax] |`syntrax`
325
334
  |umlet |{uri-umlet}[Umlet] |`umlet`
326
335
  |vega |{uri-vega}[vg2png] and/or {uri-vega}[vg2png] |`vg2png` and `vg2svg`
@@ -3,6 +3,7 @@ require_relative 'asciidoctor-diagram/blockdiag'
3
3
  require_relative 'asciidoctor-diagram/bpmn'
4
4
  require_relative 'asciidoctor-diagram/bytefield'
5
5
  require_relative 'asciidoctor-diagram/ditaa'
6
+ require_relative 'asciidoctor-diagram/dpic'
6
7
  require_relative 'asciidoctor-diagram/erd'
7
8
  require_relative 'asciidoctor-diagram/gnuplot'
8
9
  require_relative 'asciidoctor-diagram/graphviz'
@@ -11,11 +12,13 @@ require_relative 'asciidoctor-diagram/meme'
11
12
  require_relative 'asciidoctor-diagram/mermaid'
12
13
  require_relative 'asciidoctor-diagram/msc'
13
14
  require_relative 'asciidoctor-diagram/nomnoml'
15
+ require_relative 'asciidoctor-diagram/pikchr'
14
16
  require_relative 'asciidoctor-diagram/plantuml'
15
17
  require_relative 'asciidoctor-diagram/salt'
16
18
  require_relative 'asciidoctor-diagram/shaape'
17
19
  require_relative 'asciidoctor-diagram/smcat'
18
20
  require_relative 'asciidoctor-diagram/svgbob'
21
+ require_relative 'asciidoctor-diagram/symbolator'
19
22
  require_relative 'asciidoctor-diagram/syntrax'
20
23
  require_relative 'asciidoctor-diagram/tikz'
21
24
  require_relative 'asciidoctor-diagram/umlet'
@@ -13,13 +13,13 @@ module Asciidoctor
13
13
  [:svg]
14
14
  end
15
15
 
16
- def collect_options(source, name)
16
+ def collect_options(source)
17
17
  options = {}
18
- options[:sx] = source.attr('scalex', nil, name)
19
- options[:sy] = source.attr('scaley', nil, name)
20
- options[:scale] = source.attr('scale', nil, name)
21
- options[:noblur] = source.attr('noblur', nil, name) == 'true'
22
- options[:font] = source.attr('fontfamily', nil, name)
18
+ options[:sx] = source.attr('scalex')
19
+ options[:sy] = source.attr('scaley')
20
+ options[:scale] = source.attr('scale')
21
+ options[:noblur] = source.attr('noblur') == 'true'
22
+ options[:font] = source.attr('fontfamily')
23
23
  options
24
24
  end
25
25
 
@@ -50,6 +50,10 @@ module Asciidoctor
50
50
  args
51
51
  end
52
52
  end
53
+
54
+ def native_scaling?
55
+ true
56
+ end
53
57
  end
54
58
  end
55
59
  end
@@ -19,7 +19,7 @@ module Asciidoctor
19
19
  cmd_name = self.class.const_get(:TOOL)
20
20
  alt_cmd_name = "#{cmd_name}3"
21
21
 
22
- font_path = source.attr('fontpath', nil, cmd_name)
22
+ font_path = source.attr('fontpath')
23
23
 
24
24
  generate_stdin(source.find_command(cmd_name, :alt_cmds => [alt_cmd_name]), format.to_s, source.to_s) do |tool_path, output_path|
25
25
  args = [tool_path, '-a', '-o', Platform.native_path(output_path), "-T#{format.to_s}"]
@@ -15,11 +15,11 @@ module Asciidoctor
15
15
  [:png, :svg, :pdf, :jpeg]
16
16
  end
17
17
 
18
- def collect_options(source, name)
18
+ def collect_options(source)
19
19
  options = {}
20
20
 
21
- options[:width] = source.attr('width', nil, name)
22
- options[:height] = source.attr('height', nil, name)
21
+ options[:width] = source.attr('width')
22
+ options[:height] = source.attr('height')
23
23
 
24
24
  options
25
25
  end
@@ -7,13 +7,17 @@ module Asciidoctor
7
7
  raise NotImplementedError.new
8
8
  end
9
9
 
10
- def collect_options(source, name)
10
+ def collect_options(source)
11
11
  {}
12
12
  end
13
13
 
14
14
  def convert(source, format, options)
15
15
  raise NotImplementedError.new
16
16
  end
17
+
18
+ def native_scaling?
19
+ false
20
+ end
17
21
  end
18
22
  end
19
23
  end
@@ -3,6 +3,7 @@ require 'asciidoctor/extensions'
3
3
  require 'digest'
4
4
  require 'json'
5
5
  require 'fileutils'
6
+ require 'pathname'
6
7
  require_relative 'diagram_source.rb'
7
8
  require_relative 'http/converter'
8
9
  require_relative 'version'
@@ -30,8 +31,6 @@ module Asciidoctor
30
31
  host_class.extend(ClassMethods)
31
32
  end
32
33
 
33
- DIAGRAM_PREFIX = 'diagram'
34
-
35
34
  IMAGE_PARAMS = {
36
35
  :svg => {
37
36
  :encoding => Encoding::UTF_8,
@@ -69,7 +68,7 @@ module Asciidoctor
69
68
  supported_formats = converter.supported_formats
70
69
 
71
70
  begin
72
- format = source.attributes.delete('format') || source.attr('format', nil, name) || source.attr('format', supported_formats[0], DIAGRAM_PREFIX)
71
+ format = source.attributes.delete('format') || source.global_attr('format', supported_formats[0])
73
72
  format = format.to_sym if format.respond_to?(:to_sym)
74
73
 
75
74
  raise "Format undefined" unless format
@@ -91,7 +90,7 @@ module Asciidoctor
91
90
  block.assign_caption(caption, 'figure')
92
91
  block
93
92
  rescue => e
94
- case source.attr('on-error', 'log', DIAGRAM_PREFIX)
93
+ case source.global_attr('on-error', 'log')
95
94
  when 'abort'
96
95
  raise e
97
96
  else
@@ -146,7 +145,7 @@ module Asciidoctor
146
145
  def create_image_block(parent, source, format, converter)
147
146
  image_name = "#{source.image_name}.#{format}"
148
147
  image_dir = image_output_dir(parent)
149
- cache_dir = cache_dir(parent)
148
+ cache_dir = cache_dir(source, parent)
150
149
  image_file = parent.normalize_system_path image_name, image_dir
151
150
  metadata_file = parent.normalize_system_path "#{image_name}.cache", cache_dir
152
151
 
@@ -157,25 +156,26 @@ module Asciidoctor
157
156
  end
158
157
 
159
158
  image_attributes = source.attributes
160
- options = converter.collect_options(source, name)
159
+ options = converter.collect_options(source)
161
160
 
162
161
  if !File.exist?(image_file) || source.should_process?(image_file, metadata) || options != metadata[:options]
163
162
  params = IMAGE_PARAMS[format]
164
163
 
165
- server_url = source.attr('server-url', nil, name) || source.attr('server-url', nil, DIAGRAM_PREFIX)
164
+ server_url = source.global_attr('server-url')
166
165
  if server_url
167
- server_type = source.attr('server-type', nil, name) || source.attr('server-type', 'plantuml', DIAGRAM_PREFIX)
166
+ server_type = source.global_attr('server-type')
168
167
  converter = HttpConverter.new(server_url, server_type.to_sym, converter)
169
168
  end
170
169
 
171
- options = converter.collect_options(source, name)
170
+ options = converter.collect_options(source)
172
171
  result = converter.convert(source, format, options)
173
172
 
174
173
  result.force_encoding(params[:encoding])
175
174
 
176
175
  metadata = source.create_image_metadata
177
176
  metadata[:options] = options
178
- metadata[:width], metadata[:height] = params[:decoder].get_image_size(result)
177
+
178
+ result, metadata[:width], metadata[:height] = params[:decoder].post_process_image(result)
179
179
 
180
180
  FileUtils.mkdir_p(File.dirname(image_file)) unless Dir.exist?(File.dirname(image_file))
181
181
  File.open(image_file, 'wb') {|f| f.write result}
@@ -184,14 +184,8 @@ module Asciidoctor
184
184
  File.open(metadata_file, 'w') {|f| JSON.dump(metadata, f)}
185
185
  end
186
186
 
187
- image_attributes['target'] = source.attr('data-uri', nil, true) ? image_file : image_name
188
- if format == :svg
189
- svg_type = source.attr('svg-type', nil, name) || source.attr('svg-type', nil, DIAGRAM_PREFIX)
190
- image_attributes['opts'] = svg_type if svg_type && svg_type != 'static'
191
- end
192
-
193
187
  scale = image_attributes['scale']
194
- if scalematch = /(\d+(?:\.\d+))/.match(scale)
188
+ if !converter.native_scaling? && scalematch = /(\d+(?:\.\d+))/.match(scale)
195
189
  scale_factor = scalematch[1].to_f
196
190
  else
197
191
  scale_factor = 1.0
@@ -207,25 +201,58 @@ module Asciidoctor
207
201
  end
208
202
  end
209
203
 
210
- image_attributes['alt'] ||= if title_text = image_attributes['title']
211
- title_text
212
- elsif target = image_attributes['target']
213
- (File.basename(target, File.extname(target)) || '').tr '_-', ' '
214
- else
215
- 'Diagram'
216
- end
204
+ parent.document.register(:images, image_name)
205
+
206
+ node = Asciidoctor::Block.new parent, :image, :content_model => :empty, :attributes => image_attributes
217
207
 
218
- image_attributes['alt'] = parent.sub_specialchars image_attributes['alt']
208
+ alt_text = node.attr('alt')
209
+ alt_text ||= if title_text = image_attributes['title']
210
+ title_text
211
+ elsif target = image_attributes['target']
212
+ (File.basename(target, File.extname(target)) || '').tr '_-', ' '
213
+ else
214
+ 'Diagram'
215
+ end
216
+ alt_text = parent.sub_specialchars(alt_text)
219
217
 
220
- parent.document.register(:images, image_name)
221
- if (scaledwidth = image_attributes['scaledwidth'])
218
+ node.set_attr('alt', alt_text)
219
+
220
+ if (scaledwidth = node.attr('scaledwidth'))
222
221
  # append % to scaledwidth if ends in number (no units present)
223
222
  if DIGIT_CHAR_RANGE.include?((scaledwidth[-1] || 0).ord)
224
- image_attributes['scaledwidth'] = %(#{scaledwidth}%)
223
+ node.set_attr('scaledwidth', %(#{scaledwidth}%))
225
224
  end
226
225
  end
227
226
 
228
- Asciidoctor::Block.new parent, :image, :content_model => :empty, :attributes => image_attributes
227
+ use_absolute_path = source.attr('data-uri', nil, true)
228
+
229
+ if format == :svg
230
+ svg_type = source.global_attr('svg-type')
231
+ case svg_type
232
+ when nil, 'static'
233
+ when 'inline', 'interactive'
234
+ node.set_option(svg_type)
235
+ use_absolute_path = true
236
+ else
237
+ raise "Unsupported SVG type: #{svg_type}"
238
+ end
239
+ end
240
+
241
+ if use_absolute_path
242
+ node.set_attr('target', image_file)
243
+ else
244
+ node.set_attr('target', image_name)
245
+
246
+ if source.global_attr('autoimagesdir')
247
+ output_base_dir = output_base_dir(parent)
248
+ if output_base_dir
249
+ imagesdir = Pathname.new(image_file).relative_path_from(output_base_dir).dirname.to_s
250
+ node.set_attr('imagesdir', imagesdir)
251
+ end
252
+ end
253
+ end
254
+
255
+ node
229
256
  end
230
257
 
231
258
  def scale(size, factor)
@@ -239,32 +266,31 @@ module Asciidoctor
239
266
  end
240
267
 
241
268
  def image_output_dir(parent)
242
- document = parent.document
243
-
244
269
  images_dir = parent.attr('imagesoutdir', nil, true)
245
270
 
246
271
  if images_dir
247
272
  base_dir = nil
248
273
  else
249
- base_dir = parent.attr('outdir', nil, true) || doc_option(document, :to_dir)
274
+ base_dir = output_base_dir(parent)
250
275
  images_dir = parent.attr('imagesdir', nil, true)
251
276
  end
252
277
 
253
278
  parent.normalize_system_path(images_dir, base_dir)
254
279
  end
255
280
 
256
- def cache_dir(parent)
257
- document = parent.document
258
- cache_dir = '.asciidoctor/diagram'
259
- base_dir = parent.attr('outdir', nil, true) || doc_option(document, :to_dir)
260
- parent.normalize_system_path(cache_dir, base_dir)
281
+ def output_base_dir(parent)
282
+ parent.normalize_system_path(parent.attr('outdir', nil, true) || doc_option(parent.document, :to_dir))
283
+ end
284
+
285
+ def cache_dir(source, parent)
286
+ source.global_attr('cachedir') || parent.normalize_system_path('.asciidoctor/diagram', output_base_dir(parent))
261
287
  end
262
288
 
263
289
  def create_literal_block(parent, source, format, converter)
264
290
  literal_attributes = source.attributes
265
291
  literal_attributes.delete('target')
266
292
 
267
- options = converter.collect_options(source, name)
293
+ options = converter.collect_options(source)
268
294
  result = converter.convert(source, format, options)
269
295
 
270
296
  result.force_encoding(Encoding::UTF_8)
@@ -1,3 +1,4 @@
1
+ require 'asciidoctor/logging'
1
2
  require_relative 'util/which'
2
3
 
3
4
  module Asciidoctor
@@ -5,6 +6,12 @@ module Asciidoctor
5
6
  # This module describes the duck-typed interface that diagram sources must implement. Implementations
6
7
  # may include this module but it is not required.
7
8
  module DiagramSource
9
+ include Asciidoctor::Logging
10
+
11
+ def diagram_type
12
+ raise NotImplementedError.new
13
+ end
14
+
8
15
  def image_name
9
16
  raise NotImplementedError.new
10
17
  end
@@ -15,20 +22,24 @@ module Asciidoctor
15
22
  raise NotImplementedError.new
16
23
  end
17
24
 
25
+ def global_attr(name, default_value = nil)
26
+ attr(name) || attr(name, default_value, 'diagram')
27
+ end
28
+
18
29
  # Get the value for the specified attribute. First look in the attributes on
19
30
  # this document and return the value of the attribute if found. Otherwise, if
20
31
  # this document is a child of the Document document, look in the attributes of the
21
32
  # Document document and return the value of the attribute if found. Otherwise,
22
33
  # return the default value, which defaults to nil.
23
34
  #
24
- # @param name [String, Symbol] the name of the attribute to lookup
35
+ # @param name [String, Symbol, Array] the name(s) of the attribute to lookup
25
36
  # @param default_value [Object] the value to return if the attribute is not found
26
37
  # @inherit [Boolean, String] indicates whether to check for the attribute on the AsciiDoctor::Document if not found on this document.
27
38
  # When a non-nil String is given the an attribute name "#{inherit}-#{name}" is looked for on the document.
28
39
  #
29
40
  # @return the value of the attribute or the default value if the attribute is not found in the attributes of this node or the document node
30
41
  # @abstract
31
- def attr(name, default_value = nil, inherit = nil)
42
+ def attr(name, default_value = nil, inherit = diagram_type)
32
43
  raise NotImplementedError.new
33
44
  end
34
45
 
@@ -75,14 +86,42 @@ module Asciidoctor
75
86
  if config.key? cmd_var
76
87
  cmd_path = config[cmd_var]
77
88
  else
78
- cmd_path = attr_names.map { |attr_name| attr(attr_name, nil, true) }.find { |attr| !attr.nil? }
79
-
80
- unless cmd_path && File.executable?(cmd_path)
81
- cmd_paths = cmd_names.map do |c|
82
- ::Asciidoctor::Diagram::Which.which(c, :path => options[:path])
83
- end
84
-
85
- cmd_path = cmd_paths.reject { |c| c.nil? }.first
89
+ logger.debug "Finding '#{cmd}' in attributes"
90
+ cmd_path = attr_names.map { |attr_name|
91
+ attr = attr(attr_name, nil, true)
92
+ if logger.debug? && attr
93
+ logger.debug "Found value '#{attr}' in attribute '#{attr_name}'" if attr
94
+ end
95
+ attr
96
+ }
97
+ .reject { |attr| attr.nil? }
98
+ .map { |attr|
99
+ expanded = File.expand_path(attr)
100
+ if logger.debug? && attr != expanded
101
+ logger.debug "Expanded '#{attr}' to '#{expanded}'"
102
+ end
103
+ expanded
104
+ }
105
+ .select { |path|
106
+ executable = File.executable?(path)
107
+ if logger.debug?
108
+ logger.debug "Is '#{path}' executable? #{executable}"
109
+ end
110
+ executable
111
+ }
112
+ .first
113
+
114
+ unless cmd_path
115
+ logger.debug "Finding '#{cmd}' in environment"
116
+ cmd_path = cmd_names.map { |c|
117
+ path = ::Asciidoctor::Diagram::Which.which(c, :path => options[:path])
118
+ if logger.debug? && path
119
+ logger.debug "Found '#{path}' in environment"
120
+ end
121
+ path
122
+ }
123
+ .reject { |path| path.nil? }
124
+ .first
86
125
  end
87
126
 
88
127
  config[cmd_var] = cmd_path
@@ -113,6 +152,10 @@ module Asciidoctor
113
152
  @attributes = attributes
114
153
  end
115
154
 
155
+ def diagram_type
156
+ @block_processor.name.downcase
157
+ end
158
+
116
159
  def resolve_path target, start = base_dir
117
160
  @parent_block.normalize_system_path(target, start)
118
161
  end
@@ -125,18 +168,22 @@ module Asciidoctor
125
168
  attr('target', 'diag-' + checksum)
126
169
  end
127
170
 
128
- def attr(name, default_value = nil, inherit = nil)
171
+ def attr(name, default_value = nil, inherit = diagram_type)
129
172
  name = name.to_s if ::Symbol === name
173
+ name = [name] unless name.is_a?(Enumerable)
130
174
 
131
- value = @attributes[name]
175
+ value = name.lazy.map { |n| @attributes[n] }.reject { |v| v.nil? }.first
132
176
 
133
177
  if value.nil? && inherit
134
- case inherit
135
- when String, Symbol
136
- value = @parent_block.attr("#{inherit.to_s}-#{name}", default_value, true)
137
- else
138
- value = @parent_block.attr(name, default_value, inherit)
178
+ inherited_values = name.lazy.map do |n|
179
+ case inherit
180
+ when String, Symbol
181
+ @parent_block.attr("#{inherit.to_s}-#{n}", default_value, true)
182
+ else
183
+ @parent_block.attr(n, default_value, inherit)
184
+ end
139
185
  end
186
+ value = inherited_values.reject { |v| v.nil? }.first
140
187
  end
141
188
 
142
189
  value || default_value