jekyll-diagrams 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +83 -0
  3. data/.gitignore +4 -5
  4. data/.rubocop.yml +22 -0
  5. data/.simplecov +5 -0
  6. data/.travis.yml +48 -1
  7. data/Dockerfile +14 -12
  8. data/Gemfile +4 -1
  9. data/README.md +49 -21
  10. data/Rakefile +20 -2
  11. data/features/blockdiag.feature +20 -0
  12. data/features/graphviz.feature +22 -0
  13. data/features/mermaid.feature +21 -0
  14. data/features/nomnoml.feature +36 -0
  15. data/features/plantuml.feature +24 -0
  16. data/features/smcat.feature +29 -0
  17. data/features/step_definitions/jekyll-diagrams.rb +25 -0
  18. data/features/support/env.rb +33 -0
  19. data/features/svgbob.feature +22 -0
  20. data/features/syntrax.feature +22 -0
  21. data/features/vega.feature +32 -0
  22. data/features/wavedrom.feature +22 -0
  23. data/jekyll-diagrams.gemspec +13 -7
  24. data/lib/jekyll-diagrams.rb +3 -2
  25. data/lib/jekyll-diagrams/block.rb +5 -4
  26. data/lib/jekyll-diagrams/blockdiag.rb +9 -7
  27. data/lib/jekyll-diagrams/erd.rb +9 -6
  28. data/lib/jekyll-diagrams/graphviz.rb +12 -17
  29. data/lib/jekyll-diagrams/mermaid.rb +21 -18
  30. data/lib/jekyll-diagrams/nomnoml.rb +6 -4
  31. data/lib/jekyll-diagrams/plantuml.rb +8 -4
  32. data/lib/jekyll-diagrams/smcat.rb +10 -7
  33. data/lib/jekyll-diagrams/svgbob.rb +6 -4
  34. data/lib/jekyll-diagrams/syntrax.rb +8 -6
  35. data/lib/jekyll-diagrams/util.rb +78 -11
  36. data/lib/jekyll-diagrams/vega.rb +8 -5
  37. data/lib/jekyll-diagrams/version.rb +4 -2
  38. data/lib/jekyll-diagrams/wavedrom.rb +6 -4
  39. data/test/erd_test.rb +22 -0
  40. data/test/test_helper.rb +4 -7
  41. data/test/util_test.rb +20 -0
  42. metadata +54 -11
  43. data/lib/jekyll-diagrams/renderer.rb +0 -53
@@ -0,0 +1,21 @@
1
+ Feature: Mermaid
2
+
3
+
4
+ Scenario: Default configuration
5
+ Given I have a file 'mermaid.md' with content:
6
+ """
7
+ ---
8
+ ---
9
+
10
+ {% mermaid %}
11
+ sequenceDiagram
12
+ participant John
13
+ participant Alice
14
+ Alice->>John: Hello John, how are you?
15
+ John-->>Alice: Great!
16
+ {% endmermaid %}
17
+ """
18
+ When I run jekyll build
19
+ Then the file '_site/mermaid.html' should exist
20
+ And I should see 'diagrams mermaid' in '_site/mermaid.html'
21
+ And I should see svg output in '_site/mermaid.html'
@@ -0,0 +1,36 @@
1
+ Feature: Nomnoml
2
+
3
+
4
+ Scenario: Default configuration
5
+ Given I have a file 'nomnoml.md' with content:
6
+ """
7
+ ---
8
+ ---
9
+
10
+ {% nomnoml %}
11
+ [Pirate|eyeCount: Int|raid();pillage()|
12
+ [beard]--[parrot]
13
+ [beard]-:>[foul mouth]
14
+ ]
15
+
16
+ [<abstract>Marauder]<:--[Pirate]
17
+ [Pirate]- 0..7[mischief]
18
+ [jollyness]->[Pirate]
19
+ [jollyness]->[rum]
20
+ [jollyness]->[singing]
21
+ [Pirate]-> *[rum|tastiness: Int|swig()]
22
+ [Pirate]->[singing]
23
+ [singing]<->[rum]
24
+
25
+ [<start>st]->[<state>plunder]
26
+ [plunder]->[<choice>more loot]
27
+ [more loot]->[st]
28
+ [more loot] no ->[<end>e]
29
+
30
+ [<actor>Sailor] - [<usecase>shiver me;timbers]
31
+ {% endnomnoml %}
32
+ """
33
+ When I run jekyll build
34
+ Then the file '_site/nomnoml.html' should exist
35
+ And I should see 'diagrams nomnoml' in '_site/nomnoml.html'
36
+ And I should see svg output in '_site/nomnoml.html'
@@ -0,0 +1,24 @@
1
+ Feature: PlantUML
2
+
3
+
4
+ Scenario: Default configuration
5
+ Given I have a file 'plantuml.md' with content:
6
+ """
7
+ ---
8
+ ---
9
+
10
+ {% plantuml %}
11
+ @startuml
12
+ class Car
13
+
14
+ Driver - Car : drives >
15
+ Car *- Wheel : have 4 >
16
+ Car -- Person : < owns
17
+
18
+ @enduml
19
+ {% endplantuml %}
20
+ """
21
+ When I run jekyll build
22
+ Then the file '_site/plantuml.html' should exist
23
+ And I should see 'diagrams plantuml' in '_site/plantuml.html'
24
+ And I should see svg output in '_site/plantuml.html'
@@ -0,0 +1,29 @@
1
+ Feature: SMCat
2
+
3
+
4
+ Scenario: Default configuration
5
+ Given I have a file 'smcat.md' with content:
6
+ """
7
+ ---
8
+ ---
9
+
10
+ {% smcat %}
11
+ initial,
12
+ "tape player off",
13
+ "tape player on" {
14
+ stopped => playing : play;
15
+ playing => stopped : stop;
16
+ playing => paused : pause;
17
+ paused => playing : pause;
18
+ paused => stopped : stop;
19
+ };
20
+
21
+ initial => "tape player off";
22
+ "tape player off" => stopped : power;
23
+ "tape player on" => "tape player off" : power;
24
+ {% endsmcat %}
25
+ """
26
+ When I run jekyll build
27
+ Then the file '_site/smcat.html' should exist
28
+ And I should see 'diagrams smcat' in '_site/smcat.html'
29
+ And I should see svg output in '_site/smcat.html'
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ Given('I have a file {string} with content:') do |file, content|
4
+ File.write(file, content)
5
+ end
6
+
7
+ When('I run jekyll build') do
8
+ run_jekyll
9
+ end
10
+
11
+ Then('the file {string} should exist') do |file|
12
+ assert File.exist?(file)
13
+ end
14
+
15
+ Then('I should see svg output in {string}') do |file|
16
+ assert_match %r{<svg(.|\r|\n)*?>(.|\r|\n)*</svg>}, File.read(file)
17
+ end
18
+
19
+ Then('I should see {string} in {string}') do |pattern, file|
20
+ assert_match Regexp.new(pattern), File.read(file)
21
+ end
22
+
23
+ Then('I should not see {string} in {string}') do |pattern, file|
24
+ refute_match Regexp.new(pattern), File.read(file)
25
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('../lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'coveralls'
7
+ Coveralls.wear!
8
+
9
+ require 'tmpdir'
10
+ require 'minitest'
11
+ require 'jekyll'
12
+ require 'jekyll-diagrams'
13
+
14
+ TEST_DIR = File.join(Dir.tmpdir, 'jekyll-diagrams-features')
15
+
16
+ Before do
17
+ FileUtils.rm_rf(TEST_DIR) if File.exist?(TEST_DIR)
18
+ FileUtils.mkdir_p(TEST_DIR)
19
+ Dir.chdir(TEST_DIR)
20
+ end
21
+
22
+ After do
23
+ if File.exist?(TEST_DIR)
24
+ Dir.chdir(File.dirname(TEST_DIR))
25
+ FileUtils.rm_rf(TEST_DIR)
26
+ end
27
+ end
28
+
29
+ def run_jekyll
30
+ options = Jekyll.configuration(source: TEST_DIR, quiet: true)
31
+
32
+ Jekyll::Site.new(options).process
33
+ end
@@ -0,0 +1,22 @@
1
+ Feature: Svgbob
2
+
3
+
4
+ Scenario: Default configuration
5
+ Given I have a file 'svgbob.md' with content:
6
+ """
7
+ ---
8
+ ---
9
+
10
+ {% svgbob %}
11
+ .---> F
12
+ A B C D /
13
+ *-------*-----*---*----*-----> E
14
+ \ ^ \
15
+ v / '---> G
16
+ B --> C -'
17
+ {% endsvgbob %}
18
+ """
19
+ When I run jekyll build
20
+ Then the file '_site/svgbob.html' should exist
21
+ And I should see 'diagrams svgbob' in '_site/svgbob.html'
22
+ And I should see svg output in '_site/svgbob.html'
@@ -0,0 +1,22 @@
1
+ Feature: Syntrax
2
+
3
+
4
+ Scenario: Default configuration
5
+ Given I have a file 'syntrax.md' with content:
6
+ """
7
+ ---
8
+ ---
9
+
10
+ {% syntrax %}
11
+ indentstack(10,
12
+ line(opt('-'), choice('0', line('1-9', loop(None, '0-9'))),
13
+ opt('.', loop('0-9', None))),
14
+
15
+ line(opt(choice('e', 'E'), choice(None, '+', '-'), loop('0-9', None)))
16
+ )
17
+ {% endsyntrax %}
18
+ """
19
+ When I run jekyll build
20
+ Then the file '_site/syntrax.html' should exist
21
+ And I should see 'diagrams syntrax' in '_site/syntrax.html'
22
+ And I should see svg output in '_site/syntrax.html'
@@ -0,0 +1,32 @@
1
+ Feature: Vega
2
+
3
+
4
+ Scenario: Default configuration
5
+ Given I have a file 'vega.md' with content:
6
+ """
7
+ ---
8
+ ---
9
+
10
+ {% vega %}
11
+ {
12
+ "": "https://vega.github.io/schema/vega-lite/v4.json",
13
+ "description": "A simple bar chart with embedded data.",
14
+ "data": {
15
+ "values": [
16
+ {"a": "A", "b": 28}, {"a": "B", "b": 55}, {"a": "C", "b": 43},
17
+ {"a": "D", "b": 91}, {"a": "E", "b": 81}, {"a": "F", "b": 53},
18
+ {"a": "G", "b": 19}, {"a": "H", "b": 87}, {"a": "I", "b": 52}
19
+ ]
20
+ },
21
+ "mark": "bar",
22
+ "encoding": {
23
+ "x": {"field": "a", "type": "ordinal"},
24
+ "y": {"field": "b", "type": "quantitative"}
25
+ }
26
+ }
27
+ {% endvega %}
28
+ """
29
+ When I run jekyll build
30
+ Then the file '_site/vega.html' should exist
31
+ And I should see 'diagrams vega' in '_site/vega.html'
32
+ And I should see svg output in '_site/vega.html'
@@ -0,0 +1,22 @@
1
+ Feature: Wavedrom
2
+
3
+
4
+ Scenario: Default configuration
5
+ Given I have a file 'wavedrom.md' with content:
6
+ """
7
+ ---
8
+ ---
9
+
10
+ {% wavedrom %}
11
+ {signal: [
12
+ {name: 'clk', wave: 'p.....|...'},
13
+ {name: 'dat', wave: 'x.345x|=.x', data: ['head', 'body', 'tail', 'data']},
14
+ {name: 'req', wave: '0.1..0|1.0'},
15
+ {name: 'ack', wave: '1.....|01.'}
16
+ ]}
17
+ {% endwavedrom %}
18
+ """
19
+ When I run jekyll build
20
+ Then the file '_site/wavedrom.html' should exist
21
+ And I should see 'diagrams wavedrom' in '_site/wavedrom.html'
22
+ And I should see svg output in '_site/wavedrom.html'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
 
@@ -6,20 +8,24 @@ require 'jekyll-diagrams/version'
6
8
  Gem::Specification.new do |spec|
7
9
  spec.name = 'jekyll-diagrams'
8
10
  spec.version = Jekyll::Diagrams::VERSION
9
- spec.authors = ['zhustec']
10
- spec.email = ['zhustec@foxmail.com']
11
+ spec.author = 'zhustec'
12
+ spec.email = 'zhustec@foxmail.com'
11
13
  spec.homepage = 'https://github.com/zhustec/jekyll-diagrams'
12
- spec.description = 'Jekyll plugins for diagrams support.'
13
- spec.summary = 'Jekyll plugins for diagrams support, including Graphviz, Blockdiag, PlantUML and so on.'
14
14
  spec.license = 'MIT'
15
+ spec.summary = 'Jekyll plugins for diagrams support'
16
+ spec.description = <<~DESC
17
+ Jekyll plugins for diagrams support, including Graphviz, Blockdiag,
18
+ PlantUML and so on.
19
+ DESC
15
20
 
16
21
  spec.files = `git ls-files -z`.split("\x0")
17
- spec.test_files = spec.files.grep(%r!^(test|spec|features)!)
22
+ spec.test_files = spec.files.grep(/^(test|spec|features)/)
18
23
  spec.require_paths = ['lib']
19
24
 
20
25
  spec.add_dependency 'jekyll', '>= 3.7', '< 5.0'
21
26
 
22
27
  spec.add_development_dependency 'bundler'
23
- spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'cucumber'
24
29
  spec.add_development_dependency 'minitest', '~> 5.0'
25
- end
30
+ spec.add_development_dependency 'rake'
31
+ end
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'jekyll-diagrams/util'
2
- require_relative 'jekyll-diagrams/renderer'
3
4
  require_relative 'jekyll-diagrams/block'
4
5
 
5
6
  require_relative 'jekyll-diagrams/blockdiag'
@@ -12,4 +13,4 @@ require_relative 'jekyll-diagrams/smcat'
12
13
  require_relative 'jekyll-diagrams/svgbob'
13
14
  require_relative 'jekyll-diagrams/syntrax'
14
15
  require_relative 'jekyll-diagrams/vega'
15
- require_relative 'jekyll-diagrams/wavedrom'
16
+ require_relative 'jekyll-diagrams/wavedrom'
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jekyll
2
4
  module Diagrams
3
5
  class Block < Liquid::Block
4
- include Renderer
5
6
  include Util
6
7
 
7
8
  def render(context)
@@ -9,8 +10,8 @@ module Jekyll
9
10
  wrap_class(svg)
10
11
  end
11
12
 
12
- def render_svg(content, config)
13
- raise 'Not Implemented'
13
+ def render_svg(_, _)
14
+ ''
14
15
  end
15
16
 
16
17
  def read_config(context)
@@ -22,4 +23,4 @@ module Jekyll
22
23
  end
23
24
  end
24
25
  end
25
- end
26
+ end
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jekyll
2
4
  module Diagrams
3
5
  class BlockdiagBlock < Block
4
- CONFIGURATIONS = %w( config font fontmap size ).freeze
6
+ CONFIGURATIONS = %w[config font fontmap size].freeze
5
7
 
6
8
  def render_svg(code, config)
7
9
  command = build_command(config)
8
10
 
9
- render_with_tempfile(command, code) do |command, input, output|
10
- "#{command} #{input} -o #{output}"
11
+ render_with_tempfile(command, code) do |input, output|
12
+ "#{input} -o #{output}"
11
13
  end
12
14
  end
13
15
 
@@ -17,10 +19,10 @@ module Jekyll
17
19
 
18
20
  def build_command(config)
19
21
  command = "#{block_name} -T svg --nodoctype"
20
- command << ' --antialias' if config.has_key?('antialias')
22
+ command << ' --antialias' if config.fetch('antialias', false) != false
21
23
 
22
24
  CONFIGURATIONS.each do |conf|
23
- command << " --#{conf}=#{config[conf]}" if config.has_key?(conf)
25
+ command << " --#{conf}=#{config[conf]}" if config.key?(conf)
24
26
  end
25
27
 
26
28
  command
@@ -29,6 +31,6 @@ module Jekyll
29
31
  end
30
32
  end
31
33
 
32
- %i(blockdiag seqdiag actdiag nwdiag rackdiag packetdiag).each do |tag|
34
+ %i[blockdiag seqdiag actdiag nwdiag rackdiag packetdiag].each do |tag|
33
35
  Liquid::Template.register_tag(tag, Jekyll::Diagrams::BlockdiagBlock)
34
- end
36
+ end
@@ -1,21 +1,24 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jekyll
2
4
  module Diagrams
3
5
  class ErdBlock < Block
4
- CONFIGURATIONS = %w( config edge ).freeze
6
+ XML_REGEX = /^<\?xml(([^>]|\n)*>\n?){2}/.freeze
7
+ CONFIGURATIONS = %w[config edge].freeze
5
8
 
6
9
  def render_svg(code, config)
7
10
  command = build_command(config)
8
11
 
9
12
  svg = render_with_stdin_stdout(command, code)
10
- svg.sub!(/^<\?xml(([^>]|\n)*>\n?){2}/, '')
13
+ svg.sub!(XML_REGEX, '')
11
14
  end
12
15
 
13
16
  def build_command(config)
14
- command = 'erd --fmt=svg'
15
- command << ' --dot-entity' if config.has_key?('dot-entity')
17
+ command = +'erd --fmt=svg'
18
+ command << ' --dot-entity' if config.fetch('dot-entity', false) != false
16
19
 
17
20
  CONFIGURATIONS.each do |conf|
18
- command << " --#{conf}=#{config[conf]}" if config.has_key?(conf)
21
+ command << " --#{conf}=#{config[conf]}" if config.key?(conf)
19
22
  end
20
23
 
21
24
  command
@@ -24,4 +27,4 @@ module Jekyll
24
27
  end
25
28
  end
26
29
 
27
- Liquid::Template.register_tag(:erd, Jekyll::Diagrams::ErdBlock)
30
+ Liquid::Template.register_tag(:erd, Jekyll::Diagrams::ErdBlock)
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jekyll
2
4
  module Diagrams
3
5
  class GraphvizBlock < Block
6
+ XML_REGEX = /^<\?xml(([^>]|\n)*>\n?){2}/.freeze
4
7
  CONFIGRATIONS = {
5
8
  'K' => 'default_layout',
6
9
  'G' => 'graph_attributes',
@@ -11,28 +14,20 @@ module Jekyll
11
14
  def render_svg(code, config)
12
15
  command = build_command(config)
13
16
 
14
- svg = render_with_stdin_stdout(command, code)
15
- svg.sub!(/^<\?xml(([^>]|\n)*>\n?){2}/, '')
17
+ svg = render_with_stdin_stdout(command, code).force_encoding(
18
+ config.fetch('encoding', 'utf-8')
19
+ )
20
+
21
+ svg.sub!(XML_REGEX, '')
16
22
  end
17
23
 
18
24
  def build_command(config)
19
- command = 'dot -Tsvg'
25
+ command = +'dot -Tsvg'
20
26
 
21
27
  CONFIGRATIONS.each do |prefix, conf|
22
- next unless config.has_key?(conf)
23
-
24
- attrs = config[conf]
25
-
26
- attrs = case attrs
27
- when String
28
- attrs
29
- when Array
30
- attrs.join(" -#{prefix}")
31
- when Hash
32
- attrs.map { |k, v| "#{k}=#{v}" }.join(" -#{prefix}")
33
- end
28
+ next unless config.key?(conf)
34
29
 
35
- command << " -#{prefix}#{attrs}"
30
+ command << normalized_attrs(config[conf], prefix: " -#{prefix}")
36
31
  end
37
32
 
38
33
  command
@@ -41,4 +36,4 @@ module Jekyll
41
36
  end
42
37
  end
43
38
 
44
- Liquid::Template.register_tag(:graphviz, Jekyll::Diagrams::GraphvizBlock)
39
+ Liquid::Template.register_tag(:graphviz, Jekyll::Diagrams::GraphvizBlock)