asciidoctor-diagram 2.0.5 → 2.2.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 +52 -2
- data/README.adoc +25 -516
- 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 +362 -0
- data/docs/modules/ROOT/partials/create_diagram.adoc +134 -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 +41 -0
- data/examples/features.adoc +1 -1
- data/lib/asciidoctor-diagram.rb +2 -0
- data/lib/asciidoctor-diagram/a2s.rb +1 -0
- data/lib/asciidoctor-diagram/a2s/extension.rb +4 -0
- data/lib/asciidoctor-diagram/barcode.rb +11 -0
- data/lib/asciidoctor-diagram/barcode/converter.rb +157 -0
- data/lib/asciidoctor-diagram/barcode/dependencies.rb +10 -0
- data/lib/asciidoctor-diagram/barcode/extension.rb +47 -0
- data/lib/asciidoctor-diagram/barcode/svg_outputter.rb +12 -0
- data/lib/asciidoctor-diagram/blockdiag.rb +1 -0
- data/lib/asciidoctor-diagram/blockdiag/extension.rb +5 -0
- data/lib/asciidoctor-diagram/bpmn.rb +1 -0
- data/lib/asciidoctor-diagram/bpmn/extension.rb +4 -0
- data/lib/asciidoctor-diagram/bytefield.rb +1 -0
- data/lib/asciidoctor-diagram/bytefield/extension.rb +4 -0
- data/lib/asciidoctor-diagram/diagram_converter.rb +4 -0
- data/lib/asciidoctor-diagram/diagram_processor.rb +55 -6
- data/lib/asciidoctor-diagram/diagram_source.rb +23 -7
- data/lib/asciidoctor-diagram/diagrams.rb +8 -0
- data/lib/asciidoctor-diagram/diagrams/converter.rb +49 -0
- data/lib/asciidoctor-diagram/diagrams/extension.rb +18 -0
- data/lib/asciidoctor-diagram/ditaa.rb +1 -0
- data/lib/asciidoctor-diagram/ditaa/converter.rb +14 -5
- data/lib/asciidoctor-diagram/ditaa/ditaa-1.3.20.jar +0 -0
- data/lib/asciidoctor-diagram/ditaa/extension.rb +4 -0
- data/lib/asciidoctor-diagram/dpic.rb +1 -0
- data/lib/asciidoctor-diagram/dpic/extension.rb +4 -0
- data/lib/asciidoctor-diagram/erd.rb +1 -0
- data/lib/asciidoctor-diagram/erd/extension.rb +4 -0
- data/lib/asciidoctor-diagram/gnuplot.rb +1 -0
- data/lib/asciidoctor-diagram/gnuplot/extension.rb +4 -0
- data/lib/asciidoctor-diagram/graphviz.rb +1 -0
- data/lib/asciidoctor-diagram/graphviz/extension.rb +4 -0
- data/lib/asciidoctor-diagram/http/converter.rb +34 -16
- data/lib/asciidoctor-diagram/http/server.rb +1 -1
- data/lib/asciidoctor-diagram/lilypond.rb +1 -0
- data/lib/asciidoctor-diagram/lilypond/converter.rb +11 -1
- data/lib/asciidoctor-diagram/lilypond/extension.rb +4 -0
- data/lib/asciidoctor-diagram/meme.rb +1 -0
- data/lib/asciidoctor-diagram/meme/converter.rb +15 -9
- data/lib/asciidoctor-diagram/meme/extension.rb +14 -16
- data/lib/asciidoctor-diagram/mermaid.rb +1 -0
- data/lib/asciidoctor-diagram/mermaid/converter.rb +27 -10
- data/lib/asciidoctor-diagram/mermaid/extension.rb +4 -0
- data/lib/asciidoctor-diagram/msc.rb +1 -0
- data/lib/asciidoctor-diagram/msc/extension.rb +4 -0
- data/lib/asciidoctor-diagram/nomnoml.rb +1 -0
- data/lib/asciidoctor-diagram/nomnoml/extension.rb +4 -0
- data/lib/asciidoctor-diagram/pikchr.rb +1 -0
- data/lib/asciidoctor-diagram/pikchr/converter.rb +8 -1
- data/lib/asciidoctor-diagram/pikchr/extension.rb +4 -0
- data/lib/asciidoctor-diagram/plantuml.rb +1 -0
- data/lib/asciidoctor-diagram/plantuml/converter.rb +67 -42
- data/lib/asciidoctor-diagram/plantuml/extension.rb +8 -0
- data/lib/asciidoctor-diagram/plantuml/plantuml-1.3.20.jar +0 -0
- data/lib/asciidoctor-diagram/salt.rb +1 -0
- data/lib/asciidoctor-diagram/shaape.rb +1 -0
- data/lib/asciidoctor-diagram/shaape/extension.rb +4 -0
- data/lib/asciidoctor-diagram/smcat.rb +1 -0
- data/lib/asciidoctor-diagram/smcat/extension.rb +4 -0
- data/lib/asciidoctor-diagram/svgbob.rb +1 -0
- data/lib/asciidoctor-diagram/svgbob/converter.rb +4 -0
- data/lib/asciidoctor-diagram/svgbob/extension.rb +4 -0
- data/lib/asciidoctor-diagram/symbolator.rb +1 -0
- data/lib/asciidoctor-diagram/symbolator/extension.rb +4 -0
- data/lib/asciidoctor-diagram/syntrax.rb +1 -0
- data/lib/asciidoctor-diagram/syntrax/converter.rb +1 -1
- data/lib/asciidoctor-diagram/syntrax/extension.rb +4 -0
- data/lib/asciidoctor-diagram/tikz.rb +1 -0
- data/lib/asciidoctor-diagram/tikz/extension.rb +4 -0
- data/lib/asciidoctor-diagram/umlet.rb +1 -0
- data/lib/asciidoctor-diagram/umlet/extension.rb +4 -0
- data/lib/asciidoctor-diagram/util/cli.rb +16 -1
- data/lib/asciidoctor-diagram/util/cli_generator.rb +13 -9
- data/lib/asciidoctor-diagram/util/gif.rb +1 -1
- data/lib/asciidoctor-diagram/util/java.rb +5 -3
- data/lib/asciidoctor-diagram/util/java_jruby.rb +4 -1
- data/lib/asciidoctor-diagram/util/java_socket.rb +10 -1
- data/lib/asciidoctor-diagram/util/pdf.rb +1 -1
- data/lib/asciidoctor-diagram/util/png.rb +1 -1
- data/lib/{server-1.3.15.jar → asciidoctor-diagram/util/server-1.3.20.jar} +0 -0
- data/lib/asciidoctor-diagram/util/svg.rb +25 -4
- data/lib/asciidoctor-diagram/vega.rb +2 -0
- data/lib/asciidoctor-diagram/vega/extension.rb +4 -0
- data/lib/asciidoctor-diagram/version.rb +1 -1
- data/lib/asciidoctor-diagram/wavedrom.rb +1 -0
- data/lib/asciidoctor-diagram/wavedrom/extension.rb +4 -0
- data/spec/a2s_spec.rb +10 -6
- data/spec/barcode_spec.rb +176 -0
- data/spec/blockdiag_spec.rb +10 -6
- data/spec/bpmn_spec.rb +7 -3
- data/spec/bytefield_spec.rb +10 -6
- data/spec/diagrams_spec.rb +27 -0
- data/spec/ditaa_spec.rb +8 -4
- data/spec/dpic_spec.rb +10 -6
- data/spec/erd_spec.rb +10 -6
- data/spec/gnuplot_spec.rb +14 -10
- data/spec/graphviz_spec.rb +7 -3
- data/spec/lilypond_spec.rb +10 -6
- data/spec/mermaid_spec.rb +44 -3
- data/spec/msc_spec.rb +10 -6
- data/spec/nomnoml_spec.rb +9 -5
- data/spec/pikchr_spec.rb +28 -6
- data/spec/plantuml_spec.rb +114 -3
- data/spec/shaape_spec.rb +10 -6
- data/spec/shared_examples.rb +161 -0
- data/spec/smcat_spec.rb +10 -6
- data/spec/svgbob_spec.rb +10 -6
- data/spec/symbolator_spec.rb +7 -3
- data/spec/syntrax_spec.rb +10 -6
- data/spec/test_helper.rb +6 -8
- data/spec/tikz_spec.rb +11 -7
- data/spec/umlet_spec.rb +6 -3
- data/spec/vega_spec.rb +11 -6
- data/spec/wavedrom_spec.rb +7 -3
- metadata +71 -14
- 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.15.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.15.jar +0 -0
- data/lib/plantuml.jar +0 -0
@@ -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,41 @@
|
|
1
|
+
:uri-a2s: https://github.com/asciitosvg/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-diagrams: https://diagrams.mingrammer.com
|
9
|
+
:uri-ditaa: http://ditaa.sourceforge.net/
|
10
|
+
:uri-dpic: https://gitlab.com/aplevich/dpic
|
11
|
+
:uri-dot: https://graphviz.gitlab.io/_pages/doc/info/lang.html
|
12
|
+
:uri-erd: https://github.com/BurntSushi/erd
|
13
|
+
:uri-gnuplot: http://gnuplot.info
|
14
|
+
:uri-graphviz: https://graphviz.gitlab.io
|
15
|
+
:uri-imagemagick: http://www.imagemagick.org
|
16
|
+
:uri-java: http://java.sun.com
|
17
|
+
:uri-mermaid: https://github.com/mermaid-js/mermaid-cli
|
18
|
+
:uri-mscgen: http://www.mcternan.me.uk/mscgen/
|
19
|
+
:uri-nomnoml: http://nomnoml.com
|
20
|
+
:uri-nwdiag: http://blockdiag.com/en/nwdiag/index.html
|
21
|
+
:uri-packetdiag: http://blockdiag.com/en/nwdiag/index.html
|
22
|
+
:uri-phantomjs: http://phantomjs.org
|
23
|
+
:uri-pikchr: https://pikchr.org
|
24
|
+
:uri-plantuml: http://plantuml.sourceforge.net
|
25
|
+
:uri-py-plantuml: https://code.google.com/p/asciidoc-plantuml/
|
26
|
+
:uri-python: https://www.python.org
|
27
|
+
:uri-rackdiag: http://blockdiag.com/en/nwdiag/index.html
|
28
|
+
:uri-seqdiag: http://blockdiag.com/en/seqdiag/index.html
|
29
|
+
:uri-shaape: https://github.com/christiangoltz/shaape
|
30
|
+
:uri-smcat: https://github.com/sverweij/state-machine-cat
|
31
|
+
:uri-svgbob: https://github.com/ivanceras/svgbobrus
|
32
|
+
:uri-symbolator: https://github.com/kevinpt/symbolator
|
33
|
+
:uri-syntrax: https://kevinpt.github.io/syntrax/
|
34
|
+
:uri-jsyntrax: https://atp-mipt.github.io/jsyntrax/
|
35
|
+
:uri-tikz: https://github.com/pgf-tikz/pgf
|
36
|
+
:uri-umlet: http://www.umlet.com/
|
37
|
+
:uri-vega: https://vega.github.io/vega/
|
38
|
+
:uri-vegalite: https://vega.github.io/vega-lite/
|
39
|
+
:uri-wavedrom: http://wavedrom.com
|
40
|
+
:uri-wavedromeditor: https://github.com/wavedrom/wavedrom.github.io/releases
|
41
|
+
: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
|
+
require_relative 'asciidoctor-diagram/barcode'
|
2
3
|
require_relative 'asciidoctor-diagram/blockdiag'
|
3
4
|
require_relative 'asciidoctor-diagram/bpmn'
|
4
5
|
require_relative 'asciidoctor-diagram/bytefield'
|
6
|
+
require_relative 'asciidoctor-diagram/diagrams'
|
5
7
|
require_relative 'asciidoctor-diagram/ditaa'
|
6
8
|
require_relative 'asciidoctor-diagram/dpic'
|
7
9
|
require_relative 'asciidoctor-diagram/erd'
|
@@ -4,4 +4,5 @@ require_relative 'a2s/extension'
|
|
4
4
|
Asciidoctor::Extensions.register do
|
5
5
|
block Asciidoctor::Diagram::AsciiToSvgBlockProcessor, :a2s
|
6
6
|
block_macro Asciidoctor::Diagram::AsciiToSvgBlockMacroProcessor, :a2s
|
7
|
+
inline_macro Asciidoctor::Diagram::AsciiToSvgInlineMacroProcessor, :a2s
|
7
8
|
end
|
@@ -10,5 +10,9 @@ module Asciidoctor
|
|
10
10
|
class AsciiToSvgBlockMacroProcessor < DiagramBlockMacroProcessor
|
11
11
|
use_converter AsciiToSvgConverter
|
12
12
|
end
|
13
|
+
|
14
|
+
class AsciiToSvgInlineMacroProcessor < DiagramInlineMacroProcessor
|
15
|
+
use_converter AsciiToSvgConverter
|
16
|
+
end
|
13
17
|
end
|
14
18
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'asciidoctor/extensions'
|
2
|
+
require_relative 'barcode/extension'
|
3
|
+
require_relative 'barcode/converter'
|
4
|
+
|
5
|
+
Asciidoctor::Extensions.register do
|
6
|
+
Asciidoctor::Diagram::BarcodeConverter::BARCODE_TYPES.each do |type|
|
7
|
+
block Asciidoctor::Diagram::BarcodeBlockProcessor, type, :type => type
|
8
|
+
block_macro Asciidoctor::Diagram::BarcodeBlockMacroProcessor, type, :type => type
|
9
|
+
inline_macro Asciidoctor::Diagram::BarcodeInlineMacroProcessor, type, :type => type
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
require_relative '../diagram_converter'
|
2
|
+
require_relative 'dependencies'
|
3
|
+
|
4
|
+
module Asciidoctor
|
5
|
+
module Diagram
|
6
|
+
# @private
|
7
|
+
class BarcodeConverter
|
8
|
+
BARCODE_TYPES = [
|
9
|
+
:bookland,
|
10
|
+
:codabar,
|
11
|
+
:code25,
|
12
|
+
:code25iata,
|
13
|
+
:code25interleaved,
|
14
|
+
:code39,
|
15
|
+
:code93,
|
16
|
+
:code128,
|
17
|
+
:code128a,
|
18
|
+
:code128b,
|
19
|
+
:code128c,
|
20
|
+
:ean8,
|
21
|
+
:ean13,
|
22
|
+
:gs1_128,
|
23
|
+
:qrcode,
|
24
|
+
:upca,
|
25
|
+
]
|
26
|
+
|
27
|
+
include DiagramConverter
|
28
|
+
|
29
|
+
def supported_formats
|
30
|
+
[:png, :svg, :txt]
|
31
|
+
end
|
32
|
+
|
33
|
+
def collect_options(source)
|
34
|
+
options = {}
|
35
|
+
|
36
|
+
options[:xdim] = source.attr('xdim')
|
37
|
+
options[:ydim] = source.attr('ydim')
|
38
|
+
options[:margin] = source.attr('margin')
|
39
|
+
options[:height] = source.attr('height')
|
40
|
+
options[:foreground] = source.attr('foreground')
|
41
|
+
options[:background] = source.attr('background')
|
42
|
+
|
43
|
+
[:xdim, :ydim, :margin, :height].each { |o| options[o] = options[o].to_i if options[o] }
|
44
|
+
|
45
|
+
options
|
46
|
+
end
|
47
|
+
|
48
|
+
def convert(source, format, options)
|
49
|
+
BarcodeDependencies::BARCODE_DEPENDENCIES.each_pair { |n, v| source.ensure_gem(n, v) }
|
50
|
+
require 'barby'
|
51
|
+
|
52
|
+
code = source.code
|
53
|
+
type = source.config[:type]
|
54
|
+
|
55
|
+
case type
|
56
|
+
when :bookland
|
57
|
+
require 'barby/barcode/bookland'
|
58
|
+
barcode = Barby::Bookland.new(code)
|
59
|
+
when :codabar
|
60
|
+
require 'barby/barcode/codabar'
|
61
|
+
barcode = Barby::Codabar.new(code)
|
62
|
+
when :code25
|
63
|
+
require 'barby/barcode/code_25'
|
64
|
+
barcode = Barby::Code25.new(code)
|
65
|
+
when :code25iata
|
66
|
+
require 'barby/barcode/code_25_iata'
|
67
|
+
barcode = Barby::Code25IATA.new(code)
|
68
|
+
when :code25interleaved
|
69
|
+
require 'barby/barcode/code_25_interleaved'
|
70
|
+
barcode = Barby::Code25Interleaved.new(code)
|
71
|
+
when :code39
|
72
|
+
require 'barby/barcode/code_39'
|
73
|
+
barcode = Barby::Code39.new(code)
|
74
|
+
when :code93
|
75
|
+
require 'barby/barcode/code_93'
|
76
|
+
barcode = Barby::Code93.new(code)
|
77
|
+
when :code128
|
78
|
+
require 'barby/barcode/code_128'
|
79
|
+
barcode = Barby::Code128.new(code)
|
80
|
+
when :code128a
|
81
|
+
require 'barby/barcode/code_128'
|
82
|
+
barcode = Barby::Code128A.new(code)
|
83
|
+
when :code128b
|
84
|
+
require 'barby/barcode/code_128'
|
85
|
+
barcode = Barby::Code128B.new(code)
|
86
|
+
when :code128c
|
87
|
+
require 'barby/barcode/code_128'
|
88
|
+
barcode = Barby::Code128C.new(code)
|
89
|
+
when :ean8
|
90
|
+
require 'barby/barcode/ean_8'
|
91
|
+
barcode = Barby::EAN8.new(code)
|
92
|
+
when :ean13
|
93
|
+
require 'barby/barcode/ean_13'
|
94
|
+
barcode = Barby::EAN13.new(code)
|
95
|
+
when :gs1_128
|
96
|
+
require 'barby/barcode/code_128'
|
97
|
+
code = code.gsub /\([^)]+\)/ do |control|
|
98
|
+
case control.upcase
|
99
|
+
when '(FNC1)'
|
100
|
+
Barby::Code128::FNC1
|
101
|
+
when '(FNC2)'
|
102
|
+
Barby::Code128::FNC2
|
103
|
+
when '(FNC3)'
|
104
|
+
Barby::Code128::FNC3
|
105
|
+
when '(FNC4)'
|
106
|
+
Barby::Code128::FNC4
|
107
|
+
when '(CODEA)'
|
108
|
+
Barby::Code128::CODEA
|
109
|
+
when '(CODEB)'
|
110
|
+
Barby::Code128::CODEB
|
111
|
+
when '(CODEC)'
|
112
|
+
Barby::Code128::CODEC
|
113
|
+
when '(SHIFT)'
|
114
|
+
Barby::Code128::SHIFT
|
115
|
+
when '(SP)'
|
116
|
+
' '
|
117
|
+
else
|
118
|
+
control
|
119
|
+
end
|
120
|
+
end
|
121
|
+
code = code.gsub(/\s+/, '')
|
122
|
+
code = code.prepend(Barby::Code128::FNC1) unless code[0] == Barby::Code128::FNC1
|
123
|
+
barcode = Barby::Code128.new(code)
|
124
|
+
when :qrcode
|
125
|
+
BarcodeDependencies::QRCODE_DEPENDENCIES.each_pair { |n, v| source.ensure_gem(n, v) }
|
126
|
+
require 'barby/barcode/qr_code'
|
127
|
+
barcode = Barby::QrCode.new(code)
|
128
|
+
when :upca
|
129
|
+
require 'barby/barcode/ean_13'
|
130
|
+
barcode = Barby::UPCA.new(code)
|
131
|
+
else
|
132
|
+
raise "Unsupported barcode type: #{type}"
|
133
|
+
end
|
134
|
+
|
135
|
+
case format
|
136
|
+
when :png
|
137
|
+
BarcodeDependencies::PNG_DEPENDENCIES.each_pair { |n, v| source.ensure_gem(n, v) }
|
138
|
+
require 'barby/outputter/png_outputter'
|
139
|
+
require 'chunky_png/color'
|
140
|
+
options[:foreground] = ChunkyPNG::Color(options[:foreground]) if options[:foreground]
|
141
|
+
options[:background] = ChunkyPNG::Color(options[:background]) if options[:background]
|
142
|
+
barcode.to_png(options)
|
143
|
+
when :svg
|
144
|
+
require_relative 'svg_outputter'
|
145
|
+
options[:foreground] = "##{options[:foreground]}" if options[:foreground] =~ /^[0-9a-f]+$/i
|
146
|
+
options[:background] = "##{options[:background]}" if options[:background] =~ /^[0-9a-f]+$/i
|
147
|
+
barcode.to_svg(options)
|
148
|
+
when :txt
|
149
|
+
require 'barby/outputter/ascii_outputter'
|
150
|
+
barcode.to_ascii
|
151
|
+
else
|
152
|
+
raise "Unsupported format: #{format}"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Asciidoctor
|
2
|
+
module Diagram
|
3
|
+
module BarcodeDependencies
|
4
|
+
BARCODE_DEPENDENCIES = {'barby' => '~> 0.6.8'}
|
5
|
+
PNG_DEPENDENCIES = {'chunky_png' => '~> 1.4.0'}
|
6
|
+
QRCODE_DEPENDENCIES = {'rqrcode' => '~> 2.0.0'}
|
7
|
+
ALL_DEPENDENCIES = {}.merge(BARCODE_DEPENDENCIES).merge(PNG_DEPENDENCIES).merge(QRCODE_DEPENDENCIES)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative 'converter'
|
2
|
+
require_relative '../diagram_processor'
|
3
|
+
|
4
|
+
module Asciidoctor
|
5
|
+
module Diagram
|
6
|
+
module BarcodeProcessor
|
7
|
+
def self.check_config(config = {})
|
8
|
+
type = config[:type]
|
9
|
+
raise "Barcode type not specified in config" if type.nil?
|
10
|
+
raise "Unsupported barcode type: '#{type}'" unless BarcodeConverter::BARCODE_TYPES.include?(type)
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(name = nil, config = {})
|
14
|
+
super
|
15
|
+
BarcodeProcessor.check_config(config)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module BarcodeMacroProcessor
|
20
|
+
def create_source(parent, target, attributes)
|
21
|
+
if attributes['external']
|
22
|
+
super
|
23
|
+
else
|
24
|
+
code = parent.sub_attributes(target, :attribute_missing => 'warn')
|
25
|
+
::Asciidoctor::Diagram::ReaderSource.new(self, parent, code, attributes)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class BarcodeBlockProcessor < DiagramBlockProcessor
|
31
|
+
use_converter BarcodeConverter
|
32
|
+
include BarcodeProcessor
|
33
|
+
end
|
34
|
+
|
35
|
+
class BarcodeBlockMacroProcessor < DiagramBlockMacroProcessor
|
36
|
+
use_converter BarcodeConverter
|
37
|
+
include BarcodeProcessor
|
38
|
+
include BarcodeMacroProcessor
|
39
|
+
end
|
40
|
+
|
41
|
+
class BarcodeInlineMacroProcessor < DiagramInlineMacroProcessor
|
42
|
+
use_converter BarcodeConverter
|
43
|
+
include BarcodeProcessor
|
44
|
+
include BarcodeMacroProcessor
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'barby/outputter/svg_outputter'
|
2
|
+
|
3
|
+
module Barby
|
4
|
+
class SvgOutputter
|
5
|
+
# Monkey patch to fix foreground color in SVG output
|
6
|
+
def bars_to_path(opts={})
|
7
|
+
with_options opts do
|
8
|
+
%Q|<path stroke="#{foreground}" stroke-width="#{xdim}" d="#{bars_to_path_data(opts)}" />|
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -5,5 +5,6 @@ Asciidoctor::Extensions.register do
|
|
5
5
|
['BlockDiag', 'SeqDiag', 'ActDiag', 'NwDiag', 'RackDiag', 'PacketDiag'].each do |tool|
|
6
6
|
block ::Asciidoctor::Diagram.const_get("#{tool}BlockProcessor"), tool.downcase.to_sym
|
7
7
|
block_macro ::Asciidoctor::Diagram.const_get("#{tool}BlockMacroProcessor"), tool.downcase.to_sym
|
8
|
+
inline_macro ::Asciidoctor::Diagram.const_get("#{tool}InlineMacroProcessor"), tool.downcase.to_sym
|
8
9
|
end
|
9
10
|
end
|
@@ -13,6 +13,11 @@ module Asciidoctor
|
|
13
13
|
use_converter ::Asciidoctor::Diagram.const_get("#{tool}Converter")
|
14
14
|
end
|
15
15
|
::Asciidoctor::Diagram.const_set("#{tool}BlockMacroProcessor", block_macro)
|
16
|
+
|
17
|
+
inline_macro = Class.new(DiagramInlineMacroProcessor) do
|
18
|
+
use_converter ::Asciidoctor::Diagram.const_get("#{tool}Converter")
|
19
|
+
end
|
20
|
+
::Asciidoctor::Diagram.const_set("#{tool}InlineMacroProcessor", inline_macro)
|
16
21
|
end
|
17
22
|
end
|
18
23
|
end
|
@@ -4,4 +4,5 @@ require_relative 'bytefield/extension'
|
|
4
4
|
Asciidoctor::Extensions.register do
|
5
5
|
block Asciidoctor::Diagram::BytefieldBlockProcessor, :bytefield
|
6
6
|
block_macro Asciidoctor::Diagram::BytefieldBlockMacroProcessor, :bytefield
|
7
|
+
inline_macro Asciidoctor::Diagram::BytefieldInlineMacroProcessor, :bytefield
|
7
8
|
end
|
@@ -50,6 +50,8 @@ module Asciidoctor
|
|
50
50
|
}
|
51
51
|
}
|
52
52
|
|
53
|
+
TEXT_FORMATS = [:txt, :atxt, :utxt]
|
54
|
+
|
53
55
|
# Processes the diagram block or block macro by converting it into an image or literal block.
|
54
56
|
#
|
55
57
|
# @param parent [Asciidoctor::AbstractBlock] the parent asciidoc block of the block or block macro being processed
|
@@ -57,17 +59,22 @@ module Asciidoctor
|
|
57
59
|
# target value of a block macro
|
58
60
|
# @param attributes [Hash] the attributes of the block or block macro
|
59
61
|
# @return [Asciidoctor::AbstractBlock] a new block that replaces the original block or block macro
|
62
|
+
|
60
63
|
def process(parent, reader_or_target, attributes)
|
61
64
|
location = parent.document.reader.cursor_at_mark
|
62
65
|
|
63
66
|
normalised_attributes = attributes.inject({}) { |h, (k, v)| h[normalise_attribute_name(k)] = v; h }
|
64
|
-
source = create_source(parent, reader_or_target, normalised_attributes)
|
65
|
-
|
66
67
|
converter = config[:converter].new
|
67
68
|
|
68
|
-
supported_formats = converter
|
69
|
+
supported_formats = supported_formats(converter)
|
70
|
+
|
71
|
+
source = create_source(parent, reader_or_target, normalised_attributes)
|
72
|
+
# memorize current code here for error message to avoid calling wrapped source's code method later
|
73
|
+
code = source.code
|
69
74
|
|
70
75
|
begin
|
76
|
+
source = converter.wrap_source(source)
|
77
|
+
|
71
78
|
format = source.attributes.delete('format') || source.global_attr('format', supported_formats[0])
|
72
79
|
format = format.to_sym if format.respond_to?(:to_sym)
|
73
80
|
|
@@ -80,7 +87,7 @@ module Asciidoctor
|
|
80
87
|
caption = source.attributes.delete 'caption'
|
81
88
|
|
82
89
|
case format
|
83
|
-
when
|
90
|
+
when *TEXT_FORMATS
|
84
91
|
block = create_literal_block(parent, source, format, converter)
|
85
92
|
else
|
86
93
|
block = create_image_block(parent, source, format, converter)
|
@@ -103,7 +110,7 @@ module Asciidoctor
|
|
103
110
|
logger.error message_with_context warn_msg, source_location: location
|
104
111
|
|
105
112
|
text << "\n"
|
106
|
-
text <<
|
113
|
+
text << code
|
107
114
|
Asciidoctor::Block.new parent, :listing, :source => text, :attributes => attributes
|
108
115
|
end
|
109
116
|
|
@@ -129,6 +136,10 @@ module Asciidoctor
|
|
129
136
|
|
130
137
|
private
|
131
138
|
|
139
|
+
def supported_formats(converter)
|
140
|
+
converter.supported_formats
|
141
|
+
end
|
142
|
+
|
132
143
|
def normalise_attribute_name(k)
|
133
144
|
case k
|
134
145
|
when String
|
@@ -174,7 +185,8 @@ module Asciidoctor
|
|
174
185
|
metadata = source.create_image_metadata
|
175
186
|
metadata[:options] = options
|
176
187
|
|
177
|
-
|
188
|
+
allow_image_optimisation = source.attr('optimise', 'true') == 'true'
|
189
|
+
result, metadata[:width], metadata[:height] = params[:decoder].post_process_image(result, allow_image_optimisation)
|
178
190
|
|
179
191
|
FileUtils.mkdir_p(File.dirname(image_file)) unless Dir.exist?(File.dirname(image_file))
|
180
192
|
File.open(image_file, 'wb') {|f| f.write result}
|
@@ -370,5 +382,42 @@ module Asciidoctor
|
|
370
382
|
FileSource.new(self, parent, apply_target_subs(parent, target), attributes)
|
371
383
|
end
|
372
384
|
end
|
385
|
+
|
386
|
+
# Base class for diagram inline macro processors.
|
387
|
+
class DiagramInlineMacroProcessor < Asciidoctor::Extensions::InlineMacroProcessor
|
388
|
+
include DiagramProcessor
|
389
|
+
|
390
|
+
def self.inherited(subclass)
|
391
|
+
subclass.name_positional_attributes ['format']
|
392
|
+
end
|
393
|
+
|
394
|
+
def apply_target_subs(parent, target)
|
395
|
+
if target
|
396
|
+
parent.normalize_system_path(parent.sub_attributes(target, :attribute_missing => 'warn'))
|
397
|
+
else
|
398
|
+
nil
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
alias_method(:generate_block,:process)
|
403
|
+
|
404
|
+
def process(parent, reader_or_target, attributes)
|
405
|
+
block = generate_block(parent, reader_or_target, attributes)
|
406
|
+
attrs = block.attributes.dup
|
407
|
+
target = attrs.delete('target')
|
408
|
+
create_inline(parent, :image, nil, :type => 'image', :target => target, :attributes => attrs).convert
|
409
|
+
end
|
410
|
+
|
411
|
+
def supported_formats(converter)
|
412
|
+
converter.supported_formats.reject { |f| TEXT_FORMATS.include?(f) }
|
413
|
+
end
|
414
|
+
|
415
|
+
# Creates a FileSource using target as the file name.
|
416
|
+
#
|
417
|
+
# @return [FileSource] a FileSource
|
418
|
+
def create_source(parent, target, attributes)
|
419
|
+
FileSource.new(self, parent, apply_target_subs(parent, target), attributes)
|
420
|
+
end
|
421
|
+
end
|
373
422
|
end
|
374
423
|
end
|