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,38 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'blockdiag/renderer'
4
+ require_relative 'blockdiag/block'
5
+
3
6
  module Jekyll
4
7
  module Diagrams
5
- class BlockdiagBlock < Block
6
- CONFIGURATIONS = %w[config font fontmap size].freeze
7
- SWITCHES = {
8
- 'antialias' => false
9
- }.freeze
10
-
11
- def render_svg(code, config)
12
- command = build_command(config)
13
-
14
- render_with_tempfile(command, code) do |input, output|
15
- "#{input} -o #{output}"
16
- end
17
- end
18
-
19
- def build_command(config)
20
- command = +"#{block_name} -T svg --nodoctype"
21
-
22
- SWITCHES.merge(config.slice(*SWITCHES.keys)).each do |switch, value|
23
- command << " --#{switch}" if value != false
24
- end
25
-
26
- CONFIGURATIONS.each do |conf|
27
- command << " --#{conf}=#{config[conf]}" if config.key?(conf)
28
- end
29
-
30
- command
31
- end
8
+ %i[blockdiag seqdiag actdiag nwdiag rackdiag packetdiag].each do |name|
9
+ Liquid::Template.register_tag(name, const_get("#{name.capitalize}Block"))
32
10
  end
33
11
  end
34
12
  end
35
-
36
- %i[blockdiag seqdiag actdiag nwdiag rackdiag packetdiag].each do |tag|
37
- Liquid::Template.register_tag(tag, Jekyll::Diagrams::BlockdiagBlock)
38
- end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ %i[blockdiag seqdiag actdiag nwdiag rackdiag packetdiag].each do |name|
6
+ const_set "#{name.capitalize}Block", Class.new(BasicBlock)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ %i[blockdiag seqdiag actdiag nwdiag rackdiag packetdiag].each do |name|
6
+ renderer = Class.new(BasicRenderer) do
7
+ const_set :CONFIGURATIONS, %w[config font fontmap size].freeze
8
+ const_set :SWITCHES, {
9
+ 'antialias' => false
10
+ }.freeze
11
+
12
+ def render_svg(code, config)
13
+ command = build_command(config)
14
+
15
+ render_with_tempfile(command, code) do |input, output|
16
+ "#{input} -o #{output}"
17
+ end
18
+ end
19
+
20
+ def build_command(config)
21
+ command = +"#{@diagram} -T svg --nodoctype"
22
+
23
+ switches = self.class.const_get(:SWITCHES)
24
+
25
+ switches.merge(config.slice(*switches.keys)).each do |switch, value|
26
+ command << " --#{switch}" if value != false
27
+ end
28
+
29
+ self.class.const_get(:CONFIGURATIONS).each do |conf|
30
+ command << " --#{conf}=#{config[conf]}" if config.key?(conf)
31
+ end
32
+
33
+ command
34
+ end
35
+ end
36
+
37
+ const_set "#{name.capitalize}Renderer", renderer
38
+ end
39
+ end
40
+ end
@@ -1,36 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'erd/renderer'
4
+ require_relative 'erd/block'
5
+
3
6
  module Jekyll
4
7
  module Diagrams
5
- class ErdBlock < Block
6
- XML_REGEX = /^<\?xml(([^>]|\n)*>\n?){2}/.freeze
7
- CONFIGURATIONS = %w[config edge].freeze
8
- SWITCHES = {
9
- 'dot-entity' => false
10
- }.freeze
11
-
12
- def render_svg(code, config)
13
- command = build_command(config)
14
-
15
- svg = render_with_stdin_stdout(command, code)
16
- svg.sub!(XML_REGEX, '')
17
- end
18
-
19
- def build_command(config)
20
- command = +'erd --fmt=svg'
21
-
22
- SWITCHES.merge(config.slice(*SWITCHES.keys)).each do |switch, value|
23
- command << " --#{switch}" if value != false
24
- end
25
-
26
- CONFIGURATIONS.each do |conf|
27
- command << " --#{conf}=#{config[conf]}" if config.key?(conf)
28
- end
29
-
30
- command
31
- end
32
- end
8
+ Liquid::Template.register_tag(:erd, ErdBlock)
33
9
  end
34
10
  end
35
-
36
- Liquid::Template.register_tag(:erd, Jekyll::Diagrams::ErdBlock)
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ class ErdBlock < BasicBlock
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ class ErdRenderer < BasicRenderer
6
+ XML_REGEX = /^<\?xml(([^>]|\n)*>\n?){2}/.freeze
7
+ CONFIGURATIONS = %w[config edge].freeze
8
+ SWITCHES = {
9
+ 'dot-entity' => false
10
+ }.freeze
11
+
12
+ def render_svg(code, config)
13
+ command = build_command(config)
14
+
15
+ svg = render_with_stdin_stdout(command, code)
16
+ svg.sub!(XML_REGEX, '')
17
+ end
18
+
19
+ def build_command(config)
20
+ command = +'erd --fmt=svg'
21
+
22
+ SWITCHES.merge(config.slice(*SWITCHES.keys)).each do |switch, value|
23
+ command << " --#{switch}" if value != false
24
+ end
25
+
26
+ CONFIGURATIONS.each do |conf|
27
+ command << " --#{conf}=#{config[conf]}" if config.key?(conf)
28
+ end
29
+
30
+ command
31
+ end
32
+ end
33
+ end
34
+ end
@@ -3,23 +3,22 @@
3
3
  module Jekyll
4
4
  module Diagrams
5
5
  module Errors
6
- BaseError = Class.new(::StandardError) do
7
- def initialize(msg)
8
- @msg = msg
9
- end
10
- end
6
+ class BasicError < ::StandardError
7
+ def initialize(val)
8
+ # Jekyll::...::CommandNotFoundError -> 'CommandNotFoundError'
9
+ klass = self.class.name.split('::').last
10
+ # 'CommandNotFound' -> 'Command Not Found'
11
+ prefix = klass.sub(/Error$/, '').split(/(?=[A-Z])/).join(' ')
11
12
 
12
- CommandNotFoundError = Class.new(BaseError) do
13
- def message
14
- "Command Not Found: #{@msg}"
13
+ # "Command Not Found: raw message"
14
+ super("#{prefix}: #{val}")
15
15
  end
16
16
  end
17
17
 
18
- RenderingFailedError = Class.new(BaseError) do
19
- def message
20
- "Rendering Failed: #{@msg}"
21
- end
22
- end
18
+ CommandNotFoundError = Class.new(BasicError)
19
+ RenderingFailedError = Class.new(BasicError)
20
+ RendererNotFoundError = Class.new(BasicError)
21
+ UnkownErrorModeError = Class.new(BasicError)
23
22
  end
24
23
  end
25
24
  end
@@ -1,40 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'graphviz/renderer'
4
+ require_relative 'graphviz/block'
5
+
3
6
  module Jekyll
4
7
  module Diagrams
5
- class GraphvizBlock < Block
6
- XML_REGEX = /^<\?xml(([^>]|\n)*>\n?){2}/.freeze
7
- CONFIGRATIONS = {
8
- 'K' => 'default_layout',
9
- 'G' => 'graph_attributes',
10
- 'N' => 'node_attributes',
11
- 'E' => 'edge_attributes'
12
- }.freeze
13
-
14
- def render_svg(code, config)
15
- command = build_command(config)
16
-
17
- svg = render_with_stdin_stdout(command, code).force_encoding(
18
- config.fetch('encoding', 'utf-8')
19
- )
20
-
21
- svg.sub!(XML_REGEX, '')
22
- end
23
-
24
- def build_command(config)
25
- command = +'dot -Tsvg'
26
-
27
- CONFIGRATIONS.each do |prefix, conf|
28
- next unless config.key?(conf)
29
-
30
- command << Diagrams.normalized_attrs(config[conf],
31
- prefix: " -#{prefix}")
32
- end
33
-
34
- command
35
- end
36
- end
8
+ Liquid::Template.register_tag(:graphviz, GraphvizBlock)
37
9
  end
38
10
  end
39
-
40
- Liquid::Template.register_tag(:graphviz, Jekyll::Diagrams::GraphvizBlock)
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ class GraphvizBlock < BasicBlock
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ class GraphvizRenderer < BasicRenderer
6
+ XML_REGEX = /^<\?xml(([^>]|\n)*>\n?){2}/.freeze
7
+ CONFIGRATIONS = {
8
+ 'K' => 'default_layout',
9
+ 'G' => 'graph_attributes',
10
+ 'N' => 'node_attributes',
11
+ 'E' => 'edge_attributes'
12
+ }.freeze
13
+
14
+ def render_svg(code, config)
15
+ command = build_command(config)
16
+
17
+ svg = render_with_stdin_stdout(command, code).force_encoding(
18
+ config.fetch('encoding', 'utf-8')
19
+ )
20
+
21
+ svg.sub!(XML_REGEX, '')
22
+ end
23
+
24
+ def build_command(config)
25
+ command = +'dot -Tsvg'
26
+
27
+ CONFIGRATIONS.each do |prefix, conf|
28
+ next unless config.key?(conf)
29
+
30
+ command << Utils.normalized_attrs(
31
+ config[conf],
32
+ prefix: " -#{prefix}"
33
+ )
34
+ end
35
+
36
+ command
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,31 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'mermaid/renderer'
4
+ require_relative 'mermaid/block'
5
+
3
6
  module Jekyll
4
7
  module Diagrams
5
- class MermaidBlock < Block
6
- CONFIGURATIONS = %w[theme width height backgroundColor
7
- configFile cssFile scale].freeze
8
-
9
- def render_svg(code, config)
10
- command = build_command(config)
11
-
12
- render_with_tempfile(command, code) do |input, output|
13
- "--input #{input} --output #{output}"
14
- end
15
- end
16
-
17
- def build_command(config)
18
- command = +'mmdc --puppeteerConfigFile '
19
- command << Diagrams.vendor_path('mermaid_puppeteer_config.json')
20
-
21
- CONFIGURATIONS.each do |conf|
22
- command << " --#{conf} #{config[conf]}" if config.key?(conf)
23
- end
24
-
25
- command
26
- end
27
- end
8
+ Liquid::Template.register_tag(:mermaid, MermaidBlock)
28
9
  end
29
10
  end
30
-
31
- Liquid::Template.register_tag(:mermaid, Jekyll::Diagrams::MermaidBlock)
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ class MermaidBlock < BasicBlock
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ class MermaidRenderer < BasicRenderer
6
+ CONFIGURATIONS = %w[theme width height backgroundColor
7
+ configFile cssFile scale].freeze
8
+
9
+ def render_svg(code, config)
10
+ command = build_command(config)
11
+
12
+ render_with_tempfile(command, code) do |input, output|
13
+ "--input #{input} --output #{output}"
14
+ end
15
+ end
16
+
17
+ def build_command(config)
18
+ command = +'mmdc --puppeteerConfigFile '
19
+ command << Utils.vendor_path('mermaid_puppeteer_config.json')
20
+
21
+ CONFIGURATIONS.each do |conf|
22
+ command << " --#{conf} #{config[conf]}" if config.key?(conf)
23
+ end
24
+
25
+ command
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,21 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'nomnoml/renderer'
4
+ require_relative 'nomnoml/block'
5
+
3
6
  module Jekyll
4
7
  module Diagrams
5
- class NomnomlBlock < Block
6
- def render_svg(code, config)
7
- command = build_command(config)
8
-
9
- render_with_tempfile(command, code) do |input, output|
10
- "#{input} #{output}"
11
- end
12
- end
13
-
14
- def build_command(_config)
15
- 'nomnoml'
16
- end
17
- end
8
+ Liquid::Template.register_tag(:nomnoml, NomnomlBlock)
18
9
  end
19
10
  end
20
-
21
- Liquid::Template.register_tag(:nomnoml, Jekyll::Diagrams::NomnomlBlock)
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ class NomnomlBlock < BasicBlock
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ class NomnomlRenderer < BasicRenderer
6
+ def render_svg(code, config)
7
+ command = build_command(config)
8
+
9
+ render_with_tempfile(command, code) do |input, output|
10
+ "#{input} #{output}"
11
+ end
12
+ end
13
+
14
+ def build_command(_config)
15
+ 'nomnoml'
16
+ end
17
+ end
18
+ end
19
+ end