asciidoctor-diagram 2.0.1 → 2.0.2

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
  SHA256:
3
- metadata.gz: 2c23479ec496e71fd006564fec4e1ca6cf88bd09ae730437e39e3d2dab6554c8
4
- data.tar.gz: 583614138465d13c09a0134a888ecb513b27e9040d1d946fd62038c1421cfaf3
3
+ metadata.gz: '09488e585ecab52e38188d04020d60aa17873bea47c3043055f8f59770f9d1aa'
4
+ data.tar.gz: ab9eab53cc00fc988ccd4518ac62e91f815ea06cfc3d3615824a24d63efb07a7
5
5
  SHA512:
6
- metadata.gz: 92fdb3bcfbf238bbcfc13f2ea84b5441c9db60c98e053bef529487351c82fb07192d44304661fd1ede94fa3286923029bb3e93f72c5bb5ffd3a8f8cbeda2227e
7
- data.tar.gz: bc7a9000e2ae1beeed9e61d538938241b6401a5aa4cff8bb5b9d15f8fe8dd7c4991b58ea326677feaf9f6e72f20c72961ce1286c53ed0704e5d48af102ad99e7
6
+ metadata.gz: 7e75194b60961b932b7ca141448948c92404db4557b83611c28786de97fb7b36e30d434189815729a4aab79620dd6a1e90d7eb0281c1a5a3a66356730f319892
7
+ data.tar.gz: d7b8c2f8d8678e6299dd309292cc524d704830d6a882ae9228620d466862f0e37c9b1540a57090641f04f3499fcfcbf46f08933febfaa0dbb15579d33c3d1c64
@@ -1,5 +1,21 @@
1
1
  = Asciidoctor-diagram Changelog
2
2
 
3
+ == 2.0.2
4
+
5
+ Enhancements::
6
+
7
+ * #260: Update PlantUML to v1.2020.6
8
+ * #270: Add support for svgbob options (@hackingotter)
9
+ * #268: Changing diagram attribute values will now also trigger image regeneration
10
+ * #276: Add support for bytefield-svg
11
+
12
+ Bug Fixes::
13
+
14
+ * Issue #253: Add support for PlantUML `atxt` and `utxt` output formats
15
+ * Issue #266: Resolve execution issue when the path for GnuPlot or Vega contains spaces
16
+ * Issue #267: Use binary mode when reading generated images from stdout
17
+ * Issue #273: Report Ditaa syntax errors correctly
18
+
3
19
  == 2.0.1
4
20
 
5
21
  Bug Fixes::
@@ -19,6 +19,7 @@ ifndef::env-site[:status:]
19
19
  :uri-asciidoctor-extensions: http://asciidoctor.org/docs/user-manual/#extension-points
20
20
  :uri-blockdiag: http://blockdiag.com
21
21
  :uri-bpmn: https://github.com/gtudan/bpmn-js-cmd
22
+ :uri-bytefield: https://github.com/Deep-Symmetry/bytefield-svg
22
23
  :uri-ditaa: http://ditaa.sourceforge.net/
23
24
  :uri-dot: https://graphviz.gitlab.io/_pages/doc/info/lang.html
24
25
  :uri-erd: https://github.com/BurntSushi/erd
@@ -49,7 +50,7 @@ ifndef::env-site[:status:]
49
50
 
50
51
  Asciidoctor Diagram is a set of Asciidoctor extensions that enable you to add diagrams, which you describe using plain text, to your AsciiDoc document.
51
52
 
52
- 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-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.
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.
53
54
 
54
55
  Each extension runs the diagram processor to generate an SVG, PNG, or TXT file from the input text.
55
56
  The generated file is then inserted into your converted document.
@@ -123,6 +124,7 @@ The following diagram types and output formats are available:
123
124
  |{uri-actdiag}[actdiag] | |{check}|{check}|{check}|
124
125
  |{uri-blockdiag}[blockdiag] | |{check}|{check}|{check}|
125
126
  |{uri-bpmn}[bpmn] | |{check}|{check}|{check}|
127
+ |{uri-bytefield}[bytefield] | | | |{check}|
126
128
  |{uri-ditaa}[ditaa] | | |{check}|{check}|
127
129
  |{uri-erd}[erd] | | |{check}|{check}|
128
130
  |{uri-gnuplot}[gnuplot] |{check}| |{check}|{check}|{check}
@@ -255,7 +257,7 @@ or load and register each extension individually.
255
257
  require 'asciidoctor-diagram/<extension_name>'
256
258
  ----
257
259
 
258
- `<extension_name>` can be one of `a2s`, `blockdiag`, `ditaa`, `erd`, `gnuplot`, `graphviz`, `meme`, `mermaid`, `msc`, `plantuml`, `shaape`, `smcat`, `svgbob`, `syntrax`, `umlet`, `vega` or `wavedrom`.
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`.
259
261
 
260
262
  Requiring one or more of these files will automatically register the extensions for all processed documents.
261
263
 
@@ -302,6 +304,7 @@ The following table lists the tools that are required for each diagram type, the
302
304
  |actdiag |{uri-actdiag}[ActDiag] |`actdiag`
303
305
  |blockdiag |{uri-blockdiag}[BlockDiag] |`blockdiag`
304
306
  |bpmn |{uri-bpmn}[bpmn-js-cmd] |`bpmn`
307
+ |bytefield |{uri-bytefield}[bytefield-svg] |`bytefield-svg`
305
308
  |ditaa |{uri-java}[Java] |`java`
306
309
  |erd |{uri-erd}[Erd] |`erd`
307
310
  |gnuplot |{uri-gnuplot}[Gnuplot] |`gnuplot`
@@ -497,6 +500,17 @@ The attribute name at the block level should be prefixed with the name of the di
497
500
  |engine |unspecified |The layout engine to use. One of `dot`, `circo`, `fdp`, `neato`, `osage`, or `twopi`
498
501
  |===
499
502
 
503
+ ==== svgbob
504
+
505
+ [cols=">,<,<",options="header"]
506
+ |===
507
+ |Name |Default value |Description
508
+ |font-family |arial |text will be rendered with this font
509
+ |font-size |14 |text will be rendered with this font size
510
+ |scale |1 |scale the entire svg (dimensions, font size, stroke width) by this factor
511
+ |stroke-width |2 |stroke width for all lines
512
+ |===
513
+
500
514
  ==== Syntrax
501
515
 
502
516
  [cols=">,<,<",options="header"]
@@ -1,6 +1,7 @@
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'
5
6
  require_relative 'asciidoctor-diagram/erd'
6
7
  require_relative 'asciidoctor-diagram/gnuplot'
@@ -29,7 +29,7 @@ module Asciidoctor
29
29
 
30
30
  opts[:width] = options[:width]
31
31
 
32
- bpmnjs = source.find_command('bpmn-js', :raise_on_error => false)
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,7 @@
1
+ require 'asciidoctor/extensions'
2
+ require_relative 'bytefield/extension'
3
+
4
+ Asciidoctor::Extensions.register do
5
+ block Asciidoctor::Diagram::BytefieldBlockProcessor, :bytefield
6
+ block_macro Asciidoctor::Diagram::BytefieldBlockMacroProcessor, :bytefield
7
+ end
@@ -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
@@ -151,14 +151,15 @@ module Asciidoctor
151
151
  metadata_file = parent.normalize_system_path "#{image_name}.cache", cache_dir
152
152
 
153
153
  if File.exist? metadata_file
154
- metadata = File.open(metadata_file, 'r') {|f| JSON.load f}
154
+ metadata = File.open(metadata_file, 'r') {|f| JSON.load(f, nil, :symbolize_names => true, :create_additions => false) }
155
155
  else
156
156
  metadata = {}
157
157
  end
158
158
 
159
159
  image_attributes = source.attributes
160
+ options = converter.collect_options(source, name)
160
161
 
161
- if !File.exist?(image_file) || source.should_process?(image_file, metadata)
162
+ if !File.exist?(image_file) || source.should_process?(image_file, metadata) || options != metadata[:options]
162
163
  params = IMAGE_PARAMS[format]
163
164
 
164
165
  server_url = source.attr('server-url', nil, name) || source.attr('server-url', nil, DIAGRAM_PREFIX)
@@ -173,7 +174,8 @@ module Asciidoctor
173
174
  result.force_encoding(params[:encoding])
174
175
 
175
176
  metadata = source.create_image_metadata
176
- metadata['width'], metadata['height'] = params[:decoder].get_image_size(result)
177
+ metadata[:options] = options
178
+ metadata[:width], metadata[:height] = params[:decoder].get_image_size(result)
177
179
 
178
180
  FileUtils.mkdir_p(File.dirname(image_file)) unless Dir.exist?(File.dirname(image_file))
179
181
  File.open(image_file, 'wb') {|f| f.write result}
@@ -197,11 +199,11 @@ module Asciidoctor
197
199
 
198
200
  if /html/i =~ parent.document.attributes['backend']
199
201
  image_attributes.delete('scale')
200
- if metadata['width'] && !image_attributes['width']
201
- image_attributes['width'] = (metadata['width'] * scale_factor).to_i
202
+ if metadata[:width] && !image_attributes['width']
203
+ image_attributes['width'] = (metadata[:width] * scale_factor).to_i
202
204
  end
203
- if metadata['height'] && !image_attributes['height']
204
- image_attributes['height'] = (metadata['height'] * scale_factor).to_i
205
+ if metadata[:height] && !image_attributes['height']
206
+ image_attributes['height'] = (metadata[:height] * scale_factor).to_i
205
207
  end
206
208
  end
207
209
 
@@ -143,11 +143,11 @@ module Asciidoctor
143
143
  end
144
144
 
145
145
  def should_process?(image_file, image_metadata)
146
- image_metadata['checksum'] != checksum
146
+ image_metadata[:checksum] != checksum
147
147
  end
148
148
 
149
149
  def create_image_metadata
150
- {'checksum' => checksum}
150
+ {:checksum => checksum}
151
151
  end
152
152
 
153
153
  def checksum
@@ -23,7 +23,7 @@ module Asciidoctor
23
23
  :transparent => lambda { |o, v| o << '--transparent' if v == 'true'}
24
24
  }
25
25
 
26
- JARS = ['ditaa-1.3.14.jar', 'ditaamini-0.12.jar'].map do |jar|
26
+ JARS = ['ditaa-1.3.15.jar', 'ditaamini-0.12.jar'].map do |jar|
27
27
  File.expand_path File.join('../..', jar), File.dirname(__FILE__)
28
28
  end
29
29
  Java.classpath.concat JARS
@@ -42,8 +42,8 @@ module Asciidoctor
42
42
 
43
43
  bg_img = source.resolve_path(bg_img, source.attr('imagesdir'))
44
44
 
45
- top_label = options[:top]
46
- bottom_label = options[:bottom]
45
+ top_label = options[:top_label]
46
+ bottom_label = options[:bottom_label]
47
47
  fill_color = options[:fill_color] || 'white'
48
48
  stroke_color = options[:stroke_color] || 'black'
49
49
  stroke_width = options[:stroke_width] || '2'
@@ -8,7 +8,7 @@ module Asciidoctor
8
8
  include DiagramConverter
9
9
 
10
10
  JARS = [
11
- 'plantuml-1.3.14.jar',
11
+ 'plantuml-1.3.15.jar',
12
12
  'plantuml.jar',
13
13
  'jlatexmath-minimal-1.0.5.jar',
14
14
  'batik-all-1.10.jar'
@@ -40,7 +40,7 @@ module Asciidoctor
40
40
  when :txt, :utxt
41
41
  mime_type = 'text/plain;charset=utf-8'
42
42
  when :atxt
43
- mime_type = 'text/plain;charset=us-ascii'
43
+ mime_type = 'text/plain'
44
44
  else
45
45
  raise "Unsupported format: #{format}"
46
46
  end
@@ -14,10 +14,34 @@ module Asciidoctor
14
14
  [:svg]
15
15
  end
16
16
 
17
+ OPTIONS = {
18
+ :font_family => lambda { |o, v| o << '--font-family' << v if v },
19
+ :font_size => lambda { |o, v| o << '--font-size' << v if v },
20
+ :stroke_width => lambda { |o, v| o << '--stroke-width' << v if v },
21
+ :scale => lambda { |o, v| o << '--scale' << v if v }
22
+ }
23
+
24
+ def collect_options(source, name)
25
+ options = {}
26
+
27
+ OPTIONS.keys.each do |option|
28
+ attr_name = option.to_s.tr('_', '-')
29
+ options[option] = source.attr(attr_name, nil, name) || source.attr(attr_name, nil, 'svgbob-option')
30
+ end
31
+
32
+ options
33
+ end
34
+
17
35
 
18
36
  def convert(source, format, options)
37
+
38
+ flags = []
39
+ options.each do |option, value|
40
+ OPTIONS[option].call(flags, value)
41
+ end
42
+
19
43
  generate_stdin(source.find_command('svgbob'), format.to_s, source.to_s) do |tool_path, output_path|
20
- [tool_path, '-o', Platform.native_path(output_path)]
44
+ ([tool_path, '-o', Platform.native_path(output_path)] + flags)
21
45
  end
22
46
  end
23
47
  end
@@ -9,7 +9,7 @@ module Asciidoctor
9
9
  require_relative 'java'
10
10
 
11
11
  def self.run(*args)
12
- opts = args.pop if args.last.is_a? Hash
12
+ opts = args.pop.dup if args.last.is_a? Hash
13
13
  in_data = opts && opts[:stdin_data]
14
14
 
15
15
  pb = java.lang.ProcessBuilder.new(*args)
@@ -61,12 +61,23 @@ module Asciidoctor
61
61
  require 'open3'
62
62
 
63
63
  def self.run(*args)
64
- stdout, stderr, status = Open3.capture3(*args)
64
+ if Hash === args.last
65
+ opts = args.pop.dup
66
+ else
67
+ opts = {}
68
+ end
69
+
70
+ # When the first argument is an array, we force capture3 (or better the underlying Kernel#spawn)
71
+ # to use a non-shell execution variant.
72
+ cmd = File.basename(args[0])
73
+ args[0] = [args[0], cmd]
74
+
75
+ stdout, stderr, status = Open3.capture3(*args, opts)
65
76
 
66
77
  exit = status.exitstatus
67
78
 
68
79
  if exit != 0
69
- raise "#{File.basename(args[0])} failed: #{stdout.empty? ? stderr : stdout}"
80
+ raise "#{cmd} failed: #{stdout.empty? ? stderr : stdout}"
70
81
  end
71
82
 
72
83
  {
@@ -26,7 +26,7 @@ module Asciidoctor
26
26
  else
27
27
  opts = [tool]
28
28
  end
29
- generate(opts, :stdout, :stdin_data => code)
29
+ generate(opts, :stdout, :stdin_data => code, :binmode => true)
30
30
  end
31
31
 
32
32
  def generate_file(tool, input_ext, output_ext, code)
@@ -6,7 +6,7 @@ module Asciidoctor
6
6
  module Java
7
7
  def self.classpath
8
8
  @classpath ||= [
9
- File.expand_path(File.join('../..', 'server-1.3.14.jar'), File.dirname(__FILE__))
9
+ File.expand_path(File.join('../..', 'server-1.3.15.jar'), File.dirname(__FILE__))
10
10
  ]
11
11
  end
12
12
 
@@ -1,5 +1,5 @@
1
1
  module Asciidoctor
2
2
  module Diagram
3
- VERSION = "2.0.1"
3
+ VERSION = "2.0.2"
4
4
  end
5
5
  end
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,230 @@
1
+ require_relative 'test_helper'
2
+
3
+ code = <<-eos
4
+ ;; This the source for the sample diagram illustrated in the project Read Me.
5
+
6
+ ;; Some nice default background colors, used to distinguish header sections.
7
+ (defattrs :bg-green {:fill "#a0ffa0"})
8
+ (defattrs :bg-yellow {:fill "#ffffa0"})
9
+ (defattrs :bg-pink {:fill "#ffb0a0"})
10
+ (defattrs :bg-cyan {:fill "#a0fafa"})
11
+ (defattrs :bg-purple {:fill "#e4b5f7"})
12
+
13
+ (defn draw-group-label-header
14
+ "Creates a small borderless box used to draw the textual label headers
15
+ used below the byte labels for remotedb message diagrams.
16
+ Arguments are the number of colums to span and the text of the
17
+ label."
18
+ [span label]
19
+ (draw-box (text label [:math {:font-size 12}]) {:span span
20
+ :borders \#{}
21
+ :height 14}))
22
+
23
+ (defn draw-remotedb-header
24
+ "Generates the byte and field labels and standard header fields of a
25
+ request or response message for the remotedb database server with
26
+ the specified kind and args values."
27
+ [kind args]
28
+ (draw-column-headers)
29
+ (draw-group-label-header 5 "start")
30
+ (draw-group-label-header 5 "TxID")
31
+ (draw-group-label-header 3 "type")
32
+ (draw-group-label-header 2 "args")
33
+ (draw-group-label-header 1 "tags")
34
+ (next-row 18)
35
+
36
+ (draw-box 0x11 :bg-green)
37
+ (draw-box 0x872349ae [{:span 4} :bg-green])
38
+ (draw-box 0x11 :bg-yellow)
39
+ (draw-box (text "TxID" :math) [{:span 4} :bg-yellow])
40
+ (draw-box 0x10 :bg-pink)
41
+ (draw-box (hex-text kind 4 :bold) [{:span 2} :bg-pink])
42
+ (draw-box 0x0f :bg-cyan)
43
+ (draw-box (hex-text args 2 :bold) :bg-cyan)
44
+ (draw-box 0x14 :bg-purple)
45
+
46
+ (draw-box (text "0000000c" :hex [[:plain {:font-weight "light" :font-size 16}] " (12)"])
47
+ [{:span 4} :bg-purple])
48
+ (draw-box (hex-text 6 2 :bold) [:box-first :bg-purple])
49
+ (doseq [val [6 6 3 6 6 6 6 3]]
50
+ (draw-box (hex-text val 2 :bold) [:box-related :bg-purple]))
51
+ (doseq [val [0 0]]
52
+ (draw-box val [:box-related :bg-purple]))
53
+ (draw-box 0 [:box-last :bg-purple]))
54
+
55
+ ;; Figure 48: Cue point response message.
56
+
57
+ (draw-remotedb-header 0x4702 9)
58
+
59
+ (draw-box 0x11)
60
+ (draw-box 0x2104 {:span 4})
61
+ (draw-box 0x11)
62
+ (draw-box 0 {:span 4})
63
+ (draw-box 0x11)
64
+ (draw-box (text "length" [:math] [:sub 1]) {:span 4})
65
+ (draw-box 0x14)
66
+
67
+ (draw-box (text "length" [:math] [:sub 1]) {:span 4})
68
+ (draw-gap "Cue and loop point bytes")
69
+
70
+ (draw-box nil :box-below)
71
+ (draw-box 0x11)
72
+ (draw-box 0x36 {:span 4})
73
+ (draw-box 0x11)
74
+ (draw-box (text "num" [:math] [:sub "hot"]) {:span 4})
75
+ (draw-box 0x11)
76
+ (draw-box (text "num" [:math] [:sub "cue"]) {:span 4})
77
+
78
+ (draw-box 0x11)
79
+ (draw-box (text "length" [:math] [:sub 2]) {:span 4})
80
+ (draw-box 0x14)
81
+ (draw-box (text "length" [:math] [:sub 2]) {:span 4})
82
+ (draw-gap "Unknown bytes" {:min-label-columns 6})
83
+ (draw-bottom)
84
+ eos
85
+
86
+ describe Asciidoctor::Diagram::BytefieldBlockMacroProcessor, :broken_on_travis, :broken_on_windows do
87
+ it "should generate SVG images when format is set to 'svg'" do
88
+ File.write('bytefield.txt', code)
89
+
90
+ doc = <<-eos
91
+ = Hello, Bytefield!
92
+ Doc Writer <doc@example.com>
93
+
94
+ == First Section
95
+
96
+ bytefield::bytefield.txt[format="svg"]
97
+ eos
98
+
99
+ d = load_asciidoc doc
100
+ expect(d).to_not be_nil
101
+
102
+ b = d.find { |bl| bl.context == :image }
103
+ expect(b).to_not be_nil
104
+
105
+ expect(b.content_model).to eq :empty
106
+
107
+ target = b.attributes['target']
108
+ expect(target).to_not be_nil
109
+ expect(target).to match(/\.svg/)
110
+ expect(File.exist?(target)).to be true
111
+
112
+ expect(b.attributes['width']).to_not be_nil
113
+ expect(b.attributes['height']).to_not be_nil
114
+ end
115
+ end
116
+
117
+ describe Asciidoctor::Diagram::BytefieldBlockProcessor, :broken_on_travis, :broken_on_windows do
118
+ it "should generate SVG images when format is set to 'svg'" do
119
+ doc = <<-eos
120
+ = Hello, Bytefield!
121
+ Doc Writer <doc@example.com>
122
+
123
+ == First Section
124
+
125
+ [bytefield, format="svg"]
126
+ ----
127
+ #{code}
128
+ ----
129
+ eos
130
+
131
+ d = load_asciidoc doc
132
+ expect(d).to_not be_nil
133
+
134
+ b = d.find { |bl| bl.context == :image }
135
+ expect(b).to_not be_nil
136
+
137
+ expect(b.content_model).to eq :empty
138
+
139
+ target = b.attributes['target']
140
+ expect(target).to_not be_nil
141
+ expect(target).to match(/\.svg/)
142
+ expect(File.exist?(target)).to be true
143
+
144
+ expect(b.attributes['width']).to_not be_nil
145
+ expect(b.attributes['height']).to_not be_nil
146
+ end
147
+
148
+ it "should raise an error when when format is set to an invalid value" do
149
+ doc = <<-eos
150
+ = Hello, Bytefield!
151
+ Doc Writer <doc@example.com>
152
+
153
+ == First Section
154
+
155
+ [bytefield, format="foobar"]
156
+ ----
157
+ ----
158
+ eos
159
+
160
+ expect { load_asciidoc doc }.to raise_error(/support.*format/i)
161
+ end
162
+
163
+ it "should not regenerate images when source has not changed" do
164
+ File.write('bytefield.txt', code)
165
+
166
+ doc = <<-eos
167
+ = Hello, Bytefield!
168
+ Doc Writer <doc@example.com>
169
+
170
+ == First Section
171
+
172
+ bytefield::bytefield.txt
173
+
174
+ [bytefield, format="svg"]
175
+ ----
176
+ #{code}
177
+ ----
178
+ eos
179
+
180
+ d = load_asciidoc doc
181
+ b = d.find { |bl| bl.context == :image }
182
+ expect(b).to_not be_nil
183
+ target = b.attributes['target']
184
+ mtime1 = File.mtime(target)
185
+
186
+ sleep 1
187
+
188
+ d = load_asciidoc doc
189
+
190
+ mtime2 = File.mtime(target)
191
+
192
+ expect(mtime2).to eq mtime1
193
+ end
194
+
195
+ it "should handle two block macros with the same source" do
196
+ File.write('bytefield.txt', code)
197
+
198
+ doc = <<-eos
199
+ = Hello, Bytefield!
200
+ Doc Writer <doc@example.com>
201
+
202
+ == First Section
203
+
204
+ bytefield::bytefield.txt[]
205
+ bytefield::bytefield.txt[]
206
+ eos
207
+
208
+ load_asciidoc doc
209
+ expect(File.exist?('bytefield.svg')).to be true
210
+ end
211
+
212
+ it "should respect target attribute in block macros" do
213
+ File.write('bytefield.txt', code)
214
+
215
+ doc = <<-eos
216
+ = Hello, Bytefield!
217
+ Doc Writer <doc@example.com>
218
+
219
+ == First Section
220
+
221
+ bytefield::bytefield.txt["foobar"]
222
+ bytefield::bytefield.txt["foobaz"]
223
+ eos
224
+
225
+ load_asciidoc doc
226
+ expect(File.exist?('foobar.svg')).to be true
227
+ expect(File.exist?('foobaz.svg')).to be true
228
+ expect(File.exist?('bytefield.svg')).to be false
229
+ end
230
+ end
@@ -253,4 +253,36 @@ Doc Writer <doc@example.com>
253
253
  expect(b.attributes['width']).to_not be_nil
254
254
  expect(b.attributes['height']).to_not be_nil
255
255
  end
256
+
257
+ it "should report syntax errors" do
258
+ doc = <<-eos
259
+ = Hello, Ditaa!
260
+ Doc Writer <doc@example.com>
261
+
262
+ == First Section
263
+
264
+ [ditaa,format="svg"]
265
+ ----
266
+ This should cause a bug.
267
+
268
+ // TODO:
269
+ // - don't make bugs
270
+ // - oops I wrote a comment here
271
+
272
+ +--------+ +-------+ +-------+
273
+ | | --+ ditaa +--> | |
274
+ | Text | +-------+ |diagram|
275
+ |Document| |!magic!| | |
276
+ | {d}| | | | |
277
+ +---+----+ +-------+ +-------+
278
+ : ^
279
+ | Lots of work |
280
+ +-------------------------+
281
+ ----
282
+ eos
283
+
284
+ expect {
285
+ load_asciidoc doc
286
+ }.to raise_error(/Cannot follow cell/i)
287
+ end
256
288
  end
@@ -8,6 +8,7 @@ require 'tmpdir'
8
8
  require_relative '../lib/asciidoctor-diagram'
9
9
  require_relative '../lib/asciidoctor-diagram/a2s/extension'
10
10
  require_relative '../lib/asciidoctor-diagram/blockdiag/extension'
11
+ require_relative '../lib/asciidoctor-diagram/bytefield'
11
12
  require_relative '../lib/asciidoctor-diagram/ditaa/extension'
12
13
  require_relative '../lib/asciidoctor-diagram/erd/extension'
13
14
  require_relative '../lib/asciidoctor-diagram/gnuplot/extension'
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: 2.0.1
4
+ version: 2.0.2
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: 2020-01-08 00:00:00.000000000 Z
11
+ date: 2020-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,6 +100,9 @@ files:
100
100
  - lib/asciidoctor-diagram/bpmn.rb
101
101
  - lib/asciidoctor-diagram/bpmn/converter.rb
102
102
  - lib/asciidoctor-diagram/bpmn/extension.rb
103
+ - lib/asciidoctor-diagram/bytefield.rb
104
+ - lib/asciidoctor-diagram/bytefield/converter.rb
105
+ - lib/asciidoctor-diagram/bytefield/extension.rb
103
106
  - lib/asciidoctor-diagram/diagram_converter.rb
104
107
  - lib/asciidoctor-diagram/diagram_processor.rb
105
108
  - lib/asciidoctor-diagram/diagram_source.rb
@@ -174,16 +177,17 @@ files:
174
177
  - lib/asciidoctor-diagram/wavedrom/converter.rb
175
178
  - lib/asciidoctor-diagram/wavedrom/extension.rb
176
179
  - lib/batik-all-1.10.jar
177
- - lib/ditaa-1.3.14.jar
180
+ - lib/ditaa-1.3.15.jar
178
181
  - lib/ditaamini-0.12.jar
179
182
  - lib/jlatexmath-minimal-1.0.5.jar
180
- - lib/plantuml-1.3.14.jar
183
+ - lib/plantuml-1.3.15.jar
181
184
  - lib/plantuml.jar
182
- - lib/server-1.3.14.jar
185
+ - lib/server-1.3.15.jar
183
186
  - spec/a2s_spec.rb
184
187
  - spec/blockdiag_spec.rb
185
188
  - spec/bpmn-example.xml
186
189
  - spec/bpmn_spec.rb
190
+ - spec/bytefield_spec.rb
187
191
  - spec/ditaa_spec.rb
188
192
  - spec/erd_spec.rb
189
193
  - spec/gnuplot_spec.rb
@@ -234,6 +238,7 @@ test_files:
234
238
  - spec/blockdiag_spec.rb
235
239
  - spec/bpmn-example.xml
236
240
  - spec/bpmn_spec.rb
241
+ - spec/bytefield_spec.rb
237
242
  - spec/ditaa_spec.rb
238
243
  - spec/erd_spec.rb
239
244
  - spec/gnuplot_spec.rb
Binary file
Binary file
Binary file