jekyll-diagrams 0.9.3 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Diagrams
5
- VERSION = '0.9.3'
5
+ VERSION = '0.10.0'
6
6
  end
7
7
  end
@@ -1,21 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'wavedrom/renderer'
4
+ require_relative 'wavedrom/block'
5
+
3
6
  module Jekyll
4
7
  module Diagrams
5
- class WavedromBlock < Block
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
8
+ Liquid::Template.register_tag(:wavedrom, WavedromBlock)
18
9
  end
19
10
  end
20
-
21
- Liquid::Template.register_tag(:wavedrom, Jekyll::Diagrams::WavedromBlock)
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Diagrams
5
+ class WavedromBlock < 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 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
@@ -0,0 +1,70 @@
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
@@ -0,0 +1,69 @@
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
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Jekyll::Diagrams::BlockdiagRenderer do
6
+ subject(:renderer) do
7
+ described_class.new(Liquid::ParseContext.new, '')
8
+ end
9
+
10
+ describe '#build_command' do
11
+ context 'when config is empty' do
12
+ let(:config) { {} }
13
+
14
+ it 'build command' do
15
+ expect(renderer.build_command(config)).to match '-T svg --nodoctype'
16
+ end
17
+ end
18
+
19
+ context 'when switch is true' do
20
+ let(:config) { { 'antialias' => true } }
21
+
22
+ it 'build command' do
23
+ expect(renderer.build_command(config)).to match '--antialias'
24
+ end
25
+ end
26
+
27
+ context 'when switch is false' do
28
+ let(:config) { { 'antialias' => false } }
29
+
30
+ it 'build command' do
31
+ expect(renderer.build_command(config)).not_to match '--antialias'
32
+ end
33
+ end
34
+
35
+ context 'when options with value' do
36
+ let(:config) { { 'size' => 3 } }
37
+
38
+ it 'build command' do
39
+ expect(renderer.build_command(config)).to match '--size=3'
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Jekyll::Diagrams::ErdRenderer do
6
+ subject(:renderer) do
7
+ described_class.new(Liquid::ParseContext.new, '')
8
+ end
9
+
10
+ describe '#build_command' do
11
+ context 'when config is empty' do
12
+ let(:config) { {} }
13
+
14
+ it 'build command' do
15
+ expect(renderer.build_command(config)).to eq 'erd --fmt=svg'
16
+ end
17
+ end
18
+
19
+ context 'when switch is true' do
20
+ let(:config) { { 'dot-entity' => true } }
21
+
22
+ it 'build command' do
23
+ expect(renderer.build_command(config)).to match '--dot-entity'
24
+ end
25
+ end
26
+
27
+ context 'when switch is false' do
28
+ let(:config) { { 'dot-entity' => false } }
29
+
30
+ it 'build command' do
31
+ expect(renderer.build_command(config)).not_to match '--dot-entity'
32
+ end
33
+ end
34
+
35
+ context 'when options with value' do
36
+ let(:config) { { 'edge' => 'compound' } }
37
+
38
+ it 'build command' do
39
+ expect(renderer.build_command(config)).to match '--edge'
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Jekyll::Diagrams::GraphvizRenderer do
6
+ subject(:renderer) do
7
+ described_class.new(Liquid::ParseContext.new, '')
8
+ end
9
+
10
+ describe '#build_command' do
11
+ context 'when config is empty' do
12
+ subject { renderer.build_command(config) }
13
+
14
+ let(:config) { {} }
15
+
16
+ it { is_expected.to eq 'dot -Tsvg' }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Jekyll::Diagrams do
6
+ describe '.config_name' do
7
+ subject { described_class.config_name }
8
+
9
+ it { is_expected.to eq 'jekyll-diagrams' }
10
+ end
11
+
12
+ describe '.logger_topic' do
13
+ subject { described_class.logger_topic }
14
+
15
+ it { is_expected.to eq 'Jekyll Diagrams:' }
16
+ end
17
+
18
+ describe '.defaut_error_mode' do
19
+ subject { described_class.default_error_mode }
20
+
21
+ it { is_expected.to eq :warn }
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Jekyll::Diagrams::MermaidRenderer do
6
+ subject(:renderer) do
7
+ described_class.new(Liquid::ParseContext.new, '')
8
+ end
9
+
10
+ describe '#build_command' do
11
+ context 'when config is empty' do
12
+ subject { renderer.build_command(config) }
13
+
14
+ let(:config) { {} }
15
+
16
+ it { is_expected.to match 'mmdc --puppeteerConfigFile' }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Jekyll::Diagrams::NomnomlRenderer do
6
+ subject(:renderer) do
7
+ described_class.new(Liquid::ParseContext.new, '')
8
+ end
9
+
10
+ describe '#build_command' do
11
+ context 'when config is empty' do
12
+ subject { renderer.build_command(config) }
13
+
14
+ let(:config) { {} }
15
+
16
+ it { is_expected.to eq 'nomnoml' }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Jekyll::Diagrams::PlantUMLRenderer do
6
+ subject(:renderer) do
7
+ described_class.new(Liquid::ParseContext.new, '')
8
+ end
9
+
10
+ describe '#build_command' do
11
+ context 'when config is empty' do
12
+ subject { renderer.build_command(config) }
13
+
14
+ let(:config) { {} }
15
+
16
+ it { is_expected.to match 'plantuml' }
17
+ it { is_expected.to match '-tsvg -pipe' }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Jekyll::Diagrams::Rendering do
6
+ describe '.render_with_stdin_stdout' do
7
+ it 'call render_with_command' do
8
+ allow(described_class).to receive(:render_with_command)
9
+
10
+ described_class.render_with_stdin_stdout('command', 'content')
11
+
12
+ expect(described_class).to have_received(:render_with_command).with(
13
+ 'command', :stdout, stdin_data: 'content'
14
+ )
15
+ end
16
+ end
17
+
18
+ describe '.render_with_tempfile' do
19
+ before do
20
+ allow(described_class).to receive(:render_with_command)
21
+
22
+ allow(Dir).to receive(:mktmpdir).and_yield('/tmp')
23
+ allow(File).to receive(:write)
24
+ allow(Tempfile).to receive_message_chain(:new, :close!)
25
+ allow(Tempfile).to receive_message_chain(:new, :path)
26
+ end
27
+
28
+ it 'call Dir.mktmpdir to create a direcory' do
29
+ allow(Dir).to receive(:mktmpdir)
30
+
31
+ described_class.render_with_tempfile('command', 'content')
32
+
33
+ expect(Dir).to have_received(:mktmpdir)
34
+ end
35
+
36
+ it 'call Tempfile.new twice to create temp file' do
37
+ described_class.render_with_tempfile('command', 'content') {}
38
+
39
+ expect(Tempfile).to have_received(:new).twice
40
+ end
41
+
42
+ it 'call render_with_command' do
43
+ described_class.render_with_tempfile('command', 'content') {}
44
+
45
+ expect(described_class).to have_received(:render_with_command)
46
+ end
47
+ end
48
+
49
+ describe '.render_with_command' do
50
+ it 'call Open3.capture3 to render' do
51
+ status = Object.new
52
+ allow(status).to receive(:success?).and_return(true)
53
+ allow(Open3).to receive(:capture3).and_return(['o', 'e', status])
54
+
55
+ described_class.render_with_command('command')
56
+
57
+ expect(Open3).to have_received(:capture3)
58
+ end
59
+
60
+ context 'when command not found' do
61
+ it 'raise a command not found error' do
62
+ allow(Open3).to receive(:capture3).and_raise(Errno::ENOENT)
63
+
64
+ expect do
65
+ described_class.render_with_command('command_that_is_not_exist')
66
+ end.to raise_error Jekyll::Diagrams::Errors::CommandNotFoundError
67
+ end
68
+ end
69
+
70
+ context 'when rendering failed' do
71
+ before do
72
+ status = Object.new
73
+ allow(status).to receive(:success?).and_return(false)
74
+ allow(Open3).to receive(:capture3).and_return(['o', 'e', status])
75
+ end
76
+
77
+ it 'raise a rendering failed error' do
78
+ expect do
79
+ described_class.render_with_command('command_that_will_failed')
80
+ end.to raise_error Jekyll::Diagrams::Errors::RenderingFailedError
81
+ end
82
+ end
83
+
84
+ context 'when output is stdout' do
85
+ before do
86
+ status = Object.new
87
+ allow(status).to receive(:success?).and_return(true)
88
+ allow(Open3).to receive(:capture3).and_return(['o', 'e', status])
89
+ end
90
+
91
+ it 'read output from stdout' do
92
+ expect(described_class.render_with_command('cmd', :stdout)).to eq 'o'
93
+ end
94
+ end
95
+
96
+ context 'when output is a file' do
97
+ before do
98
+ status = Object.new
99
+ allow(status).to receive(:success?).and_return(true)
100
+ allow(Open3).to receive(:capture3).and_return(['o', 'e', status])
101
+ allow(File).to receive(:read)
102
+ end
103
+
104
+ it 'read output from the file' do
105
+ described_class.render_with_command('cmd', 'a_file')
106
+
107
+ expect(File).to have_received(:read).with('a_file')
108
+ end
109
+ end
110
+ end
111
+ end