asciidoctor-diagram 2.0.2 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +25 -0
  3. data/README.adoc +13 -4
  4. data/lib/asciidoctor-diagram.rb +3 -0
  5. data/lib/asciidoctor-diagram/a2s/converter.rb +10 -6
  6. data/lib/asciidoctor-diagram/blockdiag/converter.rb +1 -1
  7. data/lib/asciidoctor-diagram/bpmn/converter.rb +3 -3
  8. data/lib/asciidoctor-diagram/diagram_converter.rb +5 -1
  9. data/lib/asciidoctor-diagram/diagram_processor.rb +64 -38
  10. data/lib/asciidoctor-diagram/diagram_source.rb +64 -17
  11. data/lib/asciidoctor-diagram/ditaa/converter.rb +6 -2
  12. data/lib/asciidoctor-diagram/dpic.rb +7 -0
  13. data/lib/asciidoctor-diagram/dpic/converter.rb +30 -0
  14. data/lib/asciidoctor-diagram/dpic/extension.rb +14 -0
  15. data/lib/asciidoctor-diagram/gnuplot/converter.rb +8 -8
  16. data/lib/asciidoctor-diagram/graphviz/converter.rb +2 -2
  17. data/lib/asciidoctor-diagram/http/converter.rb +25 -5
  18. data/lib/asciidoctor-diagram/http/server.rb +10 -5
  19. data/lib/asciidoctor-diagram/lilypond/converter.rb +2 -2
  20. data/lib/asciidoctor-diagram/meme/converter.rb +7 -7
  21. data/lib/asciidoctor-diagram/mermaid/converter.rb +16 -15
  22. data/lib/asciidoctor-diagram/msc/converter.rb +2 -2
  23. data/lib/asciidoctor-diagram/pikchr.rb +7 -0
  24. data/lib/asciidoctor-diagram/pikchr/converter.rb +26 -0
  25. data/lib/asciidoctor-diagram/pikchr/extension.rb +14 -0
  26. data/lib/asciidoctor-diagram/plantuml/converter.rb +3 -3
  27. data/lib/asciidoctor-diagram/smcat/converter.rb +3 -3
  28. data/lib/asciidoctor-diagram/svgbob/converter.rb +2 -2
  29. data/lib/asciidoctor-diagram/symbolator.rb +7 -0
  30. data/lib/asciidoctor-diagram/symbolator/converter.rb +23 -0
  31. data/lib/asciidoctor-diagram/symbolator/extension.rb +14 -0
  32. data/lib/asciidoctor-diagram/syntrax/converter.rb +9 -6
  33. data/lib/asciidoctor-diagram/util/cli_generator.rb +18 -0
  34. data/lib/asciidoctor-diagram/util/gif.rb +2 -2
  35. data/lib/asciidoctor-diagram/util/pdf.rb +2 -2
  36. data/lib/asciidoctor-diagram/util/png.rb +2 -2
  37. data/lib/asciidoctor-diagram/util/svg.rb +46 -19
  38. data/lib/asciidoctor-diagram/vega/converter.rb +2 -2
  39. data/lib/asciidoctor-diagram/version.rb +1 -1
  40. data/spec/a2s_spec.rb +2 -140
  41. data/spec/blockdiag_spec.rb +2 -200
  42. data/spec/bpmn_spec.rb +52 -92
  43. data/spec/bytefield_spec.rb +2 -140
  44. data/spec/ditaa_spec.rb +5 -143
  45. data/spec/dpic_spec.rb +19 -0
  46. data/spec/erd_spec.rb +2 -199
  47. data/spec/gnuplot_spec.rb +2 -255
  48. data/spec/graphviz_spec.rb +6 -145
  49. data/spec/lilypond_spec.rb +2 -140
  50. data/spec/mermaid_spec.rb +2 -199
  51. data/spec/msc_spec.rb +2 -199
  52. data/spec/nomnoml_spec.rb +4 -142
  53. data/spec/pikchr_spec.rb +51 -0
  54. data/spec/plantuml_spec.rb +6 -578
  55. data/spec/shaape_spec.rb +9 -221
  56. data/spec/shared_examples.rb +552 -0
  57. data/spec/smcat_spec.rb +2 -140
  58. data/spec/svgbob_spec.rb +2 -140
  59. data/spec/symbolator_spec.rb +23 -0
  60. data/spec/syntrax_spec.rb +5 -215
  61. data/spec/test_helper.rb +1 -22
  62. data/spec/tikz_spec.rb +4 -24
  63. data/spec/umlet_spec.rb +2 -58
  64. data/spec/vega_spec.rb +4 -117
  65. data/spec/wavedrom_spec.rb +2 -199
  66. metadata +20 -6
  67. data/spec/bpmn-example.xml +0 -44
@@ -33,17 +33,21 @@ module Asciidoctor
33
33
  [:png, :svg]
34
34
  end
35
35
 
36
- def collect_options(source, name)
36
+ def collect_options(source)
37
37
  options = {}
38
38
 
39
39
  OPTIONS.keys.each do |option|
40
40
  attr_name = option.to_s.tr('_', '-')
41
- options[option] = source.attr(attr_name, nil, name) || source.attr(attr_name, nil, 'ditaa-option')
41
+ options[option] = source.attr(attr_name) || source.attr(attr_name, nil, 'ditaa-option')
42
42
  end
43
43
 
44
44
  options
45
45
  end
46
46
 
47
+ def native_scaling?
48
+ true
49
+ end
50
+
47
51
  def convert(source, format, options)
48
52
  Java.load
49
53
 
@@ -0,0 +1,7 @@
1
+ require 'asciidoctor/extensions'
2
+ require_relative 'dpic/extension'
3
+
4
+ Asciidoctor::Extensions.register do
5
+ block Asciidoctor::Diagram::DpicBlockProcessor, :dpic
6
+ block_macro Asciidoctor::Diagram::DpicBlockMacroProcessor, :dpic
7
+ end
@@ -0,0 +1,30 @@
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 DpicConverter
9
+ include DiagramConverter
10
+ include CliGenerator
11
+
12
+
13
+ def supported_formats
14
+ [:svg]
15
+ end
16
+
17
+ def convert(source, format, options)
18
+ dpic_path = source.find_command('dpic')
19
+
20
+ code = source.to_s
21
+ code.prepend ".PS\n" unless code.start_with?(".PS\n")
22
+ code << "\n.PE" unless code.start_with?("\n.PE")
23
+
24
+ generate_file_stdout(dpic_path, format.to_s, code) do |tool_path, input_path|
25
+ [tool_path, "-v", "-z", input_path]
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,14 @@
1
+ require_relative 'converter'
2
+ require_relative '../diagram_processor'
3
+
4
+ module Asciidoctor
5
+ module Diagram
6
+ class DpicBlockProcessor < DiagramBlockProcessor
7
+ use_converter DpicConverter
8
+ end
9
+
10
+ class DpicBlockMacroProcessor < DiagramBlockMacroProcessor
11
+ use_converter DpicConverter
12
+ end
13
+ end
14
+ end
@@ -14,15 +14,15 @@ module Asciidoctor
14
14
  [:png, :svg, :gif, :txt, :literal]
15
15
  end
16
16
 
17
- def collect_options(source, name)
17
+ def collect_options(source)
18
18
  {
19
- :width => source.attr('width', nil, name),
20
- :height => source.attr('height', nil, name),
21
- :transparent => source.attr('transparent', nil, name),
22
- :crop => source.attr('crop', nil, name),
23
- :font => source.attr('font', nil, name),
24
- :fontscale => source.attr('fontscale', nil, name),
25
- :background => source.attr('background', nil, name),
19
+ :width => source.attr('width'),
20
+ :height => source.attr('height'),
21
+ :transparent => source.attr('transparent'),
22
+ :crop => source.attr('crop'),
23
+ :font => source.attr('font'),
24
+ :fontscale => source.attr('fontscale'),
25
+ :background => source.attr('background'),
26
26
  }
27
27
  end
28
28
 
@@ -13,8 +13,8 @@ module Asciidoctor
13
13
  [:png, :pdf, :svg]
14
14
  end
15
15
 
16
- def collect_options(source, name)
17
- {:layout => source.attr('layout', nil, name)}
16
+ def collect_options(source)
17
+ {:layout => source.attr('layout')}
18
18
  end
19
19
 
20
20
  def convert(source, format, options)
@@ -51,6 +51,7 @@ module Asciidoctor
51
51
  path << '/' unless path.end_with? '/'
52
52
  path << format.to_s
53
53
  path << '/' << data
54
+ uri.path = path
54
55
  when :kroki_io
55
56
  compressed = Zlib.deflate(code, Zlib::BEST_COMPRESSION)
56
57
  data = Base64.urlsafe_encode64(compressed)
@@ -60,17 +61,36 @@ module Asciidoctor
60
61
  path << options[:block_name].to_s
61
62
  path << '/' << format.to_s
62
63
  path << '/' << data
64
+ uri.path = path
63
65
  else
64
66
  raise "Unsupported server type: " + @type
65
67
  end
66
68
 
69
+ get_uri(uri)
70
+ end
71
+
72
+ private
73
+
74
+ def get_uri(uri, attempt = 1)
75
+ if attempt >= 10
76
+ raise "Too many redirects"
77
+ end
78
+
67
79
  Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme.downcase == 'https') do |http|
68
- response = http.request_get path
80
+ response = http.request_get uri.path
69
81
  case response
70
- when Net::HTTPSuccess
71
- response.body
72
- else
73
- response.value
82
+ when Net::HTTPSuccess
83
+ response.body
84
+ when Net::HTTPRedirection then
85
+ location = response['Location']
86
+ new_uri = URI.parse(location)
87
+ if new_uri.relative?
88
+ get_uri(uri + location, attempt + 1)
89
+ else
90
+ get_uri(new_uri, attempt + 1)
91
+ end
92
+ else
93
+ response.value
74
94
  end
75
95
  end
76
96
  end
@@ -67,15 +67,15 @@ module Asciidoctor
67
67
  end
68
68
  end
69
69
 
70
- def render_diagram(type, accepts, code, attributes)
70
+ def render_diagram(type, accepts, source, attributes)
71
71
  converter = get_converter(type.downcase.to_sym)
72
72
  return [500, "Unsupported diagram type #{type}"] unless converter
73
73
 
74
74
  format = converter.supported_formats.find {|f| accepts.call(f)}
75
75
  return [500, "Could not determine supported output format"] unless format
76
76
 
77
- source = ServerSource.new(code, attributes)
78
- options = converter.collect_options(source, type.downcase)
77
+ source = ServerSource.new(type.downcase, source, attributes)
78
+ options = converter.collect_options(source)
79
79
  diagram = converter.convert(source, format, options)
80
80
 
81
81
  content_type to_mime_type(format)
@@ -86,12 +86,17 @@ module Asciidoctor
86
86
  class ServerSource
87
87
  include Asciidoctor::Diagram::DiagramSource
88
88
 
89
- def initialize(source, attributes)
89
+ def initialize(name, source, attributes)
90
+ @name = name
90
91
  @source = source
91
92
  @attributes = attributes
92
93
  end
93
94
 
94
- def attr(name, default_value = nil, inherit = nil)
95
+ def diagram_type
96
+ @name
97
+ end
98
+
99
+ def attr(name, default_value = nil, inherit = diagram_type)
95
100
  @attributes[name] || default_value
96
101
  end
97
102
 
@@ -14,9 +14,9 @@ module Asciidoctor
14
14
  [:png, :pdf]
15
15
  end
16
16
 
17
- def collect_options(source, name)
17
+ def collect_options(source)
18
18
  {
19
- :resolution => source.attr('resolution', nil, name)
19
+ :resolution => source.attr('resolution')
20
20
  }
21
21
  end
22
22
 
@@ -15,20 +15,20 @@ module Asciidoctor
15
15
  end
16
16
 
17
17
 
18
- def collect_options(source, name)
19
- bg_img = source.attr('background', nil, name)
18
+ def collect_options(source)
19
+ bg_img = source.attr('background')
20
20
  raise "background attribute is required" unless bg_img
21
21
 
22
- options = source.attr('options', '', name).split(',')
22
+ options = source.attr('options', '').split(',')
23
23
 
24
24
  {
25
25
  :bg_img => bg_img,
26
26
  :top_label => source.attr('top'),
27
27
  :bottom_label => source.attr('bottom'),
28
- :fill_color => source.attr('fillcolor', nil, name) || source.attr('fill-color', nil, name),
29
- :stroke_color => source.attr('strokecolor', nil, name) || source.attr('stroke-color', nil, name),
30
- :stroke_width => source.attr('strokewidth', nil, name) || source.attr('stroke-width', nil, name),
31
- :font => source.attr('font', 'Impact', name),
28
+ :fill_color => source.attr(['fillcolor', 'fill-color']),
29
+ :stroke_color => source.attr(['strokecolor', 'stroke-color']),
30
+ :stroke_width => source.attr(['strokewidth', 'stroke-width']),
31
+ :font => source.attr('font', 'Impact'),
32
32
  :noupcase => options.include?('noupcase'),
33
33
  }
34
34
  end
@@ -15,18 +15,18 @@ module Asciidoctor
15
15
  [:png, :svg]
16
16
  end
17
17
 
18
- def collect_options(source, name)
18
+ def collect_options(source)
19
19
  options = {}
20
20
 
21
- options[:css] = source.attr('css', nil, name)
22
- options[:gantt_config] = source.attr('ganttconfig', nil, name) || source.attr('gantt-config', nil, name)
23
- options[:seq_config] = source.attr('sequenceconfig', nil, name) || source.attr('sequence-config', nil, name)
24
- options[:width] = source.attr('width', nil, name)
25
- options[:height] = source.attr('height', nil, name)
26
- options[:theme] = source.attr('theme', nil, name)
27
- options[:background] = source.attr('background', nil, name)
28
- options[:config] = source.attr('config', nil, name)
29
- options[:puppeteer_config] = source.attr('puppeteerconfig', nil, name) || source.attr('puppeteer-config', nil, name)
21
+ options[:css] = source.attr('css')
22
+ options[:gantt_config] = source.attr(['ganttconfig', 'gantt-config'])
23
+ options[:seq_config] = source.attr(['sequenceconfig', 'sequence-config'])
24
+ options[:width] = source.attr('width')
25
+ options[:height] = source.attr('height')
26
+ options[:theme] = source.attr('theme')
27
+ options[:background] = source.attr('background')
28
+ options[:config] = source.attr('config')
29
+ options[:puppeteer_config] = source.attr(['puppeteerconfig', 'puppeteer-config'])
30
30
 
31
31
  options
32
32
  end
@@ -57,7 +57,8 @@ module Asciidoctor
57
57
  opts[:width] = options[:width]
58
58
 
59
59
  mmdc = source.find_command('mmdc', :raise_on_error => false)
60
- if mmdc
60
+ node = source.find_command('node', :raise_on_error => false)
61
+ if mmdc && node
61
62
  opts[:height] = options[:height]
62
63
  opts[:theme] = options[:theme]
63
64
  opts[:background] = options[:background]
@@ -65,7 +66,7 @@ module Asciidoctor
65
66
  if config
66
67
  opts[:config] = source.resolve_path(config)
67
68
  end
68
- run_mmdc(mmdc, source, format, opts)
69
+ run_mmdc(node, mmdc, source, format, opts)
69
70
  else
70
71
  mermaid = source.find_command('mermaid')
71
72
  run_mermaid(mermaid, source, format, opts)
@@ -73,9 +74,9 @@ module Asciidoctor
73
74
  end
74
75
 
75
76
  private
76
- def run_mmdc(mmdc, source, format, options = {})
77
- generate_file(mmdc, 'mmd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
78
- args = [tool_path, '-i', Platform.native_path(input_path), '-o', Platform.native_path(output_path)]
77
+ def run_mmdc(node, mmdc, source, format, options = {})
78
+ generate_file(node, 'mmd', format.to_s, source.to_s) do |tool_path, input_path, output_path|
79
+ args = [tool_path, '--unhandled-rejections=strict', mmdc, '-i', Platform.native_path(input_path), '-o', Platform.native_path(output_path)]
79
80
 
80
81
  if options[:css]
81
82
  args << '--cssFile' << Platform.native_path(options[:css])
@@ -14,8 +14,8 @@ module Asciidoctor
14
14
  [:png, :svg]
15
15
  end
16
16
 
17
- def collect_options(source, name)
18
- {:font => source.attr('font', nil, name)}
17
+ def collect_options(source)
18
+ {:font => source.attr('font')}
19
19
  end
20
20
 
21
21
  def convert(source, format, options)
@@ -0,0 +1,7 @@
1
+ require 'asciidoctor/extensions'
2
+ require_relative 'pikchr/extension'
3
+
4
+ Asciidoctor::Extensions.register do
5
+ block Asciidoctor::Diagram::PikchrBlockProcessor, :pikchr
6
+ block_macro Asciidoctor::Diagram::PikchrBlockMacroProcessor, :pikchr
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 PikchrConverter
9
+ include DiagramConverter
10
+ include CliGenerator
11
+
12
+
13
+ def supported_formats
14
+ [:svg]
15
+ end
16
+
17
+ def convert(source, format, options)
18
+ pikchr_path = source.find_command('pikchr')
19
+
20
+ generate_file_stdout(pikchr_path, format.to_s, source.to_s) do |tool_path, input_path|
21
+ [tool_path, "--svg-only", input_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 PikchrBlockProcessor < DiagramBlockProcessor
7
+ use_converter PikchrConverter
8
+ end
9
+
10
+ class PikchrBlockMacroProcessor < DiagramBlockMacroProcessor
11
+ use_converter PikchrConverter
12
+ end
13
+ end
14
+ end
@@ -21,9 +21,9 @@ module Asciidoctor
21
21
  [:png, :svg, :txt, :atxt, :utxt]
22
22
  end
23
23
 
24
- def collect_options(source, name)
24
+ def collect_options(source)
25
25
  {
26
- :config => source.attr('plantumlconfig', nil, true) || source.attr('config', nil, name)
26
+ :config => source.attr('plantumlconfig', nil, true) || source.attr('config')
27
27
  }
28
28
  end
29
29
 
@@ -78,7 +78,7 @@ module Asciidoctor
78
78
  code = "@start#{tag}\n#{code}\n@end#{tag}" unless code.index("@start") && code.index("@end")
79
79
 
80
80
  code.gsub!(/(?<=<img:)[^>]+(?=>)/) do |match|
81
- resolve_path(match, source, source.attr('imagesdir'))
81
+ resolve_path(match, source, source.attr('imagesdir', nil, false))
82
82
  end
83
83
 
84
84
  code.gsub!(/(?:(?<=!include\s)|(?<=!includesub\s))\s*[^<][^!\n\r]+/) do |match|
@@ -14,10 +14,10 @@ module Asciidoctor
14
14
  [:svg]
15
15
  end
16
16
 
17
- def collect_options(source, name)
17
+ def collect_options(source)
18
18
  {
19
- :direction => source.attr('direction', nil, name),
20
- :engine => source.attr('engine', nil, name)
19
+ :direction => source.attr('direction'),
20
+ :engine => source.attr('engine')
21
21
  }
22
22
  end
23
23
 
@@ -21,12 +21,12 @@ module Asciidoctor
21
21
  :scale => lambda { |o, v| o << '--scale' << v if v }
22
22
  }
23
23
 
24
- def collect_options(source, name)
24
+ def collect_options(source)
25
25
  options = {}
26
26
 
27
27
  OPTIONS.keys.each do |option|
28
28
  attr_name = option.to_s.tr('_', '-')
29
- options[option] = source.attr(attr_name, nil, name) || source.attr(attr_name, nil, 'svgbob-option')
29
+ options[option] = source.attr(attr_name) || source.attr(attr_name, nil, 'svgbob-option')
30
30
  end
31
31
 
32
32
  options
@@ -0,0 +1,7 @@
1
+ require 'asciidoctor/extensions'
2
+ require_relative 'symbolator/extension'
3
+
4
+ Asciidoctor::Extensions.register do
5
+ block Asciidoctor::Diagram::SymbolatorBlockProcessor, :symbolator
6
+ block_macro Asciidoctor::Diagram::SymbolatorBlockMacroProcessor, :symbolator
7
+ end
@@ -0,0 +1,23 @@
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 SymbolatorConverter
9
+ include DiagramConverter
10
+ include CliGenerator
11
+
12
+ def supported_formats
13
+ [:png, :pdf, :svg]
14
+ end
15
+
16
+ def convert(source, format, options)
17
+ generate_stdin(source.find_command('symbolator'), format.to_s, source.to_s) do |tool_path, output_path|
18
+ [tool_path, "-i-", "-o#{Platform.native_path(output_path)}", "-f#{format.to_s}"]
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end