jekyll-diagrams 0.10.0 → 0.11.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +26 -411
  3. data/features/{blockdiag/block.feature → blockdiag_block.feature} +0 -0
  4. data/features/{graphviz/block.feature → graphviz_block.feature} +0 -0
  5. data/features/{graphviz/config.feature → graphviz_config.feature} +0 -0
  6. data/features/{mermaid/block.feature → mermaid_block.feature} +0 -0
  7. data/features/{nomnoml/block.feature → nomnoml_block.feature} +0 -0
  8. data/features/{plantuml/block.feature → plantuml_block.feature} +0 -0
  9. data/features/{smcat/block.feature → smcat_block.feature} +0 -0
  10. data/features/step_definitions/{jekyll-diagrams.rb → diagrams.rb} +0 -0
  11. data/features/support/env.rb +4 -1
  12. data/features/{syntrax/block.feature → syntrax_block.feature} +0 -0
  13. data/features/{vega/block.feature → vega_block.feature} +0 -0
  14. data/features/{wavedrom/block.feature → wavedrom_block.feature} +0 -0
  15. data/lib/jekyll-diagrams.rb +1 -38
  16. data/lib/jekyll_diagrams.rb +85 -0
  17. data/lib/jekyll_diagrams/version.rb +5 -0
  18. data/spec/{utils_spec.rb → jekyll_diagrams_spec.rb} +18 -70
  19. data/spec/spec_helper.rb +10 -8
  20. metadata +85 -129
  21. data/lib/jekyll-diagrams/basic_block.rb +0 -28
  22. data/lib/jekyll-diagrams/basic_renderer.rb +0 -38
  23. data/lib/jekyll-diagrams/blockdiag.rb +0 -12
  24. data/lib/jekyll-diagrams/blockdiag/block.rb +0 -9
  25. data/lib/jekyll-diagrams/blockdiag/renderer.rb +0 -40
  26. data/lib/jekyll-diagrams/erd.rb +0 -10
  27. data/lib/jekyll-diagrams/erd/block.rb +0 -8
  28. data/lib/jekyll-diagrams/erd/renderer.rb +0 -34
  29. data/lib/jekyll-diagrams/errors.rb +0 -24
  30. data/lib/jekyll-diagrams/graphviz.rb +0 -10
  31. data/lib/jekyll-diagrams/graphviz/block.rb +0 -8
  32. data/lib/jekyll-diagrams/graphviz/renderer.rb +0 -40
  33. data/lib/jekyll-diagrams/mermaid.rb +0 -10
  34. data/lib/jekyll-diagrams/mermaid/block.rb +0 -8
  35. data/lib/jekyll-diagrams/mermaid/renderer.rb +0 -29
  36. data/lib/jekyll-diagrams/nomnoml.rb +0 -10
  37. data/lib/jekyll-diagrams/nomnoml/block.rb +0 -8
  38. data/lib/jekyll-diagrams/nomnoml/renderer.rb +0 -19
  39. data/lib/jekyll-diagrams/plantuml.rb +0 -10
  40. data/lib/jekyll-diagrams/plantuml/block.rb +0 -8
  41. data/lib/jekyll-diagrams/plantuml/renderer.rb +0 -23
  42. data/lib/jekyll-diagrams/rendering.rb +0 -67
  43. data/lib/jekyll-diagrams/smcat.rb +0 -10
  44. data/lib/jekyll-diagrams/smcat/block.rb +0 -8
  45. data/lib/jekyll-diagrams/smcat/renderer.rb +0 -30
  46. data/lib/jekyll-diagrams/svgbob.rb +0 -10
  47. data/lib/jekyll-diagrams/svgbob/block.rb +0 -8
  48. data/lib/jekyll-diagrams/svgbob/renderer.rb +0 -25
  49. data/lib/jekyll-diagrams/syntrax.rb +0 -10
  50. data/lib/jekyll-diagrams/syntrax/block.rb +0 -8
  51. data/lib/jekyll-diagrams/syntrax/renderer.rb +0 -27
  52. data/lib/jekyll-diagrams/utils.rb +0 -85
  53. data/lib/jekyll-diagrams/vega.rb +0 -12
  54. data/lib/jekyll-diagrams/vega/block.rb +0 -9
  55. data/lib/jekyll-diagrams/vega/renderer.rb +0 -33
  56. data/lib/jekyll-diagrams/version.rb +0 -7
  57. data/lib/jekyll-diagrams/wavedrom.rb +0 -10
  58. data/lib/jekyll-diagrams/wavedrom/block.rb +0 -8
  59. data/lib/jekyll-diagrams/wavedrom/renderer.rb +0 -19
  60. data/spec/basic_block_spec.rb +0 -70
  61. data/spec/basic_renderer_spec.rb +0 -69
  62. data/spec/blockdiag_renderer_spec.rb +0 -43
  63. data/spec/erd_renderer_spec.rb +0 -43
  64. data/spec/graphviz_renderer_spec.rb +0 -19
  65. data/spec/jekyll-diagrams_spec.rb +0 -23
  66. data/spec/mermaid_renderer_spec.rb +0 -19
  67. data/spec/nomnoml_renderer_spec.rb +0 -19
  68. data/spec/plantuml_renderer_spec.rb +0 -20
  69. data/spec/rendering_spec.rb +0 -111
  70. data/spec/smcat_renderer_spec.rb +0 -19
  71. data/spec/svgbob_renderer_spec.rb +0 -27
  72. data/spec/syntrax_renderer_spec.rb +0 -19
  73. data/spec/vega_renderer_spec.rb +0 -19
  74. data/spec/wavedrom_renderer_spec.rb +0 -19
  75. data/vendor/mermaid_puppeteer_config.json +0 -3
  76. data/vendor/plantuml.1.2020.1.jar +0 -0
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'smcat/renderer'
4
- require_relative 'smcat/block'
5
-
6
- module Jekyll
7
- module Diagrams
8
- Liquid::Template.register_tag(:smcat, SMCatBlock)
9
- end
10
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jekyll
4
- module Diagrams
5
- class SMCatBlock < BasicBlock
6
- end
7
- end
8
- end
@@ -1,30 +0,0 @@
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,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'svgbob/renderer'
4
- require_relative 'svgbob/block'
5
-
6
- module Jekyll
7
- module Diagrams
8
- Liquid::Template.register_tag(:svgbob, SvgbobBlock)
9
- end
10
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jekyll
4
- module Diagrams
5
- class SvgbobBlock < BasicBlock
6
- end
7
- end
8
- end
@@ -1,25 +0,0 @@
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,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'syntrax/renderer'
4
- require_relative 'syntrax/block'
5
-
6
- module Jekyll
7
- module Diagrams
8
- Liquid::Template.register_tag(:syntrax, SyntraxBlock)
9
- end
10
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jekyll
4
- module Diagrams
5
- class SyntraxBlock < BasicBlock
6
- end
7
- end
8
- end
@@ -1,27 +0,0 @@
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
@@ -1,85 +0,0 @@
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,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'vega/renderer'
4
- require_relative 'vega/block'
5
-
6
- module Jekyll
7
- module Diagrams
8
- %i[vega vegalite].each do |name|
9
- Liquid::Template.register_tag(name, const_get("#{name.capitalize}Block"))
10
- end
11
- end
12
- end
@@ -1,9 +0,0 @@
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
@@ -1,33 +0,0 @@
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
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jekyll
4
- module Diagrams
5
- VERSION = '0.10.0'
6
- end
7
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'wavedrom/renderer'
4
- require_relative 'wavedrom/block'
5
-
6
- module Jekyll
7
- module Diagrams
8
- Liquid::Template.register_tag(:wavedrom, WavedromBlock)
9
- end
10
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jekyll
4
- module Diagrams
5
- class WavedromBlock < BasicBlock
6
- end
7
- end
8
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jekyll
4
- module Diagrams
5
- class WavedromRenderer < BasicRenderer
6
- def render_svg(code, config)
7
- command = build_command(config)
8
-
9
- render_with_tempfile(command, code) do |input, output|
10
- "--input #{input} --svg #{output}"
11
- end
12
- end
13
-
14
- def build_command(_config)
15
- 'wavedrom-cli'
16
- end
17
- end
18
- end
19
- end
@@ -1,70 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Jekyll::Diagrams::BasicBlock do
6
- before do
7
- stub_const('TestBlock', Class.new(described_class))
8
- end
9
-
10
- describe '.renderer_name' do
11
- subject { TestBlock.renderer_name }
12
-
13
- it { is_expected.to eq 'TestRenderer' }
14
- end
15
-
16
- describe '.renderer' do
17
- subject { TestBlock.renderer }
18
-
19
- context 'when the renderer is not found' do
20
- it 'raise an renderer not found error' do
21
- expect { TestBlock.renderer }.to raise_error(
22
- Jekyll::Diagrams::Errors::RendererNotFoundError
23
- )
24
- end
25
- end
26
-
27
- context 'when the renderer is found' do
28
- before { stub_const('TestRenderer', Class.new) }
29
-
30
- it { is_expected.to be TestRenderer }
31
- end
32
- end
33
-
34
- describe '#render' do
35
- context 'when the renderer is not found' do
36
- it 'raise renderer not found error' do
37
- allow(Jekyll::Diagrams::Utils).to receive(:handle_error)
38
-
39
- Liquid::Template.register_tag(:test, TestBlock)
40
-
41
- content = '{% test %}test{% endtest %}'
42
- context = Liquid::Template.parse(content)
43
- context.render(context_with_config)
44
-
45
- expect(Jekyll::Diagrams::Utils).to have_received(:handle_error)
46
- end
47
- end
48
-
49
- context 'when the renderer is found' do
50
- before do
51
- renderer = Class.new do
52
- def self.render(_context, input, _name)
53
- input
54
- end
55
- end
56
-
57
- stub_const('TestRenderer', renderer)
58
-
59
- Liquid::Template.register_tag(:test, TestBlock)
60
- end
61
-
62
- it 'render the content with the renderer' do
63
- content = '{% test %}test{% endtest %}'
64
- context = Liquid::Template.parse(content)
65
-
66
- expect(context.render(context_with_config)).to eq 'test'
67
- end
68
- end
69
- end
70
- end
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Jekyll::Diagrams::BasicRenderer do
6
- describe '.render' do
7
- it 'create an instance and render' do
8
- allow(described_class).to receive_message_chain(:new, :render)
9
-
10
- described_class.render('context', 'content', { key: 'value' })
11
-
12
- expect(described_class).to have_received(:new).with(
13
- 'context', 'content', { key: 'value' }
14
- )
15
- end
16
- end
17
-
18
- describe '#render' do
19
- it 'call render_svg to render' do
20
- renderer = described_class.new('context', 'content')
21
-
22
- allow(renderer).to receive(:render_svg)
23
- allow(renderer).to receive(:configuration)
24
- allow(Jekyll::Diagrams::Utils).to receive(:wrap_class)
25
-
26
- renderer.render
27
-
28
- expect(renderer).to have_received(:render_svg)
29
- end
30
-
31
- context 'when rendering successfully' do
32
- it 'wrap the output' do
33
- renderer = described_class.new(context_with_config, '')
34
-
35
- allow(renderer).to receive(:render_svg)
36
- allow(Jekyll::Diagrams::Utils).to receive(:wrap_class)
37
-
38
- renderer.render
39
-
40
- expect(Jekyll::Diagrams::Utils).to have_received(:wrap_class)
41
- end
42
- end
43
-
44
- context 'when rendering failed' do
45
- it 'handle the error and wrap the return value' do
46
- renderer = described_class.new(context_with_config, '')
47
-
48
- allow(renderer).to receive(:render_svg).and_raise
49
- allow(Jekyll::Diagrams::Utils).to receive(:handle_error)
50
- allow(Jekyll::Diagrams::Utils).to receive(:wrap_class)
51
-
52
- renderer.render
53
-
54
- expect(Jekyll::Diagrams::Utils).to have_received(:handle_error)
55
- expect(Jekyll::Diagrams::Utils).to have_received(:wrap_class)
56
- end
57
- end
58
- end
59
-
60
- describe '#render_svg' do
61
- it 'raise not implemented error' do
62
- renderer = described_class.new('context', 'content')
63
-
64
- expect do
65
- renderer.send(:render_svg, '', '')
66
- end.to raise_error NotImplementedError
67
- end
68
- end
69
- end