asciidoctor-diagram 1.5.8 → 1.5.9

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: 0ccff08a5e14979fee3b741ce234474feb2a795d
4
- data.tar.gz: 0e61b1ad07479b28caa76797becf7ae54e2d4fb3
3
+ metadata.gz: abeb00e6c1a06050264ad6af1d4d2aeb1273e91f
4
+ data.tar.gz: 378319e93a82170c6544523d31bad76728643084
5
5
  SHA512:
6
- metadata.gz: d2f65dc8a689996d4a42d86343559538b383d4fd115d98828c585cb7cb8927ce8a4e1ed8b5b39d8b7bccc81b1ec32be70250b91f464c7f56c2d33734229b2543
7
- data.tar.gz: 6e37fdc49db2cf843e2a3c4652e292908072b914341a53875faf2463ec0027f49148cc0e3dcc2f872e5bf5203c02c0d23394731dab4fabaea20a738eb667311d
6
+ metadata.gz: 7d18137fa76b2612d93d25224aa18d771cc64cad4e24990384645bb8025f114ad4d038bdb543b4cddfb8d100c178e10115501bf73244a26bfb859029c06fa723
7
+ data.tar.gz: 9f9b51ea388030a030026b7bba7c58c05345ba989764324631ab6b5e85ded33350d85d0c27922a23de7c36f021b3a6e3664790ef7db07c23c9dbb92c5a880699
data/CHANGELOG.adoc CHANGED
@@ -1,5 +1,12 @@
1
1
  = Asciidoctor-diagram Changelog
2
2
 
3
+ == 1.5.9
4
+
5
+ Enhancements::
6
+
7
+ * Add support for ASCIIToSVG
8
+ * Issue #181: Add support for Vega and Vega-Lite
9
+
3
10
  == 1.5.8
4
11
 
5
12
  Enhancements::
data/README.adoc CHANGED
@@ -13,6 +13,7 @@ ifndef::imagesdir[:imagesdir: images]
13
13
  :check: icon:check[]
14
14
  ifdef::env-github[:check: :ballot_box_with_check:]
15
15
  ifndef::env-site[:status:]
16
+ :uri-a2s: https://github.com/dhobsd/asciitosvg
16
17
  :uri-actdiag: http://blockdiag.com/en/actdiag/index.html
17
18
  :uri-asciidoctor-api: http://asciidoctor.org/docs/user-manual/#api
18
19
  :uri-asciidoctor-extensions: http://asciidoctor.org/docs/user-manual/#extension-points
@@ -36,13 +37,15 @@ ifndef::env-site[:status:]
36
37
  :uri-svgbob: https://github.com/ivanceras/svgbobrus
37
38
  :uri-syntrax: https://kevinpt.github.io/syntrax/
38
39
  :uri-umlet: http://www.umlet.com/
40
+ :uri-vega: https://vega.github.io/vega/
41
+ :uri-vegalite: https://vega.github.io/vega-lite/
39
42
  :uri-wavedrom: http://wavedrom.com
40
43
  :uri-wavedromeditor: https://github.com/wavedrom/wavedrom.github.io/releases
41
44
  :uri-wavedromcli: https://github.com/wavedrom/cli
42
45
 
43
46
  Asciidoctor Diagram is a set of Asciidoctor extensions that enable you to add diagrams, which you describe using plain text, to your AsciiDoc document.
44
47
 
45
- The extensions supports the BlockDiag ({uri-blockdiag}[BlockDiag], {uri-seqdiag}[SeqDiag], {uri-actdiag}[ActDiag], {uri-nwdiag}[NwDiag]), {uri-ditaa}[Ditaa], {uri-erd}[Erd], {uri-dot}[GraphViz], {uri-mermaid}[Mermaid], {uri-mscgen}[Msc], {uri-plantuml}[PlantUML], {uri-shaape}[Shaape], {uri-svgbob}[SvgBob], {uri-syntrax}[Syntrax], {uri-umlet}[UMLet] and {uri-wavedrom}[WaveDrom] syntax.
48
+ The extensions supports the {uri-a2s}[AsciiToSVG], BlockDiag ({uri-blockdiag}[BlockDiag], {uri-seqdiag}[SeqDiag], {uri-actdiag}[ActDiag], {uri-nwdiag}[NwDiag]), {uri-ditaa}[Ditaa], {uri-erd}[Erd], {uri-dot}[GraphViz], {uri-mermaid}[Mermaid], {uri-mscgen}[Msc], {uri-plantuml}[PlantUML], {uri-shaape}[Shaape], {uri-svgbob}[SvgBob], {uri-syntrax}[Syntrax], {uri-umlet}[UMLet], {uri-vega}[Vega], {uri-vegalite}[Vega-Lite] and {uri-wavedrom}[WaveDrom] syntax.
46
49
 
47
50
  Each extension runs the diagram processor to generate an SVG, PNG, or TXT file from the input text.
48
51
  The generated file is then inserted into your converted document.
@@ -59,7 +62,7 @@ ifdef::status[]
59
62
 
60
63
  image:https://travis-ci.org/asciidoctor/asciidoctor-diagram.svg?branch=master["Linux Build Status", link="https://travis-ci.org/asciidoctor/asciidoctor-diagram"]
61
64
  image:https://ci.appveyor.com/api/projects/status/4r4gkk5gy3igs6nh/branch/master?svg=true["Windows Build Status", link="https://ci.appveyor.com/project/asciidoctor/asciidoctor-diagram"]
62
- image:https://img.shields.io/gem/v/asciidoctor-diagram.svg?label=gem%20version[Gem Version, link=https://rubygems.org/gems/asciidoctor-diagram]
65
+ image:https://badge.fury.io/rb/asciidoctor-diagram.svg[Gem Version, link=https://rubygems.org/gems/asciidoctor-diagram]
63
66
  endif::status[]
64
67
 
65
68
  ifeval::["{toc-placement}" == "macro"]
@@ -82,7 +85,7 @@ by first adding the following entry to your project's [.path]_Gemfile_.
82
85
  .Gemfile
83
86
  [source,ruby]
84
87
  ----
85
- gem 'asciidoctor-diagram', '~> 1.5.7'
88
+ gem 'asciidoctor-diagram'
86
89
  ----
87
90
 
88
91
  Then execute `bundle` in the CLI.
@@ -110,6 +113,7 @@ The following diagram types and output formats are available:
110
113
  [cols=">,5*^",options="header"]
111
114
  |===
112
115
  |Diagram Type |gif |pdf |png |svg |txt
116
+ |{uri-a2s}[a2s] | | | |{check}|
113
117
  |{uri-actdiag}[actdiag] | |{check}|{check}|{check}|
114
118
  |{uri-blockdiag}[blockdiag] | |{check}|{check}|{check}|
115
119
  |{uri-ditaa}[ditaa] | | |{check}|{check}|
@@ -127,6 +131,8 @@ The following diagram types and output formats are available:
127
131
  |{uri-svgbob}[svgbob] | | | |{check}|
128
132
  |{uri-syntrax}[syntrax] | |{check}|{check}|{check}|
129
133
  |{uri-umlet}[umlet] |{check}|{check}|{check}|{check}|
134
+ |{uri-vega}[vega] | | |{check}|{check}|
135
+ |{uri-vegalite}[vegalite] | | |{check}|{check}|
130
136
  |{uri-wavedrom}[wavedrom] | | |{check}|{check}|
131
137
  |===
132
138
 
@@ -239,7 +245,7 @@ or load and register each extension individually.
239
245
  require 'asciidoctor-diagram/<extension_name>'
240
246
  ----
241
247
 
242
- `<extension_name>` can be one of `blockdiag`, `ditaa`, `erd`, `graphviz`, `meme`, `mermaid`, `msc`, `plantuml`, `shaape`, `svgbob`, `syntrax`, or `wavedrom`.
248
+ `<extension_name>` can be one of `a2s`, `blockdiag`, `ditaa`, `erd`, `graphviz`, `meme`, `mermaid`, `msc`, `plantuml`, `shaape`, `svgbob`, `syntrax`, `umlet`, `vega` or `wavedrom`.
243
249
 
244
250
  Requiring one or more of these files will automatically register the extensions for all processed documents.
245
251
 
@@ -282,6 +288,7 @@ The following table lists the tools that are required for each diagram type, the
282
288
  [cols=">,2*<",options="header"]
283
289
  |===
284
290
  |Diagram Type |Tool |Attribute
291
+ |a2s |{uri-a2s}[AsciiToSvg] |`a2s`
285
292
  |actdiag |{uri-actdiag}[ActDiag] |`actdiag`
286
293
  |blockdiag |{uri-blockdiag}[BlockDiag] |`blockdiag`
287
294
  |ditaa |{uri-java}[Java] |`java`
@@ -299,6 +306,8 @@ The following table lists the tools that are required for each diagram type, the
299
306
  |svgbob |{uri-svgbob}[SvgBob] |`svgbob`
300
307
  |syntrax |{uri-syntrax}[Syntrax] |`syntrax`
301
308
  |umlet |{uri-umlet}[Umlet] |`umlet`
309
+ |vega |{uri-vega}[vg2png] and/or {uri-vega}[vg2png] |`vg2png` and `vg2svg`
310
+ |vegalite |{uri-vegalite}[vl2vg] and {uri-vega}[vg2png] and/or {uri-vega}[vg2svg]|`vl2vg`, `vg2png` and `vg2svg`
302
311
  .2+|wavedrom |{uri-wavedromeditor}[WaveDrom Editor] |`wavedrom`
303
312
  |{uri-wavedromcli}[WaveDrom CLI] and {uri-phantomjs}[PhantomJS] |`wavedrom` and `phantomjs`
304
313
  |===
@@ -346,6 +355,14 @@ This is illustrated for the blockdiag `fontpath` attribute in the example below.
346
355
  Each attribute can either be specified at the block level or at the document level.
347
356
  The attribute name at the block level should be prefixed with the name of the diagram type and a dash.
348
357
 
358
+ ==== AsciiToSVG
359
+
360
+ [cols=">,<,<",options="header"]
361
+ |===
362
+ |Name |Default value |Description
363
+ |fontfamily |unspecified |The font family to use in the generated SVG image
364
+ |noblur |unspecified |Disable drop-shadow blurring
365
+ |===
349
366
 
350
367
  ==== Blockdiag
351
368
 
@@ -1,3 +1,4 @@
1
+ require_relative 'asciidoctor-diagram/a2s'
1
2
  require_relative 'asciidoctor-diagram/blockdiag'
2
3
  require_relative 'asciidoctor-diagram/ditaa'
3
4
  require_relative 'asciidoctor-diagram/erd'
@@ -11,4 +12,5 @@ require_relative 'asciidoctor-diagram/shaape'
11
12
  require_relative 'asciidoctor-diagram/svgbob'
12
13
  require_relative 'asciidoctor-diagram/syntrax'
13
14
  require_relative 'asciidoctor-diagram/umlet'
15
+ require_relative 'asciidoctor-diagram/vega'
14
16
  require_relative 'asciidoctor-diagram/wavedrom'
@@ -0,0 +1,8 @@
1
+ require_relative 'extensions'
2
+
3
+ Asciidoctor::Extensions.register do
4
+ require_relative 'a2s/extension'
5
+
6
+ block Asciidoctor::Diagram::AsciiToSvgBlockProcessor, :a2s
7
+ block_macro Asciidoctor::Diagram::AsciiToSvgBlockMacroProcessor, :a2s
8
+ end
@@ -0,0 +1,60 @@
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 AsciiToSvg
10
+ include CliGenerator
11
+ include Which
12
+
13
+ def self.included(mod)
14
+ [:svg].each do |f|
15
+ mod.register_format(f, :image) do |parent, source|
16
+ a2s(parent, source, f)
17
+ end
18
+ end
19
+ end
20
+
21
+ def a2s(parent, source, format)
22
+ inherit_prefix = name
23
+
24
+ sx = source.attr('scalex', nil, inherit_prefix)
25
+ sy = source.attr('scaley', nil, inherit_prefix)
26
+ scale = source.attr('scale', nil, inherit_prefix)
27
+ noblur = source.attr('noblur', 'false', inherit_prefix) == 'true'
28
+ font = source.attr('fontfamily', nil, inherit_prefix)
29
+
30
+ generate_stdin(which(parent, 'a2s'), format.to_s, source.to_s) do |tool_path, output_path|
31
+ args = [tool_path, "-o#{Platform.native_path(output_path)}"]
32
+
33
+ if sx && sy
34
+ args << "-s#{sx},#{sy}"
35
+ elsif scale
36
+ args << "-s#{scale},#{scale}"
37
+ end
38
+
39
+ if noblur
40
+ args << '-b'
41
+ end
42
+
43
+ if font
44
+ args << "-f#{font}"
45
+ end
46
+
47
+ args
48
+ end
49
+ end
50
+ end
51
+
52
+ class AsciiToSvgBlockProcessor < Extensions::DiagramBlockProcessor
53
+ include AsciiToSvg
54
+ end
55
+
56
+ class AsciiToSvgBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
57
+ include AsciiToSvg
58
+ end
59
+ end
60
+ end
@@ -87,19 +87,30 @@ module Asciidoctor
87
87
  if options[:config]
88
88
  args << '--configFile' << Platform.native_path(options[:config])
89
89
  elsif options[:gantt] || options[:sequence]
90
- config = []
90
+ mermaidConfig = []
91
91
 
92
92
  if options[:gantt]
93
- config << "\"gantt\": #{File.read(options[:gantt])}"
93
+ mermaidConfig << "\"gantt\": #{File.read(options[:gantt])}"
94
94
  end
95
95
 
96
96
  if options[:sequence]
97
- config << "\"sequenceDiagram\": #{File.read(options[:sequence])}"
97
+ configKey = config['mmdcSequenceConfigKey'] ||= begin
98
+ version_parts = ::Asciidoctor::Diagram::Cli.run(mmdc, '--version')[:out].split('.').map { |p| p.to_i }
99
+ major = version_parts[0] || 0
100
+ minor = version_parts[1] || 0
101
+ patch = version_parts[2] || 0
102
+ if major > 0 || (major == 0 && minor > 4) || (major == 0 && minor == 4 && patch > 1)
103
+ 'sequence'
104
+ else
105
+ 'sequenceDiagram'
106
+ end
107
+ end
108
+ mermaidConfig << "\"#{configKey}\": #{File.read(options[:sequence])}"
98
109
  end
99
110
 
100
111
  config_file = "#{input_path}.json"
101
112
 
102
- File.write(config_file, "{#{config.join ','}}")
113
+ File.write(config_file, "{#{mermaidConfig.join ','}}")
103
114
 
104
115
  args << '--configFile' << Platform.native_path(config_file)
105
116
  end
@@ -20,6 +20,15 @@ module Asciidoctor
20
20
  end
21
21
  end
22
22
 
23
+ def generate_stdin_stdout(tool, code)
24
+ if block_given?
25
+ opts = yield tool
26
+ else
27
+ opts = [tool]
28
+ end
29
+ generate(opts, :stdout, :stdin_data => code)
30
+ end
31
+
23
32
  def generate_file(tool, input_ext, output_ext, code)
24
33
  tool_name = File.basename(tool)
25
34
 
@@ -57,7 +66,7 @@ module Asciidoctor
57
66
 
58
67
  result = ::Asciidoctor::Diagram::Cli.run(*args, open3_opts)
59
68
 
60
- data = read_result(target_file, out_file)
69
+ data = target_file == :stdout ? result[:out] : read_result(target_file, out_file)
61
70
 
62
71
  if data.empty?
63
72
  raise "#{args[0]} failed: #{result[:out].empty? ? result[:err] : result[:out]}"
@@ -0,0 +1,11 @@
1
+ require_relative 'extensions'
2
+
3
+ Asciidoctor::Extensions.register do
4
+ require_relative 'vega/extension'
5
+
6
+ block Asciidoctor::Diagram::VegaBlockProcessor, :vega
7
+ block_macro Asciidoctor::Diagram::VegaBlockMacroProcessor, :vega
8
+
9
+ block Asciidoctor::Diagram::VegaBlockProcessor, :vegalite
10
+ block_macro Asciidoctor::Diagram::VegaBlockMacroProcessor, :vegalite
11
+ end
@@ -0,0 +1,52 @@
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 Vega
10
+ include CliGenerator
11
+ include Which
12
+
13
+ def self.included(mod)
14
+ [:svg, :png].each do |f|
15
+ mod.register_format(f, :image) do |parent, source|
16
+ vega(parent, source, f)
17
+ end
18
+ end
19
+ end
20
+
21
+ def vega(parent, source, format)
22
+ base_dir = source.base_dir
23
+
24
+ code = source.to_s
25
+
26
+ if code.include?('/schema/vega-lite/') || name.to_s.include?('lite') || source.attr('vegalite')
27
+ vega_code = generate_stdin_stdout(which(parent, "vl2vg"), code)
28
+ else
29
+ vega_code = code
30
+ end
31
+
32
+ generate_file(which(parent, "vg2#{format}"), "json", format.to_s, vega_code) do |tool_path, input_path, output_path|
33
+ args = [tool_path, '--base', Platform.native_path(base_dir)]
34
+ if format == :svg
35
+ args << '--header'
36
+ end
37
+
38
+ args << Platform.native_path(input_path)
39
+ args << Platform.native_path(output_path)
40
+ end
41
+ end
42
+ end
43
+
44
+ class VegaBlockProcessor < Extensions::DiagramBlockProcessor
45
+ include Vega
46
+ end
47
+
48
+ class VegaBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
49
+ include Vega
50
+ end
51
+ end
52
+ end
@@ -1,5 +1,5 @@
1
1
  module Asciidoctor
2
2
  module Diagram
3
- VERSION = "1.5.8"
3
+ VERSION = "1.5.9"
4
4
  end
5
5
  end
data/spec/a2s_spec.rb ADDED
@@ -0,0 +1,167 @@
1
+ require_relative 'test_helper'
2
+
3
+ code = <<-eos
4
+ .--. .---. .---. .---. .---. .---. .---.
5
+ | | OS API '---' '---' '---' '---' '---' '---'
6
+ v | | | | | | |
7
+ .-. .-. .-. | v v | v | v
8
+ .-->'-' '-' '-' | .------------. | .-----------. | .-----.
9
+ | \\ | / | | Filesystem | | | Scheduler | | | MMU |
10
+ | v . v | '------------' | '-----------' | '-----'
11
+ '_______/ \\_____| | | | |
12
+ \\ / v | | v
13
+ | ____ .----. | | .---------.
14
+ '--> /___/ | IO |<----' | | Network |
15
+ '----' | '---------'
16
+ | | |
17
+ v v v
18
+ .---------------------------------------.
19
+ | HAL |
20
+ '---------------------------------------'
21
+ eos
22
+
23
+ describe Asciidoctor::Diagram::AsciiToSvgBlockMacroProcessor, :broken_on_travis, :broken_on_windows do
24
+ it "should generate SVG images when format is set to 'svg'" do
25
+ File.write('a2s.txt', code)
26
+
27
+ doc = <<-eos
28
+ = Hello, a2s!
29
+ Doc Writer <doc@example.com>
30
+
31
+ == First Section
32
+
33
+ a2s::a2s.txt[format="svg"]
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
+ describe Asciidoctor::Diagram::AsciiToSvgBlockProcessor, :broken_on_travis, :broken_on_windows do
55
+ it "should generate SVG images when format is set to 'svg'" do
56
+ doc = <<-eos
57
+ = Hello, a2s!
58
+ Doc Writer <doc@example.com>
59
+
60
+ == First Section
61
+
62
+ [a2s, format="svg"]
63
+ ----
64
+ #{code}
65
+ ----
66
+ eos
67
+
68
+ d = load_asciidoc doc
69
+ expect(d).to_not be_nil
70
+
71
+ b = d.find { |bl| bl.context == :image }
72
+ expect(b).to_not be_nil
73
+
74
+ expect(b.content_model).to eq :empty
75
+
76
+ target = b.attributes['target']
77
+ expect(target).to_not be_nil
78
+ expect(target).to match(/\.svg/)
79
+ expect(File.exist?(target)).to be true
80
+
81
+ expect(b.attributes['width']).to_not be_nil
82
+ expect(b.attributes['height']).to_not be_nil
83
+ end
84
+
85
+ it "should raise an error when when format is set to an invalid value" do
86
+ doc = <<-eos
87
+ = Hello, a2s!
88
+ Doc Writer <doc@example.com>
89
+
90
+ == First Section
91
+
92
+ [a2s, format="foobar"]
93
+ ----
94
+ ----
95
+ eos
96
+
97
+ expect { load_asciidoc doc }.to raise_error(/support.*format/i)
98
+ end
99
+
100
+ it "should not regenerate images when source has not changed" do
101
+ File.write('a2s.txt', code)
102
+
103
+ doc = <<-eos
104
+ = Hello, a2s!
105
+ Doc Writer <doc@example.com>
106
+
107
+ == First Section
108
+
109
+ a2s::a2s.txt
110
+
111
+ [a2s]
112
+ ----
113
+ #{code}
114
+ ----
115
+ eos
116
+
117
+ d = load_asciidoc doc
118
+ b = d.find { |bl| bl.context == :image }
119
+ expect(b).to_not be_nil
120
+ target = b.attributes['target']
121
+ mtime1 = File.mtime(target)
122
+
123
+ sleep 1
124
+
125
+ d = load_asciidoc doc
126
+
127
+ mtime2 = File.mtime(target)
128
+
129
+ expect(mtime2).to eq mtime1
130
+ end
131
+
132
+ it "should handle two block macros with the same source" do
133
+ File.write('a2s.txt', code)
134
+
135
+ doc = <<-eos
136
+ = Hello, a2s!
137
+ Doc Writer <doc@example.com>
138
+
139
+ == First Section
140
+
141
+ a2s::a2s.txt[]
142
+ a2s::a2s.txt[]
143
+ eos
144
+
145
+ load_asciidoc doc
146
+ expect(File.exist?('a2s.svg')).to be true
147
+ end
148
+
149
+ it "should respect target attribute in block macros" do
150
+ File.write('a2s.txt', code)
151
+
152
+ doc = <<-eos
153
+ = Hello, a2s!
154
+ Doc Writer <doc@example.com>
155
+
156
+ == First Section
157
+
158
+ a2s::a2s.txt["foobar"]
159
+ a2s::a2s.txt["foobaz"]
160
+ eos
161
+
162
+ load_asciidoc doc
163
+ expect(File.exist?('foobar.svg')).to be true
164
+ expect(File.exist?('foobaz.svg')).to be true
165
+ expect(File.exist?('a2s.svg')).to be false
166
+ end
167
+ end
data/spec/test_helper.rb CHANGED
@@ -6,6 +6,7 @@ require 'stringio'
6
6
  require 'tmpdir'
7
7
 
8
8
  require_relative '../lib/asciidoctor-diagram'
9
+ require_relative '../lib/asciidoctor-diagram/a2s/extension'
9
10
  require_relative '../lib/asciidoctor-diagram/blockdiag/extension'
10
11
  require_relative '../lib/asciidoctor-diagram/ditaa/extension'
11
12
  require_relative '../lib/asciidoctor-diagram/erd/extension'
@@ -18,6 +19,7 @@ require_relative '../lib/asciidoctor-diagram/shaape/extension'
18
19
  require_relative '../lib/asciidoctor-diagram/svgbob/extension'
19
20
  require_relative '../lib/asciidoctor-diagram/syntrax/extension'
20
21
  require_relative '../lib/asciidoctor-diagram/umlet/extension'
22
+ require_relative '../lib/asciidoctor-diagram/vega/extension'
21
23
  require_relative '../lib/asciidoctor-diagram/wavedrom/extension'
22
24
 
23
25
  require_relative '../lib/asciidoctor-diagram/util/platform'
data/spec/vega_spec.rb ADDED
@@ -0,0 +1,241 @@
1
+ require_relative 'test_helper'
2
+
3
+ vega_code = <<-eos
4
+ {
5
+ "$schema": "https://vega.github.io/schema/vega/v3.json",
6
+ "width": 400,
7
+ "height": 200,
8
+ "padding": 5,
9
+
10
+ "data": [
11
+ {
12
+ "name": "table",
13
+ "values": [
14
+ {"category": "A", "amount": 28},
15
+ {"category": "B", "amount": 55},
16
+ {"category": "C", "amount": 43},
17
+ {"category": "D", "amount": 91},
18
+ {"category": "E", "amount": 81},
19
+ {"category": "F", "amount": 53},
20
+ {"category": "G", "amount": 19},
21
+ {"category": "H", "amount": 87}
22
+ ]
23
+ }
24
+ ],
25
+
26
+ "signals": [
27
+ {
28
+ "name": "tooltip",
29
+ "value": {},
30
+ "on": [
31
+ {"events": "rect:mouseover", "update": "datum"},
32
+ {"events": "rect:mouseout", "update": "{}"}
33
+ ]
34
+ }
35
+ ],
36
+
37
+ "scales": [
38
+ {
39
+ "name": "xscale",
40
+ "type": "band",
41
+ "domain": {"data": "table", "field": "category"},
42
+ "range": "width",
43
+ "padding": 0.05,
44
+ "round": true
45
+ },
46
+ {
47
+ "name": "yscale",
48
+ "domain": {"data": "table", "field": "amount"},
49
+ "nice": true,
50
+ "range": "height"
51
+ }
52
+ ],
53
+
54
+ "axes": [
55
+ { "orient": "bottom", "scale": "xscale" },
56
+ { "orient": "left", "scale": "yscale" }
57
+ ],
58
+
59
+ "marks": [
60
+ {
61
+ "type": "rect",
62
+ "from": {"data":"table"},
63
+ "encode": {
64
+ "enter": {
65
+ "x": {"scale": "xscale", "field": "category"},
66
+ "width": {"scale": "xscale", "band": 1},
67
+ "y": {"scale": "yscale", "field": "amount"},
68
+ "y2": {"scale": "yscale", "value": 0}
69
+ },
70
+ "update": {
71
+ "fill": {"value": "steelblue"}
72
+ },
73
+ "hover": {
74
+ "fill": {"value": "red"}
75
+ }
76
+ }
77
+ },
78
+ {
79
+ "type": "text",
80
+ "encode": {
81
+ "enter": {
82
+ "align": {"value": "center"},
83
+ "baseline": {"value": "bottom"},
84
+ "fill": {"value": "#333"}
85
+ },
86
+ "update": {
87
+ "x": {"scale": "xscale", "signal": "tooltip.category", "band": 0.5},
88
+ "y": {"scale": "yscale", "signal": "tooltip.amount", "offset": -2},
89
+ "text": {"signal": "tooltip.amount"},
90
+ "fillOpacity": [
91
+ {"test": "datum === tooltip", "value": 0},
92
+ {"value": 1}
93
+ ]
94
+ }
95
+ }
96
+ }
97
+ ]
98
+ }
99
+ eos
100
+
101
+ vegalite_code = <<-eos
102
+ {
103
+ "$schema": "https://vega.github.io/schema/vega-lite/v2.json",
104
+ "description": "A simple bar chart with embedded data.",
105
+ "data": {
106
+ "values": [
107
+ {"a": "A","b": 28}, {"a": "B","b": 55}, {"a": "C","b": 43},
108
+ {"a": "D","b": 91}, {"a": "E","b": 81}, {"a": "F","b": 53},
109
+ {"a": "G","b": 19}, {"a": "H","b": 87}, {"a": "I","b": 52}
110
+ ]
111
+ },
112
+ "mark": "bar",
113
+ "encoding": {
114
+ "x": {"field": "a", "type": "ordinal"},
115
+ "y": {"field": "b", "type": "quantitative"}
116
+ }
117
+ }
118
+ eos
119
+
120
+ describe Asciidoctor::Diagram::VegaBlockMacroProcessor, :broken_on_windows do
121
+ it "should generate vega SVG images when format omitted" do
122
+ File.write('vega.json', vega_code)
123
+
124
+ doc = <<-eos
125
+ = Hello, Vega!
126
+ Doc Writer <doc@example.com>
127
+
128
+ == First Section
129
+
130
+ vega::vega.json[]
131
+ eos
132
+
133
+ d = load_asciidoc doc
134
+ expect(d).to_not be_nil
135
+
136
+ b = d.find { |bl| bl.context == :image }
137
+ expect(b).to_not be_nil
138
+
139
+ expect(b.content_model).to eq :empty
140
+
141
+ target = b.attributes['target']
142
+ expect(target).to_not be_nil
143
+ expect(target).to match(/\.svg$/)
144
+ expect(File.exist?(target)).to be true
145
+
146
+ expect(b.attributes['width']).to_not be_nil
147
+ expect(b.attributes['height']).to_not be_nil
148
+ end
149
+
150
+ it "should generate vegalite SVG images when format omitted" do
151
+ File.write('vega.json', vegalite_code)
152
+
153
+ doc = <<-eos
154
+ = Hello, Vega!
155
+ Doc Writer <doc@example.com>
156
+
157
+ == First Section
158
+
159
+ vegalite::vega.json[]
160
+ eos
161
+
162
+ d = load_asciidoc doc
163
+ expect(d).to_not be_nil
164
+
165
+ b = d.find { |bl| bl.context == :image }
166
+ expect(b).to_not be_nil
167
+
168
+ expect(b.content_model).to eq :empty
169
+
170
+ target = b.attributes['target']
171
+ expect(target).to_not be_nil
172
+ expect(target).to match(/\.svg$/)
173
+ expect(File.exist?(target)).to be true
174
+
175
+ expect(b.attributes['width']).to_not be_nil
176
+ expect(b.attributes['height']).to_not be_nil
177
+ end
178
+ end
179
+
180
+
181
+ describe Asciidoctor::Diagram::VegaBlockProcessor, :broken_on_windows do
182
+ it "should generate vega SVG images when format is omitted" do
183
+ doc = <<-eos
184
+ = Hello, Vega!
185
+ Doc Writer <doc@example.com>
186
+
187
+ == First Section
188
+
189
+ [vega]
190
+ ----
191
+ #{vega_code}
192
+ ----
193
+ eos
194
+
195
+ d = load_asciidoc doc
196
+ expect(d).to_not be_nil
197
+
198
+ b = d.find { |bl| bl.context == :image }
199
+ expect(b).to_not be_nil
200
+
201
+ expect(b.content_model).to eq :empty
202
+
203
+ target = b.attributes['target']
204
+ expect(target).to_not be_nil
205
+ expect(target).to match(/\.svg$/)
206
+ expect(File.exist?(target)).to be true
207
+
208
+ expect(b.attributes['width']).to_not be_nil
209
+ expect(b.attributes['height']).to_not be_nil
210
+ end
211
+
212
+ it "should generate vegalite SVG images when format is omitted" do
213
+ doc = <<-eos
214
+ = Hello, Vega!
215
+ Doc Writer <doc@example.com>
216
+
217
+ == First Section
218
+
219
+ [vegalite]
220
+ ----
221
+ #{vegalite_code}
222
+ ----
223
+ eos
224
+
225
+ d = load_asciidoc doc
226
+ expect(d).to_not be_nil
227
+
228
+ b = d.find { |bl| bl.context == :image }
229
+ expect(b).to_not be_nil
230
+
231
+ expect(b.content_model).to eq :empty
232
+
233
+ target = b.attributes['target']
234
+ expect(target).to_not be_nil
235
+ expect(target).to match(/\.svg$/)
236
+ expect(File.exist?(target)).to be true
237
+
238
+ expect(b.attributes['width']).to_not be_nil
239
+ expect(b.attributes['height']).to_not be_nil
240
+ end
241
+ 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.8
4
+ version: 1.5.9
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: 2018-02-24 00:00:00.000000000 Z
11
+ date: 2018-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,6 +85,8 @@ files:
85
85
  - images/asciidoctor-diagram-classes.png
86
86
  - images/asciidoctor-diagram-process.png
87
87
  - lib/asciidoctor-diagram.rb
88
+ - lib/asciidoctor-diagram/a2s.rb
89
+ - lib/asciidoctor-diagram/a2s/extension.rb
88
90
  - lib/asciidoctor-diagram/blockdiag.rb
89
91
  - lib/asciidoctor-diagram/blockdiag/extension.rb
90
92
  - lib/asciidoctor-diagram/ditaa.rb
@@ -123,6 +125,8 @@ files:
123
125
  - lib/asciidoctor-diagram/util/png.rb
124
126
  - lib/asciidoctor-diagram/util/svg.rb
125
127
  - lib/asciidoctor-diagram/util/which.rb
128
+ - lib/asciidoctor-diagram/vega.rb
129
+ - lib/asciidoctor-diagram/vega/extension.rb
126
130
  - lib/asciidoctor-diagram/version.rb
127
131
  - lib/asciidoctor-diagram/wavedrom.rb
128
132
  - lib/asciidoctor-diagram/wavedrom/extension.rb
@@ -133,6 +137,7 @@ files:
133
137
  - lib/plantuml-1.3.13.jar
134
138
  - lib/plantuml.jar
135
139
  - lib/server-1.3.13.jar
140
+ - spec/a2s_spec.rb
136
141
  - spec/blockdiag_spec.rb
137
142
  - spec/ditaa_spec.rb
138
143
  - spec/erd_spec.rb
@@ -147,6 +152,7 @@ files:
147
152
  - spec/syntrax_spec.rb
148
153
  - spec/test_helper.rb
149
154
  - spec/umlet_spec.rb
155
+ - spec/vega_spec.rb
150
156
  - spec/wavedrom_spec.rb
151
157
  homepage: https://github.com/asciidoctor/asciidoctor-diagram
152
158
  licenses:
@@ -174,6 +180,7 @@ specification_version: 4
174
180
  summary: An extension for asciidoctor that adds support for UML diagram generation
175
181
  using PlantUML
176
182
  test_files:
183
+ - spec/a2s_spec.rb
177
184
  - spec/blockdiag_spec.rb
178
185
  - spec/ditaa_spec.rb
179
186
  - spec/erd_spec.rb
@@ -188,4 +195,5 @@ test_files:
188
195
  - spec/syntrax_spec.rb
189
196
  - spec/test_helper.rb
190
197
  - spec/umlet_spec.rb
198
+ - spec/vega_spec.rb
191
199
  - spec/wavedrom_spec.rb