jekyll-diagrams 0.9.3 → 0.10.0

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 (77) hide show
  1. checksums.yaml +4 -4
  2. data/features/{blockdiag.feature → blockdiag/block.feature} +2 -2
  3. data/features/graphviz/block.feature +26 -0
  4. data/features/{graphviz.feature → graphviz/config.feature} +18 -31
  5. data/features/{mermaid.feature → mermaid/block.feature} +2 -2
  6. data/features/{nomnoml.feature → nomnoml/block.feature} +2 -2
  7. data/features/{plantuml.feature → plantuml/block.feature} +3 -12
  8. data/features/{smcat.feature → smcat/block.feature} +3 -3
  9. data/features/step_definitions/jekyll-diagrams.rb +5 -5
  10. data/features/support/env.rb +3 -9
  11. data/features/{syntrax.feature → syntrax/block.feature} +2 -2
  12. data/features/{vega.feature → vega/block.feature} +3 -3
  13. data/features/{wavedrom.feature → wavedrom/block.feature} +2 -2
  14. data/lib/jekyll-diagrams.rb +22 -61
  15. data/lib/jekyll-diagrams/basic_block.rb +28 -0
  16. data/lib/jekyll-diagrams/basic_renderer.rb +38 -0
  17. data/lib/jekyll-diagrams/blockdiag.rb +5 -31
  18. data/lib/jekyll-diagrams/blockdiag/block.rb +9 -0
  19. data/lib/jekyll-diagrams/blockdiag/renderer.rb +40 -0
  20. data/lib/jekyll-diagrams/erd.rb +4 -30
  21. data/lib/jekyll-diagrams/erd/block.rb +8 -0
  22. data/lib/jekyll-diagrams/erd/renderer.rb +34 -0
  23. data/lib/jekyll-diagrams/errors.rb +12 -13
  24. data/lib/jekyll-diagrams/graphviz.rb +4 -34
  25. data/lib/jekyll-diagrams/graphviz/block.rb +8 -0
  26. data/lib/jekyll-diagrams/graphviz/renderer.rb +40 -0
  27. data/lib/jekyll-diagrams/mermaid.rb +4 -25
  28. data/lib/jekyll-diagrams/mermaid/block.rb +8 -0
  29. data/lib/jekyll-diagrams/mermaid/renderer.rb +29 -0
  30. data/lib/jekyll-diagrams/nomnoml.rb +4 -15
  31. data/lib/jekyll-diagrams/nomnoml/block.rb +8 -0
  32. data/lib/jekyll-diagrams/nomnoml/renderer.rb +19 -0
  33. data/lib/jekyll-diagrams/plantuml.rb +4 -19
  34. data/lib/jekyll-diagrams/plantuml/block.rb +8 -0
  35. data/lib/jekyll-diagrams/plantuml/renderer.rb +23 -0
  36. data/lib/jekyll-diagrams/smcat.rb +4 -26
  37. data/lib/jekyll-diagrams/smcat/block.rb +8 -0
  38. data/lib/jekyll-diagrams/smcat/renderer.rb +30 -0
  39. data/lib/jekyll-diagrams/svgbob.rb +4 -21
  40. data/lib/jekyll-diagrams/svgbob/block.rb +8 -0
  41. data/lib/jekyll-diagrams/svgbob/renderer.rb +25 -0
  42. data/lib/jekyll-diagrams/syntrax.rb +4 -23
  43. data/lib/jekyll-diagrams/syntrax/block.rb +8 -0
  44. data/lib/jekyll-diagrams/syntrax/renderer.rb +27 -0
  45. data/lib/jekyll-diagrams/utils.rb +85 -0
  46. data/lib/jekyll-diagrams/vega.rb +5 -26
  47. data/lib/jekyll-diagrams/vega/block.rb +9 -0
  48. data/lib/jekyll-diagrams/vega/renderer.rb +33 -0
  49. data/lib/jekyll-diagrams/version.rb +1 -1
  50. data/lib/jekyll-diagrams/wavedrom.rb +4 -15
  51. data/lib/jekyll-diagrams/wavedrom/block.rb +8 -0
  52. data/lib/jekyll-diagrams/wavedrom/renderer.rb +19 -0
  53. data/spec/basic_block_spec.rb +70 -0
  54. data/spec/basic_renderer_spec.rb +69 -0
  55. data/spec/blockdiag_renderer_spec.rb +43 -0
  56. data/spec/erd_renderer_spec.rb +43 -0
  57. data/spec/graphviz_renderer_spec.rb +19 -0
  58. data/spec/jekyll-diagrams_spec.rb +23 -0
  59. data/spec/mermaid_renderer_spec.rb +19 -0
  60. data/spec/nomnoml_renderer_spec.rb +19 -0
  61. data/spec/plantuml_renderer_spec.rb +20 -0
  62. data/spec/rendering_spec.rb +111 -0
  63. data/spec/smcat_renderer_spec.rb +19 -0
  64. data/spec/spec_helper.rb +31 -0
  65. data/spec/svgbob_renderer_spec.rb +27 -0
  66. data/spec/syntrax_renderer_spec.rb +19 -0
  67. data/spec/utils_spec.rb +163 -0
  68. data/spec/vega_renderer_spec.rb +19 -0
  69. data/spec/wavedrom_renderer_spec.rb +19 -0
  70. metadata +115 -95
  71. data/lib/jekyll-diagrams/block.rb +0 -51
  72. data/test/block_test.rb +0 -6
  73. data/test/blockdiag_test.rb +0 -28
  74. data/test/erd_test.rb +0 -25
  75. data/test/rendering_test.rb +0 -20
  76. data/test/svgbob_test.rb +0 -22
  77. data/test/test_helper.rb +0 -22
@@ -1,25 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'plantuml/renderer'
4
+ require_relative 'plantuml/block'
5
+
3
6
  module Jekyll
4
7
  module Diagrams
5
- class PlantUMLBlock < Block
6
- XML_REGEX = /^<\?xml([^>]|\n)*>\n?/.freeze
7
-
8
- def render_svg(code, config)
9
- command = build_command(config)
10
-
11
- svg = render_with_stdin_stdout(command, code)
12
- svg.sub!(XML_REGEX, '')
13
- end
14
-
15
- def build_command(_config)
16
- jar = Diagrams.vendor_path('plantuml.1.2020.1.jar')
17
-
18
- options = +Diagrams.run_jar(jar)
19
- options << ' -tsvg -pipe'
20
- end
21
- end
8
+ Liquid::Template.register_tag(:plantuml, PlantUMLBlock)
22
9
  end
23
10
  end
24
-
25
- Liquid::Template.register_tag(:plantuml, Jekyll::Diagrams::PlantUMLBlock)
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ class PlantUMLBlock < BasicBlock
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ class PlantUMLRenderer < BasicRenderer
6
+ XML_REGEX = /^<\?xml([^>]|\n)*>\n?/.freeze
7
+
8
+ def render_svg(code, config)
9
+ command = build_command(config)
10
+
11
+ svg = render_with_stdin_stdout(command, code)
12
+ svg.sub!(XML_REGEX, '')
13
+ end
14
+
15
+ def build_command(_config)
16
+ jar = Utils.vendor_path('plantuml.1.2020.1.jar')
17
+
18
+ options = +Utils.run_jar(jar)
19
+ options << ' -tsvg -pipe'
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,32 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'smcat/renderer'
4
+ require_relative 'smcat/block'
5
+
3
6
  module Jekyll
4
7
  module Diagrams
5
- class SMCatBlock < Block
6
- XML_REGEX = /^<\?xml(([^>]|\n)*>\n?){2}/.freeze
7
- CONFIGURATIONS = %w[direction engine input-type].freeze
8
-
9
- def render_svg(code, config)
10
- command = build_command(config)
11
-
12
- svg = render_with_tempfile(command, code) do |input, output|
13
- "#{input} --output-to #{output}"
14
- end
15
-
16
- svg.sub!(XML_REGEX, '')
17
- end
18
-
19
- def build_command(config)
20
- command = +'smcat'
21
-
22
- CONFIGURATIONS.each do |conf|
23
- command << " --#{conf} #{config[conf]}" if config.key?(conf)
24
- end
25
-
26
- command
27
- end
28
- end
8
+ Liquid::Template.register_tag(:smcat, SMCatBlock)
29
9
  end
30
10
  end
31
-
32
- Liquid::Template.register_tag(:smcat, Jekyll::Diagrams::SMCatBlock)
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ class SMCatBlock < BasicBlock
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ class SMCatRenderer < BasicRenderer
6
+ XML_REGEX = /^<\?xml(([^>]|\n)*>\n?){2}/.freeze
7
+ CONFIGURATIONS = %w[direction engine input-type].freeze
8
+
9
+ def render_svg(code, config)
10
+ command = build_command(config)
11
+
12
+ svg = render_with_tempfile(command, code) do |input, output|
13
+ "#{input} --output-to #{output}"
14
+ end
15
+
16
+ svg.sub!(XML_REGEX, '')
17
+ end
18
+
19
+ def build_command(config)
20
+ command = +'smcat'
21
+
22
+ CONFIGURATIONS.each do |conf|
23
+ command << " --#{conf} #{config[conf]}" if config.key?(conf)
24
+ end
25
+
26
+ command
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,27 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'svgbob/renderer'
4
+ require_relative 'svgbob/block'
5
+
3
6
  module Jekyll
4
7
  module Diagrams
5
- class SvgbobBlock < Block
6
- CONFIGURATIONS = %w[font-family font-size scale stroke-width].freeze
7
-
8
- def render_svg(code, config)
9
- command = build_command(config)
10
-
11
- render_with_stdin_stdout(command, code)
12
- end
13
-
14
- def build_command(config)
15
- command = +'svgbob'
16
-
17
- CONFIGURATIONS.each do |conf|
18
- command << " --#{conf} #{config[conf]}" if config.key?(conf)
19
- end
20
-
21
- command
22
- end
23
- end
8
+ Liquid::Template.register_tag(:svgbob, SvgbobBlock)
24
9
  end
25
10
  end
26
-
27
- Liquid::Template.register_tag(:svgbob, Jekyll::Diagrams::SvgbobBlock)
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ class SvgbobBlock < BasicBlock
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ class SvgbobRenderer < BasicRenderer
6
+ CONFIGURATIONS = %w[font-family font-size scale stroke-width].freeze
7
+
8
+ def render_svg(code, config)
9
+ command = build_command(config)
10
+
11
+ render_with_stdin_stdout(command, code)
12
+ end
13
+
14
+ def build_command(config)
15
+ command = +'svgbob'
16
+
17
+ CONFIGURATIONS.each do |conf|
18
+ command << " --#{conf} #{config[conf]}" if config.key?(conf)
19
+ end
20
+
21
+ command
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,29 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'syntrax/renderer'
4
+ require_relative 'syntrax/block'
5
+
3
6
  module Jekyll
4
7
  module Diagrams
5
- class SyntraxBlock < Block
6
- CONFIGURATIONS = %w[scale style].freeze
7
-
8
- def render_svg(code, config)
9
- command = build_command(config)
10
-
11
- render_with_tempfile(command, code) do |input, output|
12
- "--input #{input} --output #{output}"
13
- end
14
- end
15
-
16
- def build_command(config)
17
- command = +'syntrax'
18
-
19
- CONFIGURATIONS.each do |conf|
20
- command << " --#{conf} #{config[conf]}" if config.key?(conf)
21
- end
22
-
23
- command
24
- end
25
- end
8
+ Liquid::Template.register_tag(:syntrax, SyntraxBlock)
26
9
  end
27
10
  end
28
-
29
- Liquid::Template.register_tag(:syntrax, Jekyll::Diagrams::SyntraxBlock)
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ class SyntraxBlock < BasicBlock
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ class SyntraxRenderer < BasicRenderer
6
+ CONFIGURATIONS = %w[scale style].freeze
7
+
8
+ def render_svg(code, config)
9
+ command = build_command(config)
10
+
11
+ render_with_tempfile(command, code) do |input, output|
12
+ "--input #{input} --output #{output}"
13
+ end
14
+ end
15
+
16
+ def build_command(config)
17
+ command = +'syntrax'
18
+
19
+ CONFIGURATIONS.each do |conf|
20
+ command << " --#{conf} #{config[conf]}" if config.key?(conf)
21
+ end
22
+
23
+ command
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ module Utils
6
+ module_function
7
+
8
+ # Return configuration of Jekyll Diagrams
9
+ #
10
+ # @param context Liquid::Template
11
+ # @return Configuration
12
+ def configuration(context)
13
+ site_config = context.registers[:site].config
14
+ page_config = context.registers[:page]
15
+
16
+ site_config.merge(page_config)
17
+ end
18
+
19
+ # @param context Liquid::Template
20
+ def config_for(context, name)
21
+ configuration(context).dig(Diagrams.config_name, name) || {}
22
+ end
23
+
24
+ # Return error mode in user configuration
25
+ #
26
+ # @param context Liquid::Template
27
+ def error_mode(context)
28
+ key = 'error_mode'
29
+ config = configuration(context)
30
+
31
+ liquid_mode = config.dig('liquid', key)
32
+ custom_mode = config.dig(Diagrams.config_name, key)
33
+
34
+ (custom_mode || liquid_mode || Diagrams.default_error_mode).to_sym
35
+ end
36
+
37
+ def handle_error(context, error)
38
+ topic = Diagrams.logger_topic
39
+ mode = error_mode(context)
40
+
41
+ case mode
42
+ when :lax
43
+ ''
44
+ when :warn
45
+ Jekyll.logger.warn topic, error
46
+ error
47
+ when :strict
48
+ Jekyll.logger.abort_with topic, error
49
+ else
50
+ raise Errors::UnkownErrorModeError, mode
51
+ end
52
+ end
53
+
54
+ def vendor_path(file = '')
55
+ File.join(File.expand_path('../../vendor', __dir__), file)
56
+ end
57
+
58
+ def run_jar(jar)
59
+ "java -Djava.awt.headless=true -jar #{jar} "
60
+ end
61
+
62
+ def normalized_attrs(attrs, prefix:, sep: '=')
63
+ attrs =
64
+ case attrs
65
+ when String
66
+ attrs
67
+ when Array
68
+ attrs.join(prefix)
69
+ when Hash
70
+ attrs.map { |k, v| "#{k}#{sep}#{v}" }.join(prefix)
71
+ end
72
+
73
+ "#{prefix}#{attrs}"
74
+ end
75
+
76
+ def wrap_class(content, class_names)
77
+ <<~CONTENT
78
+ <div class='#{Diagrams.config_name} diagrams #{class_names}'>
79
+ #{content}
80
+ </div>
81
+ CONTENT
82
+ end
83
+ end
84
+ end
85
+ end
@@ -1,33 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'vega/renderer'
4
+ require_relative 'vega/block'
5
+
3
6
  module Jekyll
4
7
  module Diagrams
5
- class VegaBlock < Block
6
- CONFIGURATIONS = %w[scale].freeze
7
-
8
- def render_svg(code, config)
9
- if block_name == 'vegalite'
10
- code = render_with_stdin_stdout('vl2vg', code)
11
- end
12
-
13
- command = build_command(config)
14
-
15
- render_with_stdin_stdout(command, code)
16
- end
17
-
18
- def build_command(config)
19
- command = +'vg2svg'
20
-
21
- CONFIGURATIONS.each do |conf|
22
- command << " --#{conf} #{config[conf]}" if config.key?(conf)
23
- end
24
-
25
- command
26
- end
8
+ %i[vega vegalite].each do |name|
9
+ Liquid::Template.register_tag(name, const_get("#{name.capitalize}Block"))
27
10
  end
28
11
  end
29
12
  end
30
-
31
- %i[vega vegalite].each do |tag|
32
- Liquid::Template.register_tag(tag, Jekyll::Diagrams::VegaBlock)
33
- end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ %w[vega vegalite].each do |name|
6
+ const_set "#{name.capitalize}Block", Class.new(BasicBlock)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ %i[vega vegalite].each do |name|
6
+ renderer = Class.new(BasicRenderer) do
7
+ const_set :CONFIGURATIONS, %w[scale].freeze
8
+
9
+ def render_svg(code, config)
10
+ if @block_name == 'vegalite'
11
+ code = render_with_stdin_stdout('vl2vg', code)
12
+ end
13
+
14
+ command = build_command(config)
15
+
16
+ render_with_stdin_stdout(command, code)
17
+ end
18
+
19
+ def build_command(config)
20
+ command = +'vg2svg'
21
+
22
+ self.class.const_get(:CONFIGURATIONS).each do |conf|
23
+ command << " --#{conf} #{config[conf]}" if config.key?(conf)
24
+ end
25
+
26
+ command
27
+ end
28
+ end
29
+
30
+ const_set "#{name.capitalize}Renderer", renderer
31
+ end
32
+ end
33
+ end