asciidoctor-diagram 1.5.18 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +75 -0
  3. data/README.adoc +98 -23
  4. data/examples/features.adoc +2 -2
  5. data/lib/asciidoctor-diagram.rb +8 -0
  6. data/lib/asciidoctor-diagram/a2s/converter.rb +59 -0
  7. data/lib/asciidoctor-diagram/a2s/extension.rb +6 -52
  8. data/lib/asciidoctor-diagram/blockdiag/converter.rb +37 -0
  9. data/lib/asciidoctor-diagram/blockdiag/extension.rb +9 -116
  10. data/lib/asciidoctor-diagram/bpmn.rb +7 -0
  11. data/lib/asciidoctor-diagram/bpmn/converter.rb +62 -0
  12. data/lib/asciidoctor-diagram/bpmn/extension.rb +14 -0
  13. data/lib/asciidoctor-diagram/bytefield.rb +7 -0
  14. data/lib/asciidoctor-diagram/bytefield/converter.rb +26 -0
  15. data/lib/asciidoctor-diagram/bytefield/extension.rb +14 -0
  16. data/lib/asciidoctor-diagram/diagram_converter.rb +23 -0
  17. data/lib/asciidoctor-diagram/diagram_processor.rb +357 -0
  18. data/lib/asciidoctor-diagram/diagram_source.rb +322 -0
  19. data/lib/asciidoctor-diagram/ditaa/converter.rb +90 -0
  20. data/lib/asciidoctor-diagram/ditaa/extension.rb +6 -71
  21. data/lib/asciidoctor-diagram/dpic.rb +7 -0
  22. data/lib/asciidoctor-diagram/dpic/converter.rb +30 -0
  23. data/lib/asciidoctor-diagram/dpic/extension.rb +14 -0
  24. data/lib/asciidoctor-diagram/erd/converter.rb +31 -0
  25. data/lib/asciidoctor-diagram/erd/extension.rb +6 -35
  26. data/lib/asciidoctor-diagram/gnuplot.rb +7 -0
  27. data/lib/asciidoctor-diagram/gnuplot/converter.rb +63 -0
  28. data/lib/asciidoctor-diagram/gnuplot/extension.rb +14 -0
  29. data/lib/asciidoctor-diagram/graphviz/converter.rb +32 -0
  30. data/lib/asciidoctor-diagram/graphviz/extension.rb +6 -35
  31. data/lib/asciidoctor-diagram/http/converter.rb +99 -0
  32. data/lib/asciidoctor-diagram/http/server.rb +132 -0
  33. data/lib/asciidoctor-diagram/lilypond.rb +7 -0
  34. data/lib/asciidoctor-diagram/lilypond/converter.rb +54 -0
  35. data/lib/asciidoctor-diagram/lilypond/extension.rb +14 -0
  36. data/lib/asciidoctor-diagram/meme/converter.rb +122 -0
  37. data/lib/asciidoctor-diagram/meme/extension.rb +5 -107
  38. data/lib/asciidoctor-diagram/mermaid/converter.rb +179 -0
  39. data/lib/asciidoctor-diagram/mermaid/extension.rb +6 -159
  40. data/lib/asciidoctor-diagram/msc/converter.rb +35 -0
  41. data/lib/asciidoctor-diagram/msc/extension.rb +6 -36
  42. data/lib/asciidoctor-diagram/nomnoml/converter.rb +25 -0
  43. data/lib/asciidoctor-diagram/nomnoml/extension.rb +6 -28
  44. data/lib/asciidoctor-diagram/pikchr.rb +7 -0
  45. data/lib/asciidoctor-diagram/pikchr/converter.rb +26 -0
  46. data/lib/asciidoctor-diagram/pikchr/extension.rb +14 -0
  47. data/lib/asciidoctor-diagram/plantuml/converter.rb +117 -0
  48. data/lib/asciidoctor-diagram/plantuml/extension.rb +10 -119
  49. data/lib/asciidoctor-diagram/shaape/converter.rb +25 -0
  50. data/lib/asciidoctor-diagram/shaape/extension.rb +6 -28
  51. data/lib/asciidoctor-diagram/smcat.rb +7 -0
  52. data/lib/asciidoctor-diagram/smcat/converter.rb +44 -0
  53. data/lib/asciidoctor-diagram/smcat/extension.rb +14 -0
  54. data/lib/asciidoctor-diagram/svgbob/converter.rb +49 -0
  55. data/lib/asciidoctor-diagram/svgbob/extension.rb +6 -28
  56. data/lib/asciidoctor-diagram/symbolator.rb +7 -0
  57. data/lib/asciidoctor-diagram/symbolator/converter.rb +23 -0
  58. data/lib/asciidoctor-diagram/symbolator/extension.rb +14 -0
  59. data/lib/asciidoctor-diagram/syntrax/converter.rb +58 -0
  60. data/lib/asciidoctor-diagram/syntrax/extension.rb +6 -51
  61. data/lib/asciidoctor-diagram/tikz/converter.rb +56 -0
  62. data/lib/asciidoctor-diagram/tikz/extension.rb +6 -60
  63. data/lib/asciidoctor-diagram/umlet/converter.rb +24 -0
  64. data/lib/asciidoctor-diagram/umlet/extension.rb +6 -28
  65. data/lib/asciidoctor-diagram/util/cli.rb +14 -3
  66. data/lib/asciidoctor-diagram/util/cli_generator.rb +19 -1
  67. data/lib/asciidoctor-diagram/util/gif.rb +2 -2
  68. data/lib/asciidoctor-diagram/util/java.rb +1 -1
  69. data/lib/asciidoctor-diagram/util/java_socket.rb +7 -9
  70. data/lib/asciidoctor-diagram/util/pdf.rb +2 -2
  71. data/lib/asciidoctor-diagram/util/png.rb +2 -2
  72. data/lib/asciidoctor-diagram/util/svg.rb +46 -19
  73. data/lib/asciidoctor-diagram/util/which.rb +0 -29
  74. data/lib/asciidoctor-diagram/vega/converter.rb +47 -0
  75. data/lib/asciidoctor-diagram/vega/extension.rb +6 -44
  76. data/lib/asciidoctor-diagram/version.rb +1 -1
  77. data/lib/asciidoctor-diagram/wavedrom/converter.rb +50 -0
  78. data/lib/asciidoctor-diagram/wavedrom/extension.rb +6 -46
  79. data/lib/ditaa-1.3.15.jar +0 -0
  80. data/lib/ditaamini-0.12.jar +0 -0
  81. data/lib/plantuml-1.3.15.jar +0 -0
  82. data/lib/plantuml.jar +0 -0
  83. data/lib/server-1.3.15.jar +0 -0
  84. data/spec/a2s_spec.rb +2 -140
  85. data/spec/blockdiag_spec.rb +2 -200
  86. data/spec/bpmn_spec.rb +56 -0
  87. data/spec/bytefield_spec.rb +92 -0
  88. data/spec/ditaa_spec.rb +37 -143
  89. data/spec/dpic_spec.rb +19 -0
  90. data/spec/erd_spec.rb +2 -199
  91. data/spec/gnuplot_spec.rb +225 -0
  92. data/spec/graphviz_spec.rb +6 -145
  93. data/spec/lilypond_spec.rb +13 -0
  94. data/spec/mermaid_spec.rb +35 -200
  95. data/spec/msc_spec.rb +2 -199
  96. data/spec/nomnoml_spec.rb +4 -142
  97. data/spec/pikchr_spec.rb +51 -0
  98. data/spec/plantuml_spec.rb +24 -507
  99. data/spec/shaape_spec.rb +9 -221
  100. data/spec/shared_examples.rb +552 -0
  101. data/spec/smcat_spec.rb +26 -0
  102. data/spec/svgbob_spec.rb +2 -140
  103. data/spec/symbolator_spec.rb +23 -0
  104. data/spec/syntrax_spec.rb +5 -215
  105. data/spec/test_helper.rb +1 -18
  106. data/spec/tikz_spec.rb +4 -24
  107. data/spec/umlet_spec.rb +2 -58
  108. data/spec/vega_spec.rb +4 -117
  109. data/spec/wavedrom_spec.rb +2 -199
  110. metadata +73 -11
  111. data/lib/asciidoctor-diagram/extensions.rb +0 -568
  112. data/lib/ditaa-1.3.13.jar +0 -0
  113. data/lib/ditaamini-0.11.jar +0 -0
  114. data/lib/plantuml-1.3.13.jar +0 -0
  115. data/lib/server-1.3.13.jar +0 -0
@@ -1,34 +1,61 @@
1
1
  require_relative 'binaryio'
2
+ require 'rexml/document'
3
+ require 'bigdecimal'
4
+ require 'bigdecimal/util'
2
5
 
3
6
  module Asciidoctor
4
7
  module Diagram
5
8
  # @private
6
9
  module SVG
7
- def self.get_image_size(data)
8
- if m = START_TAG_REGEX.match(data)
9
- start_tag = m[0]
10
- if (w = WIDTH_REGEX.match(start_tag)) && (h = HEIGHT_REGEX.match(start_tag))
11
- width = w[:value].to_i * to_px_factor(w[:unit])
12
- height = h[:value].to_i * to_px_factor(h[:unit])
13
- return [width.to_i, height.to_i]
14
- end
15
-
16
- if v = VIEWBOX_REGEX.match(start_tag)
17
- width = v[:width]
18
- height = v[:height]
19
- return [width.to_i, height.to_i]
20
- end
10
+ def self.post_process_image(data)
11
+ svg = REXML::Document.new(data)
12
+
13
+ root = svg.root
14
+
15
+ unless root.attributes['xmlns']
16
+ root.add_attribute('xmlns', 'http://www.w3.org/2000/svg')
17
+ end
18
+
19
+ unless root.attributes['preserveAspectRatio']
20
+ root.add_attribute('preserveAspectRatio', 'xMidYMid meet')
21
21
  end
22
22
 
23
- nil
23
+ width = nil
24
+ height = nil
25
+
26
+ if (w = WIDTH_HEIGHT_REGEX.match(root.attributes['width'])) && (h = WIDTH_HEIGHT_REGEX.match(root.attributes['height']))
27
+ width = to_numeric(w[:value]) * to_px_factor(w[:unit])
28
+ height = to_numeric(h[:value]) * to_px_factor(h[:unit])
29
+ end
30
+
31
+ viewbox = root.attributes['viewBox']
32
+ if (v = VIEWBOX_REGEX.match(viewbox)) && width.nil? && height.nil?
33
+ width = to_numeric(v[:width])
34
+ height = to_numeric(v[:height])
35
+ end
36
+
37
+ if viewbox.nil? && width && height
38
+ root.add_attribute('viewBox', "0 0 #{width.to_s} #{height.to_s}")
39
+ end
40
+
41
+ patched_svg = ""
42
+ svg.write(:output => patched_svg, :indent => 2)
43
+
44
+ [patched_svg, width, height]
24
45
  end
25
46
 
26
47
  private
27
48
 
28
- START_TAG_REGEX = /<svg[^>]*>/
29
- WIDTH_REGEX = /width="(?<value>\d+(?:\.\d+)?)(?<unit>[a-zA-Z]+)?"/
30
- HEIGHT_REGEX = /height="(?<value>\d+(?:\.\d+)?)(?<unit>[a-zA-Z]+)?"/
31
- VIEWBOX_REGEX = /viewBox="\d+(?:\.\d+)? \d+(?:\.\d+)? (?<width>\d+(?:\.\d+)?) (?<height>\d+(?:\.\d+)?)"/
49
+ def self.to_numeric(text)
50
+ if text.include? '.'
51
+ text.to_f
52
+ else
53
+ text.to_i
54
+ end
55
+ end
56
+
57
+ WIDTH_HEIGHT_REGEX = /^\s*(?<value>\d+(?:\.\d+)?)\s*(?<unit>[a-zA-Z]+)?\s*$/
58
+ VIEWBOX_REGEX = /^\s*\d+(?:\.\d+)?\s*\d+(?:\.\d+)?\s*(?<width>\d+(?:\.\d+)?)\s*(?<height>\d+(?:\.\d+)?)\s*$/
32
59
 
33
60
  def self.to_px_factor(unit)
34
61
  case unit
@@ -15,35 +15,6 @@ module Asciidoctor
15
15
 
16
16
  nil
17
17
  end
18
-
19
- def which(parent_block, cmd, options = {})
20
- attr_names = options[:attrs] || options.fetch(:alt_attrs, []) + [cmd]
21
- cmd_names = [cmd] + options.fetch(:alt_cmds, [])
22
-
23
- cmd_var = 'cmd-' + attr_names[0]
24
-
25
- if config.key? cmd_var
26
- cmd_path = config[cmd_var]
27
- else
28
- cmd_path = attr_names.map { |attr_name| parent_block.attr(attr_name, nil, true) }.find { |attr| !attr.nil? }
29
-
30
- unless cmd_path && File.executable?(cmd_path)
31
- cmd_paths = cmd_names.map do |c|
32
- ::Asciidoctor::Diagram::Which.which(c, :path => options[:path])
33
- end
34
-
35
- cmd_path = cmd_paths.reject { |c| c.nil? }.first
36
- end
37
-
38
- config[cmd_var] = cmd_path
39
-
40
- if cmd_path.nil? && options.fetch(:raise_on_error, true)
41
- raise "Could not find the #{cmd_names.map { |c| "'#{c}'" }.join(', ')} executable in PATH; add it to the PATH or specify its location using the '#{attr_names[0]}' document attribute"
42
- end
43
- end
44
-
45
- cmd_path
46
- end
47
18
  end
48
19
  end
49
20
  end
@@ -0,0 +1,47 @@
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 VegaConverter
9
+ include DiagramConverter
10
+ include CliGenerator
11
+
12
+
13
+ def supported_formats
14
+ [:svg, :png]
15
+ end
16
+
17
+
18
+ def collect_options(source)
19
+ {
20
+ :vegalite => source.diagram_type.to_s.include?('lite') || source.attr('vegalite')
21
+ }
22
+ end
23
+
24
+ def convert(source, format, options)
25
+ base_dir = source.base_dir
26
+
27
+ code = source.to_s
28
+
29
+ if code.include?('/schema/vega-lite/') || options[:vegalite]
30
+ vega_code = generate_stdin_stdout(source.find_command("vl2vg"), code)
31
+ else
32
+ vega_code = code
33
+ end
34
+
35
+ generate_file(source.find_command("vg2#{format}"), "json", format.to_s, vega_code) do |tool_path, input_path, output_path|
36
+ args = [tool_path, '--base', Platform.native_path(base_dir)]
37
+ if format == :svg
38
+ args << '--header'
39
+ end
40
+
41
+ args << Platform.native_path(input_path)
42
+ args << Platform.native_path(output_path)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,52 +1,14 @@
1
- require_relative '../extensions'
2
- require_relative '../util/cli_generator'
3
- require_relative '../util/platform'
4
- require_relative '../util/which'
1
+ require_relative '../diagram_processor'
2
+ require_relative 'converter'
5
3
 
6
4
  module Asciidoctor
7
5
  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
6
+ class VegaBlockProcessor < DiagramBlockProcessor
7
+ use_converter VegaConverter
46
8
  end
47
9
 
48
- class VegaBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
49
- include Vega
10
+ class VegaBlockMacroProcessor < DiagramBlockMacroProcessor
11
+ use_converter VegaConverter
50
12
  end
51
13
  end
52
14
  end
@@ -1,5 +1,5 @@
1
1
  module Asciidoctor
2
2
  module Diagram
3
- VERSION = "1.5.18"
3
+ VERSION = "2.0.4"
4
4
  end
5
5
  end
@@ -0,0 +1,50 @@
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 WavedromConverter
9
+ include DiagramConverter
10
+ include CliGenerator
11
+
12
+
13
+ def supported_formats
14
+ [:png, :svg]
15
+ end
16
+
17
+
18
+ def convert(source, format, options)
19
+ wavedrom_cli = source.find_command('wavedrom-cli', :raise_on_error => false)
20
+ if wavedrom_cli
21
+ generate_file(wavedrom_cli, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
22
+ [Platform.native_path(tool_path), '--input', Platform.native_path(input_path), "--#{format.to_s}", Platform.native_path(output_path)]
23
+ end
24
+ else
25
+ wavedrom_cli = source.find_command('wavedrom', :raise_on_error => false)
26
+ phantomjs = source.find_command('phantomjs', :alt_attrs => ['phantomjs_2'], :raise_on_error => false)
27
+
28
+ if wavedrom_cli && !wavedrom_cli.include?('WaveDromEditor') && phantomjs
29
+ generate_file(wavedrom_cli, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
30
+ [phantomjs, Platform.native_path(tool_path), '-i', Platform.native_path(input_path), "-#{format.to_s[0]}", Platform.native_path(output_path)]
31
+ end
32
+ else
33
+ if ::Asciidoctor::Diagram::Platform.os == :macosx
34
+ wavedrom = source.find_command('WaveDromEditor.app', :alt_cmds => ['wavedrom-editor.app'], :attrs => ['WaveDromEditorApp'], :path => ['/Applications'])
35
+ if wavedrom
36
+ wavedrom = File.join(wavedrom, 'Contents/MacOS/nwjs')
37
+ end
38
+ else
39
+ wavedrom = source.find_command('WaveDromEditor')
40
+ end
41
+
42
+ generate_file(wavedrom, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
43
+ [tool_path, 'source', Platform.native_path(input_path), format.to_s, Platform.native_path(output_path)]
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,54 +1,14 @@
1
- require_relative '../extensions'
2
- require_relative '../util/cli_generator'
3
- require_relative '../util/platform'
4
- require_relative '../util/which'
1
+ require_relative '../diagram_processor'
2
+ require_relative 'converter'
5
3
 
6
4
  module Asciidoctor
7
5
  module Diagram
8
- # @private
9
- module Wavedrom
10
- include CliGenerator
11
- include Which
12
-
13
- def self.included(mod)
14
- [:png, :svg].each do |f|
15
- mod.register_format(f, :image) do |parent, source|
16
- wavedrom(parent, source, f)
17
- end
18
- end
19
- end
20
-
21
- def wavedrom(parent, source, format)
22
- wavedrom_cli = which(parent, 'wavedrom', :raise_on_error => false)
23
- phantomjs = which(parent, 'phantomjs', :alt_attrs => ['phantomjs_2'], :raise_on_error => false)
24
-
25
- if wavedrom_cli && !wavedrom_cli.include?('WaveDromEditor') && phantomjs
26
- generate_file(wavedrom_cli, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
27
- [phantomjs, Platform.native_path(tool_path), '-i', Platform.native_path(input_path), "-#{format.to_s[0]}", Platform.native_path(output_path)]
28
- end
29
- else
30
- if ::Asciidoctor::Diagram::Platform.os == :macosx
31
- wavedrom = which(parent, 'WaveDromEditor.app', :alt_cmds => ['wavedrom-editor.app'], :attrs => ['WaveDromEditorApp'],:path => ['/Applications'])
32
- if wavedrom
33
- wavedrom = File.join(wavedrom, 'Contents/MacOS/nwjs')
34
- end
35
- else
36
- wavedrom = which(parent, 'WaveDromEditor')
37
- end
38
-
39
- generate_file(wavedrom, 'wvd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
40
- [tool_path, 'source', Platform.native_path(input_path), format.to_s, Platform.native_path(output_path)]
41
- end
42
- end
43
- end
44
- end
45
-
46
- class WavedromBlockProcessor < Extensions::DiagramBlockProcessor
47
- include Wavedrom
6
+ class WavedromBlockProcessor < DiagramBlockProcessor
7
+ use_converter WavedromConverter
48
8
  end
49
9
 
50
- class WavedromBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
51
- include Wavedrom
10
+ class WavedromBlockMacroProcessor < DiagramBlockMacroProcessor
11
+ use_converter WavedromConverter
52
12
  end
53
13
  end
54
14
  end
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -21,147 +21,9 @@ code = <<-eos
21
21
  eos
22
22
 
23
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
24
+ include_examples "block_macro", :a2s, code, [:svg]
52
25
  end
53
26
 
54
27
  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
28
+ include_examples "block", :svgbob, code, [:svg]
167
29
  end