asciidoctor-diagram 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +77 -1
- data/README.adoc +25 -483
- data/Rakefile +1 -1
- data/docs/antora.yml +3 -0
- data/{images → docs/modules/ROOT/images}/asciidoctor-diagram-classes.png +0 -0
- data/docs/modules/ROOT/images/asciidoctor-diagram-process.png +0 -0
- data/docs/modules/ROOT/pages/index.adoc +21 -0
- data/docs/modules/ROOT/partials/advanced.adoc +303 -0
- data/docs/modules/ROOT/partials/create_diagram.adoc +131 -0
- data/docs/modules/ROOT/partials/generate.adoc +15 -0
- data/docs/modules/ROOT/partials/installation.adoc +19 -0
- data/docs/modules/ROOT/partials/uris.adoc +38 -0
- data/examples/features.adoc +1 -1
- data/lib/asciidoctor-diagram.rb +4 -0
- data/lib/asciidoctor-diagram/a2s/converter.rb +10 -6
- data/lib/asciidoctor-diagram/blockdiag/converter.rb +1 -1
- data/lib/asciidoctor-diagram/bpmn/converter.rb +4 -4
- data/lib/asciidoctor-diagram/bytefield.rb +7 -0
- data/lib/asciidoctor-diagram/bytefield/converter.rb +26 -0
- data/lib/asciidoctor-diagram/bytefield/extension.rb +14 -0
- data/lib/asciidoctor-diagram/diagram_converter.rb +5 -1
- data/lib/asciidoctor-diagram/diagram_processor.rb +106 -51
- data/lib/asciidoctor-diagram/diagram_source.rb +66 -19
- data/lib/asciidoctor-diagram/ditaa/converter.rb +20 -7
- data/lib/asciidoctor-diagram/ditaa/ditaa-1.3.17.jar +0 -0
- data/lib/asciidoctor-diagram/dpic.rb +7 -0
- data/lib/asciidoctor-diagram/dpic/converter.rb +30 -0
- data/lib/asciidoctor-diagram/dpic/extension.rb +14 -0
- data/lib/asciidoctor-diagram/gnuplot/converter.rb +8 -8
- data/lib/asciidoctor-diagram/graphviz/converter.rb +2 -2
- data/lib/asciidoctor-diagram/http/converter.rb +93 -0
- data/lib/asciidoctor-diagram/http/server.rb +10 -5
- data/lib/asciidoctor-diagram/lilypond/converter.rb +13 -3
- data/lib/asciidoctor-diagram/meme/converter.rb +24 -18
- data/lib/asciidoctor-diagram/mermaid/converter.rb +45 -14
- data/lib/asciidoctor-diagram/msc/converter.rb +2 -2
- data/lib/asciidoctor-diagram/pikchr.rb +7 -0
- data/lib/asciidoctor-diagram/pikchr/converter.rb +33 -0
- data/lib/asciidoctor-diagram/pikchr/extension.rb +14 -0
- data/lib/asciidoctor-diagram/plantuml/converter.rb +22 -14
- data/lib/asciidoctor-diagram/plantuml/plantuml-1.3.17.jar +0 -0
- data/lib/asciidoctor-diagram/smcat/converter.rb +3 -3
- data/lib/asciidoctor-diagram/svgbob/converter.rb +29 -1
- data/lib/asciidoctor-diagram/symbolator.rb +7 -0
- data/lib/asciidoctor-diagram/symbolator/converter.rb +23 -0
- data/lib/asciidoctor-diagram/symbolator/extension.rb +14 -0
- data/lib/asciidoctor-diagram/syntrax/converter.rb +9 -6
- data/lib/asciidoctor-diagram/tikz/converter.rb +20 -1
- data/lib/asciidoctor-diagram/umlet/converter.rb +11 -2
- data/lib/asciidoctor-diagram/util/cli.rb +29 -3
- data/lib/asciidoctor-diagram/util/cli_generator.rb +22 -2
- data/lib/asciidoctor-diagram/util/gif.rb +2 -2
- data/lib/asciidoctor-diagram/util/java.rb +118 -3
- data/lib/asciidoctor-diagram/util/java_jruby.rb +4 -1
- data/lib/asciidoctor-diagram/util/java_socket.rb +9 -110
- data/lib/asciidoctor-diagram/util/pdf.rb +2 -2
- data/lib/asciidoctor-diagram/util/png.rb +2 -2
- data/lib/{server-1.3.14.jar → asciidoctor-diagram/util/server-1.3.17.jar} +0 -0
- data/lib/asciidoctor-diagram/util/svg.rb +66 -18
- data/lib/asciidoctor-diagram/vega/converter.rb +2 -2
- data/lib/asciidoctor-diagram/version.rb +1 -1
- data/spec/a2s_spec.rb +5 -143
- data/spec/blockdiag_spec.rb +5 -203
- data/spec/bpmn_spec.rb +52 -92
- data/spec/bytefield_spec.rb +92 -0
- data/spec/ditaa_spec.rb +37 -143
- data/spec/dpic_spec.rb +19 -0
- data/spec/erd_spec.rb +5 -202
- data/spec/gnuplot_spec.rb +2 -255
- data/spec/graphviz_spec.rb +6 -145
- data/spec/lilypond_spec.rb +5 -143
- data/spec/mermaid_spec.rb +68 -210
- data/spec/msc_spec.rb +2 -199
- data/spec/nomnoml_spec.rb +4 -142
- data/spec/pikchr_spec.rb +69 -0
- data/spec/plantuml_spec.rb +6 -578
- data/spec/shaape_spec.rb +12 -224
- data/spec/shared_examples.rb +603 -0
- data/spec/smcat_spec.rb +2 -140
- data/spec/svgbob_spec.rb +5 -143
- data/spec/symbolator_spec.rb +23 -0
- data/spec/syntrax_spec.rb +7 -217
- data/spec/test_helper.rb +4 -28
- data/spec/tikz_spec.rb +68 -18
- data/spec/umlet_spec.rb +2 -58
- data/spec/vega_spec.rb +4 -117
- data/spec/wavedrom_spec.rb +2 -199
- metadata +80 -15
- data/README_zh-CN.adoc +0 -336
- data/images/asciidoctor-diagram-process.png +0 -0
- data/lib/batik-all-1.10.jar +0 -0
- data/lib/ditaa-1.3.14.jar +0 -0
- data/lib/ditaamini-0.12.jar +0 -0
- data/lib/jlatexmath-minimal-1.0.5.jar +0 -0
- data/lib/plantuml-1.3.14.jar +0 -0
- data/lib/plantuml.jar +0 -0
- data/spec/bpmn-example.xml +0 -44
@@ -0,0 +1,15 @@
|
|
1
|
+
== Generating a Diagram from a Terminal
|
2
|
+
|
3
|
+
You can load Asciidoctor diagram in a terminal using the `-r` flag.
|
4
|
+
|
5
|
+
$ asciidoctor -r asciidoctor-diagram sample.adoc
|
6
|
+
|
7
|
+
You can also use Asciidoctor diagram with other converters, such as Asciidoctor EPUB.
|
8
|
+
Asciidoctor-epub3 is also loaded with the `-r` flag.
|
9
|
+
|
10
|
+
$ asciidoctor -r asciidoctor-diagram -r asciidoctor-epub3 -b epub3 sample.adoc
|
11
|
+
|
12
|
+
Or, you can invoke Asciidoctor and the EPUB converter with the `asciidoctor-epub3` command.
|
13
|
+
The command implicitly sets the `-r` and `-b` flags for EPUB3 output.
|
14
|
+
|
15
|
+
$ asciidoctor-epub3 -r asciidoctor-diagram sample.adoc
|
@@ -0,0 +1,19 @@
|
|
1
|
+
== Installation
|
2
|
+
|
3
|
+
Asciidoctor Diagram is a RubyGem, which can be installed using the `gem` or `bundle` commands.
|
4
|
+
|
5
|
+
You can install the Asciidoctor Diagram gem by typing `gem install` in the CLI.
|
6
|
+
|
7
|
+
$ gem install asciidoctor-diagram
|
8
|
+
|
9
|
+
by first adding the following entry to your project's [.path]_Gemfile_.
|
10
|
+
|
11
|
+
.Gemfile
|
12
|
+
[source,ruby]
|
13
|
+
----
|
14
|
+
gem 'asciidoctor-diagram'
|
15
|
+
----
|
16
|
+
|
17
|
+
Then execute `bundle` in the CLI.
|
18
|
+
|
19
|
+
$ bundle
|
@@ -0,0 +1,38 @@
|
|
1
|
+
:uri-a2s: https://github.com/dhobsd/asciitosvg
|
2
|
+
:uri-actdiag: http://blockdiag.com/en/actdiag/index.html
|
3
|
+
:uri-asciidoctor-api: http://asciidoctor.org/docs/user-manual/#api
|
4
|
+
:uri-asciidoctor-extensions: http://asciidoctor.org/docs/user-manual/#extension-points
|
5
|
+
:uri-blockdiag: http://blockdiag.com
|
6
|
+
:uri-bpmn: https://github.com/gtudan/bpmn-js-cmd
|
7
|
+
:uri-bytefield: https://github.com/Deep-Symmetry/bytefield-svg
|
8
|
+
:uri-ditaa: http://ditaa.sourceforge.net/
|
9
|
+
:uri-dpic: https://gitlab.com/aplevich/dpic
|
10
|
+
:uri-dot: https://graphviz.gitlab.io/_pages/doc/info/lang.html
|
11
|
+
:uri-erd: https://github.com/BurntSushi/erd
|
12
|
+
:uri-gnuplot: http://gnuplot.info
|
13
|
+
:uri-graphviz: https://graphviz.gitlab.io
|
14
|
+
:uri-imagemagick: http://www.imagemagick.org
|
15
|
+
:uri-java: http://java.sun.com
|
16
|
+
:uri-mermaid: https://github.com/mermaid-js/mermaid-cli
|
17
|
+
:uri-mscgen: http://www.mcternan.me.uk/mscgen/
|
18
|
+
:uri-nomnoml: http://nomnoml.com
|
19
|
+
:uri-nwdiag: http://blockdiag.com/en/nwdiag/index.html
|
20
|
+
:uri-packetdiag: http://blockdiag.com/en/nwdiag/index.html
|
21
|
+
:uri-phantomjs: http://phantomjs.org
|
22
|
+
:uri-pikchr: https://pikchr.org
|
23
|
+
:uri-plantuml: http://plantuml.sourceforge.net
|
24
|
+
:uri-py-plantuml: https://code.google.com/p/asciidoc-plantuml/
|
25
|
+
:uri-rackdiag: http://blockdiag.com/en/nwdiag/index.html
|
26
|
+
:uri-seqdiag: http://blockdiag.com/en/seqdiag/index.html
|
27
|
+
:uri-shaape: https://github.com/christiangoltz/shaape
|
28
|
+
:uri-smcat: https://github.com/sverweij/state-machine-cat
|
29
|
+
:uri-svgbob: https://github.com/ivanceras/svgbobrus
|
30
|
+
:uri-symbolator: https://github.com/kevinpt/symbolator
|
31
|
+
:uri-syntrax: https://kevinpt.github.io/syntrax/
|
32
|
+
:uri-tikz: https://github.com/pgf-tikz/pgf
|
33
|
+
:uri-umlet: http://www.umlet.com/
|
34
|
+
:uri-vega: https://vega.github.io/vega/
|
35
|
+
:uri-vegalite: https://vega.github.io/vega-lite/
|
36
|
+
:uri-wavedrom: http://wavedrom.com
|
37
|
+
:uri-wavedromeditor: https://github.com/wavedrom/wavedrom.github.io/releases
|
38
|
+
:uri-wavedromcli: https://github.com/wavedrom/cli
|
data/examples/features.adoc
CHANGED
@@ -150,7 +150,7 @@ results in a block with the correct caption and id applied to it.
|
|
150
150
|
Asciidoctor-diagram also supports the various diagram block in block macro form.
|
151
151
|
These are macros of the form `<name>::<target>[<attrlist>]`.
|
152
152
|
|
153
|
-
In asciidoctor-diagram the macro names are identical to the block styles: `ditaa`, `
|
153
|
+
In asciidoctor-diagram the macro names are identical to the block styles: `ditaa`, `graphviz` and `plantuml`
|
154
154
|
The target is the path to the file containing the diagram source code.
|
155
155
|
When the target is a relative path it is resolved with respect to the location of the document being processed.
|
156
156
|
The attribute list behaves mostly the same as with the block styles.
|
data/lib/asciidoctor-diagram.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require_relative 'asciidoctor-diagram/a2s'
|
2
2
|
require_relative 'asciidoctor-diagram/blockdiag'
|
3
3
|
require_relative 'asciidoctor-diagram/bpmn'
|
4
|
+
require_relative 'asciidoctor-diagram/bytefield'
|
4
5
|
require_relative 'asciidoctor-diagram/ditaa'
|
6
|
+
require_relative 'asciidoctor-diagram/dpic'
|
5
7
|
require_relative 'asciidoctor-diagram/erd'
|
6
8
|
require_relative 'asciidoctor-diagram/gnuplot'
|
7
9
|
require_relative 'asciidoctor-diagram/graphviz'
|
@@ -10,11 +12,13 @@ require_relative 'asciidoctor-diagram/meme'
|
|
10
12
|
require_relative 'asciidoctor-diagram/mermaid'
|
11
13
|
require_relative 'asciidoctor-diagram/msc'
|
12
14
|
require_relative 'asciidoctor-diagram/nomnoml'
|
15
|
+
require_relative 'asciidoctor-diagram/pikchr'
|
13
16
|
require_relative 'asciidoctor-diagram/plantuml'
|
14
17
|
require_relative 'asciidoctor-diagram/salt'
|
15
18
|
require_relative 'asciidoctor-diagram/shaape'
|
16
19
|
require_relative 'asciidoctor-diagram/smcat'
|
17
20
|
require_relative 'asciidoctor-diagram/svgbob'
|
21
|
+
require_relative 'asciidoctor-diagram/symbolator'
|
18
22
|
require_relative 'asciidoctor-diagram/syntrax'
|
19
23
|
require_relative 'asciidoctor-diagram/tikz'
|
20
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
|
16
|
+
def collect_options(source)
|
17
17
|
options = {}
|
18
|
-
options[:sx] = source.attr('scalex'
|
19
|
-
options[:sy] = source.attr('scaley'
|
20
|
-
options[:scale] = source.attr('scale'
|
21
|
-
options[:noblur] = source.attr('noblur'
|
22
|
-
options[:font] = source.attr('fontfamily'
|
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'
|
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
|
18
|
+
def collect_options(source)
|
19
19
|
options = {}
|
20
20
|
|
21
|
-
options[:width] = source.attr('width'
|
22
|
-
options[:height] = source.attr('height'
|
21
|
+
options[:width] = source.attr('width')
|
22
|
+
options[:height] = source.attr('height')
|
23
23
|
|
24
24
|
options
|
25
25
|
end
|
@@ -29,7 +29,7 @@ module Asciidoctor
|
|
29
29
|
|
30
30
|
opts[:width] = options[:width]
|
31
31
|
|
32
|
-
bpmnjs = source.find_command('bpmn-js'
|
32
|
+
bpmnjs = source.find_command('bpmn-js')
|
33
33
|
opts[:height] = options[:height]
|
34
34
|
opts[:theme] = options[:theme]
|
35
35
|
config = options[:config]
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative '../diagram_converter'
|
2
|
+
require_relative '../util/cli_generator'
|
3
|
+
require_relative '../util/platform'
|
4
|
+
|
5
|
+
module Asciidoctor
|
6
|
+
module Diagram
|
7
|
+
# @private
|
8
|
+
class BytefieldConverter
|
9
|
+
include DiagramConverter
|
10
|
+
include CliGenerator
|
11
|
+
|
12
|
+
|
13
|
+
def supported_formats
|
14
|
+
[:svg]
|
15
|
+
end
|
16
|
+
|
17
|
+
def convert(source, format, options)
|
18
|
+
bytefield_path = source.find_command('bytefield-svg')
|
19
|
+
|
20
|
+
generate_stdin(bytefield_path, format.to_s, source.to_s) do |tool_path, output_path|
|
21
|
+
[tool_path, "--output", Platform.native_path(output_path)]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative 'converter'
|
2
|
+
require_relative '../diagram_processor'
|
3
|
+
|
4
|
+
module Asciidoctor
|
5
|
+
module Diagram
|
6
|
+
class BytefieldBlockProcessor < DiagramBlockProcessor
|
7
|
+
use_converter BytefieldConverter
|
8
|
+
end
|
9
|
+
|
10
|
+
class BytefieldBlockMacroProcessor < DiagramBlockMacroProcessor
|
11
|
+
use_converter BytefieldConverter
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -7,13 +7,17 @@ module Asciidoctor
|
|
7
7
|
raise NotImplementedError.new
|
8
8
|
end
|
9
9
|
|
10
|
-
def collect_options(source
|
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,7 +3,9 @@ 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'
|
8
|
+
require_relative 'http/converter'
|
7
9
|
require_relative 'version'
|
8
10
|
require_relative 'util/java'
|
9
11
|
require_relative 'util/gif'
|
@@ -66,7 +68,7 @@ module Asciidoctor
|
|
66
68
|
supported_formats = converter.supported_formats
|
67
69
|
|
68
70
|
begin
|
69
|
-
format = source.attributes.delete('format') || source.
|
71
|
+
format = source.attributes.delete('format') || source.global_attr('format', supported_formats[0])
|
70
72
|
format = format.to_sym if format.respond_to?(:to_sym)
|
71
73
|
|
72
74
|
raise "Format undefined" unless format
|
@@ -78,8 +80,8 @@ module Asciidoctor
|
|
78
80
|
caption = source.attributes.delete 'caption'
|
79
81
|
|
80
82
|
case format
|
81
|
-
when :txt
|
82
|
-
block = create_literal_block(parent, source, converter)
|
83
|
+
when :txt, :atxt, :utxt
|
84
|
+
block = create_literal_block(parent, source, format, converter)
|
83
85
|
else
|
84
86
|
block = create_image_block(parent, source, format, converter)
|
85
87
|
end
|
@@ -88,7 +90,7 @@ module Asciidoctor
|
|
88
90
|
block.assign_caption(caption, 'figure')
|
89
91
|
block
|
90
92
|
rescue => e
|
91
|
-
case source.
|
93
|
+
case source.global_attr('on-error', 'log')
|
92
94
|
when 'abort'
|
93
95
|
raise e
|
94
96
|
else
|
@@ -142,29 +144,38 @@ module Asciidoctor
|
|
142
144
|
|
143
145
|
def create_image_block(parent, source, format, converter)
|
144
146
|
image_name = "#{source.image_name}.#{format}"
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
metadata_file = parent.normalize_system_path "#{image_name}.cache", cache_dir
|
147
|
+
|
148
|
+
image_file = parent.normalize_system_path(image_name, image_output_dir(parent))
|
149
|
+
metadata_file = parent.normalize_system_path("#{image_name}.cache", cache_dir(source, parent))
|
149
150
|
|
150
151
|
if File.exist? metadata_file
|
151
|
-
metadata = File.open(metadata_file, 'r') {|f| JSON.load
|
152
|
+
metadata = File.open(metadata_file, 'r') {|f| JSON.load(f, nil, :symbolize_names => true, :create_additions => false) }
|
152
153
|
else
|
153
154
|
metadata = {}
|
154
155
|
end
|
155
156
|
|
156
157
|
image_attributes = source.attributes
|
158
|
+
options = converter.collect_options(source)
|
157
159
|
|
158
|
-
if !File.exist?(image_file) || source.should_process?(image_file, metadata)
|
160
|
+
if !File.exist?(image_file) || source.should_process?(image_file, metadata) || options != metadata[:options]
|
159
161
|
params = IMAGE_PARAMS[format]
|
160
162
|
|
161
|
-
|
163
|
+
server_url = source.global_attr('server-url')
|
164
|
+
if server_url
|
165
|
+
server_type = source.global_attr('server-type')
|
166
|
+
converter = HttpConverter.new(server_url, server_type.to_sym, converter)
|
167
|
+
end
|
168
|
+
|
169
|
+
options = converter.collect_options(source)
|
162
170
|
result = converter.convert(source, format, options)
|
163
171
|
|
164
172
|
result.force_encoding(params[:encoding])
|
165
173
|
|
166
174
|
metadata = source.create_image_metadata
|
167
|
-
metadata[
|
175
|
+
metadata[:options] = options
|
176
|
+
|
177
|
+
allow_image_optimisation = source.attr('optimise', 'true') == 'true'
|
178
|
+
result, metadata[:width], metadata[:height] = params[:decoder].post_process_image(result, allow_image_optimisation)
|
168
179
|
|
169
180
|
FileUtils.mkdir_p(File.dirname(image_file)) unless Dir.exist?(File.dirname(image_file))
|
170
181
|
File.open(image_file, 'wb') {|f| f.write result}
|
@@ -173,14 +184,8 @@ module Asciidoctor
|
|
173
184
|
File.open(metadata_file, 'w') {|f| JSON.dump(metadata, f)}
|
174
185
|
end
|
175
186
|
|
176
|
-
image_attributes['target'] = source.attr('data-uri', nil, true) ? image_file : image_name
|
177
|
-
if format == :svg
|
178
|
-
svg_type = source.attr('svg-type', nil, 'diagram')
|
179
|
-
image_attributes['opts'] = svg_type if svg_type && svg_type != 'static'
|
180
|
-
end
|
181
|
-
|
182
187
|
scale = image_attributes['scale']
|
183
|
-
if scalematch = /(
|
188
|
+
if !converter.native_scaling? && scalematch = /([0-9]+(?:\.[0-9]+)?)/.match(scale)
|
184
189
|
scale_factor = scalematch[1].to_f
|
185
190
|
else
|
186
191
|
scale_factor = 1.0
|
@@ -188,33 +193,66 @@ module Asciidoctor
|
|
188
193
|
|
189
194
|
if /html/i =~ parent.document.attributes['backend']
|
190
195
|
image_attributes.delete('scale')
|
191
|
-
if metadata[
|
192
|
-
image_attributes['width'] = (metadata[
|
196
|
+
if metadata[:width] && !image_attributes['width']
|
197
|
+
image_attributes['width'] = (metadata[:width] * scale_factor).to_i
|
193
198
|
end
|
194
|
-
if metadata[
|
195
|
-
image_attributes['height'] = (metadata[
|
199
|
+
if metadata[:height] && !image_attributes['height']
|
200
|
+
image_attributes['height'] = (metadata[:height] * scale_factor).to_i
|
196
201
|
end
|
197
202
|
end
|
198
203
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
(File.basename(target, File.extname(target)) || '').tr '_-', ' '
|
203
|
-
else
|
204
|
-
'Diagram'
|
205
|
-
end
|
204
|
+
parent.document.register(:images, image_name)
|
205
|
+
|
206
|
+
node = Asciidoctor::Block.new parent, :image, :content_model => :empty, :attributes => image_attributes
|
206
207
|
|
207
|
-
|
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)
|
208
217
|
|
209
|
-
|
210
|
-
|
218
|
+
node.set_attr('alt', alt_text)
|
219
|
+
|
220
|
+
if (scaledwidth = node.attr('scaledwidth'))
|
211
221
|
# append % to scaledwidth if ends in number (no units present)
|
212
222
|
if DIGIT_CHAR_RANGE.include?((scaledwidth[-1] || 0).ord)
|
213
|
-
|
223
|
+
node.set_attr('scaledwidth', %(#{scaledwidth}%))
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
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}"
|
214
238
|
end
|
215
239
|
end
|
216
240
|
|
217
|
-
|
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
|
+
image_path = Pathname.new(image_file)
|
248
|
+
output_path = Pathname.new(parent.normalize_system_path(output_dir(parent)))
|
249
|
+
|
250
|
+
imagesdir = image_path.relative_path_from(output_path).dirname.to_s
|
251
|
+
node.set_attr('imagesdir', imagesdir)
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
node
|
218
256
|
end
|
219
257
|
|
220
258
|
def scale(size, factor)
|
@@ -227,34 +265,51 @@ module Asciidoctor
|
|
227
265
|
end
|
228
266
|
end
|
229
267
|
|
268
|
+
# Returns the image output directory as an absolute path
|
230
269
|
def image_output_dir(parent)
|
231
|
-
|
270
|
+
images_out_dir = parent.attr('imagesoutdir', nil, true)
|
232
271
|
|
233
|
-
|
234
|
-
|
235
|
-
if images_dir
|
236
|
-
base_dir = nil
|
272
|
+
if images_out_dir
|
273
|
+
resolve_path(parent, images_out_dir)
|
237
274
|
else
|
238
|
-
base_dir = parent.attr('outdir', nil, true) || doc_option(document, :to_dir)
|
239
275
|
images_dir = parent.attr('imagesdir', nil, true)
|
276
|
+
output_dir = output_dir(parent)
|
277
|
+
resolve_path(parent, images_dir, output_dir)
|
240
278
|
end
|
279
|
+
end
|
241
280
|
|
242
|
-
|
281
|
+
# Returns the cache directory as an absolute path
|
282
|
+
def cache_dir(source, parent)
|
283
|
+
cache_dir = source.global_attr('cachedir')
|
284
|
+
if cache_dir
|
285
|
+
resolve_path(parent, cache_dir)
|
286
|
+
else
|
287
|
+
output_dir = output_dir(parent)
|
288
|
+
resolve_path(parent, '.asciidoctor/diagram', output_dir)
|
289
|
+
end
|
243
290
|
end
|
244
291
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
base_dir = parent.attr('outdir', nil, true) || doc_option(document, :to_dir)
|
249
|
-
parent.normalize_system_path(cache_dir, base_dir)
|
292
|
+
# Returns the general output directory for Asciidoctor as an absolute path
|
293
|
+
def output_dir(parent)
|
294
|
+
resolve_path(parent, parent.attr('outdir', nil, true) || doc_option(parent.document, :to_dir))
|
250
295
|
end
|
251
296
|
|
252
|
-
def
|
297
|
+
def resolve_path(parent, path, base_dir = nil)
|
298
|
+
if path.nil?
|
299
|
+
# Resolve the base dir itself
|
300
|
+
parent.document.path_resolver.system_path(base_dir)
|
301
|
+
else
|
302
|
+
# Resolve the path with respect to the base dir
|
303
|
+
parent.document.path_resolver.system_path(path, base_dir)
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
def create_literal_block(parent, source, format, converter)
|
253
308
|
literal_attributes = source.attributes
|
254
309
|
literal_attributes.delete('target')
|
255
310
|
|
256
|
-
options = converter.collect_options(source
|
257
|
-
result = converter.convert(source,
|
311
|
+
options = converter.collect_options(source)
|
312
|
+
result = converter.convert(source, format, options)
|
258
313
|
|
259
314
|
result.force_encoding(Encoding::UTF_8)
|
260
315
|
Asciidoctor::Block.new parent, :literal, :source => result, :attributes => literal_attributes
|
@@ -298,7 +353,7 @@ module Asciidoctor
|
|
298
353
|
include DiagramProcessor
|
299
354
|
|
300
355
|
def self.inherited(subclass)
|
301
|
-
subclass.name_positional_attributes ['
|
356
|
+
subclass.name_positional_attributes ['format']
|
302
357
|
end
|
303
358
|
|
304
359
|
def apply_target_subs(parent, target)
|