jekyll-diagrams 0.5.1 → 0.6.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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +3 -1
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/README.md +43 -17
- data/Rakefile +1 -1
- data/jekyll-diagrams.gemspec +3 -6
- data/lib/jekyll-diagrams.rb +6 -1
- data/lib/jekyll-diagrams/block.rb +24 -0
- data/lib/jekyll-diagrams/blockdiag.rb +41 -0
- data/lib/jekyll-diagrams/graphviz.rb +42 -0
- data/lib/jekyll-diagrams/plantuml.rb +19 -0
- data/lib/jekyll-diagrams/renderer.rb +46 -0
- data/lib/jekyll-diagrams/util.rb +32 -0
- data/lib/jekyll-diagrams/version.rb +2 -2
- data/test/test_helper.rb +1 -14
- data/vendor/plantuml.1.2020.1.jar +0 -0
- metadata +13 -19
- data/lib/jekyll/diagrams.rb +0 -14
- data/lib/jekyll/diagrams/blockdiag.rb +0 -46
- data/lib/jekyll/diagrams/graphviz.rb +0 -51
- data/test/fixtures/_config.yml +0 -6
- data/test/fixtures/_layouts/default.html +0 -8
- data/test/fixtures/_posts/2019-08-25-blockdiag.md +0 -23
- data/test/fixtures/_posts/2019-08-25-graphviz.md +0 -48
- data/test/jekyll-diagrams_test.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 939c351c21994ececde693c60b108ddd81d8fd98f3dacc11a7722b8972f294bf
|
4
|
+
data.tar.gz: cb597bafa191ce822a239ab565718ae4efce683204bd45a39ed4e61f656e6b91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f19c1dd680ffdd9f11af3ea082e38759d120b63d163ecd9bba19ab27cfd185c08eca82ee036ae9f675597ccd58db60eabecac8abb9d0dfdf7f78b312ecc1e6fa
|
7
|
+
data.tar.gz: f6675947274f26d32558e06446ed3617fda8c183287aa54df9835df9446fccdcbb1d8eb7fa3126751ba70192f0e5de1b3b4362ccbf46fe4bb60eebe17a4130c4
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -4,10 +4,12 @@ rvm:
|
|
4
4
|
- 2.4
|
5
5
|
- 2.5
|
6
6
|
- 2.6
|
7
|
+
- 2.7
|
7
8
|
|
8
9
|
addons:
|
9
10
|
apt:
|
10
11
|
packages:
|
12
|
+
- default-jre
|
11
13
|
- graphviz
|
12
14
|
- python3
|
13
15
|
- python3-pip
|
@@ -15,4 +17,4 @@ addons:
|
|
15
17
|
|
16
18
|
before_install:
|
17
19
|
- sudo pip3 install blockdiag seqdiag actdiag nwdiag
|
18
|
-
- gem update --system && gem install bundler
|
20
|
+
- gem update --system && gem install bundler
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -9,6 +9,7 @@ Jekyll Diagrams is a jekyll plugins for creating amazing diagrams, including:
|
|
9
9
|
|
10
10
|
- Graphviz
|
11
11
|
- Blockdiag, Seqdiag, Actdiag and Nwdiag
|
12
|
+
- PlantUML
|
12
13
|
|
13
14
|
## Installation
|
14
15
|
|
@@ -47,7 +48,7 @@ plugins:
|
|
47
48
|
|
48
49
|
You need first install graphviz with package manager on your system. Then you can use `graphviz` Liquid Tag to create amazing Graphviz images!
|
49
50
|
|
50
|
-
```
|
51
|
+
```text
|
51
52
|
{% graphviz %}
|
52
53
|
digraph {
|
53
54
|
node [shape=circle, style=filled];
|
@@ -64,6 +65,26 @@ digraph {
|
|
64
65
|
{% endgraphviz %}
|
65
66
|
```
|
66
67
|
|
68
|
+
#### Configuration
|
69
|
+
|
70
|
+
A simple configuration example is shown below:
|
71
|
+
|
72
|
+
```yaml
|
73
|
+
jekyll-diagrams:
|
74
|
+
graphviz:
|
75
|
+
default_layout: dot
|
76
|
+
graph_attribute: color=red
|
77
|
+
node_attribute:
|
78
|
+
- color=blue
|
79
|
+
- fillcolor=red
|
80
|
+
edge_attribute:
|
81
|
+
color: red
|
82
|
+
fillcolor: blue
|
83
|
+
```
|
84
|
+
|
85
|
+
- `default_layout`: Change the default layout here.
|
86
|
+
- `graph/node/edge_attribute`: Default graph/node/edge attribute, can be String(when just one attribute), Array or Hash.
|
87
|
+
|
67
88
|
### Blockdiag
|
68
89
|
|
69
90
|
Blockdiag contains:
|
@@ -77,7 +98,7 @@ Blockdiag contains:
|
|
77
98
|
|
78
99
|
You need first install it and set path properly to make sure your system can find it. Then you can use `blockdiag`, `seqdiag`, `actdiag`, `nwdiag`, `rackdiag`, `packetdiag` Liquid Tag.
|
79
100
|
|
80
|
-
```
|
101
|
+
```text
|
81
102
|
{% blockdiag %}
|
82
103
|
blockdiag {
|
83
104
|
A -> B -> C -> D;
|
@@ -88,7 +109,7 @@ blockdiag {
|
|
88
109
|
|
89
110
|
And `seqdiag`:
|
90
111
|
|
91
|
-
```
|
112
|
+
```text
|
92
113
|
{% seqdiag %}
|
93
114
|
seqdiag {
|
94
115
|
browser -> webserver [label = "GET /index.html"];
|
@@ -101,27 +122,32 @@ seqdiag {
|
|
101
122
|
{% endseqdiag %}
|
102
123
|
```
|
103
124
|
|
104
|
-
|
105
|
-
|
106
|
-
You can to provide a configuration, this is optional.
|
107
|
-
|
108
|
-
A simple example configuration is shown below:
|
125
|
+
#### Configuration
|
109
126
|
|
110
127
|
```yaml
|
111
|
-
diagrams:
|
112
|
-
graphviz:
|
113
|
-
engine: dot
|
128
|
+
jekyll-diagrams:
|
114
129
|
blockdiag:
|
115
|
-
|
130
|
+
antialias: true
|
131
|
+
config: configuration_file
|
132
|
+
font: your_custom_font
|
133
|
+
fontmap: your_custom_font
|
134
|
+
size: 320x400
|
116
135
|
```
|
117
136
|
|
118
|
-
###
|
137
|
+
### PlantUML
|
119
138
|
|
120
|
-
|
139
|
+
```text
|
140
|
+
{% plantuml %}
|
141
|
+
@startuml
|
142
|
+
class Car
|
121
143
|
|
122
|
-
|
144
|
+
Driver - Car : drives >
|
145
|
+
Car *- Wheel : have 4 >
|
146
|
+
Car -- Person : < owns
|
123
147
|
|
124
|
-
|
148
|
+
@enduml
|
149
|
+
{% endplantuml %}
|
150
|
+
```
|
125
151
|
|
126
152
|
## Contributing
|
127
153
|
|
@@ -129,4 +155,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/zhuste
|
|
129
155
|
|
130
156
|
## License
|
131
157
|
|
132
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
158
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
data/jekyll-diagrams.gemspec
CHANGED
@@ -5,24 +5,21 @@ require 'jekyll-diagrams/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'jekyll-diagrams'
|
8
|
-
spec.summary = 'Jekyll plugins for diagrams support'
|
9
8
|
spec.version = Jekyll::Diagrams::VERSION
|
10
9
|
spec.authors = ['zhustec']
|
11
10
|
spec.email = ['zhustec@foxmail.com']
|
12
11
|
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.'
|
13
14
|
spec.license = 'MIT'
|
14
|
-
spec.description = 'Jekyll plugins for diagrams support, including Graphviz, Blockdiag, Seqdiag and so on.'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.test_files = spec.files.grep(%r!^(test|spec|features)!)
|
18
|
-
|
19
18
|
spec.require_paths = ['lib']
|
20
19
|
|
21
|
-
spec.required_ruby_version = '>= 2.3.0'
|
22
|
-
|
23
20
|
spec.add_dependency 'jekyll', '>= 3.7', '< 5.0'
|
24
21
|
|
25
22
|
spec.add_development_dependency 'bundler'
|
26
23
|
spec.add_development_dependency 'rake'
|
27
24
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
28
|
-
end
|
25
|
+
end
|
data/lib/jekyll-diagrams.rb
CHANGED
@@ -1 +1,6 @@
|
|
1
|
-
|
1
|
+
require_relative 'jekyll-diagrams/util'
|
2
|
+
require_relative 'jekyll-diagrams/renderer'
|
3
|
+
require_relative 'jekyll-diagrams/block'
|
4
|
+
require_relative 'jekyll-diagrams/blockdiag'
|
5
|
+
require_relative 'jekyll-diagrams/graphviz'
|
6
|
+
require_relative 'jekyll-diagrams/plantuml'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module Diagrams
|
3
|
+
class Block < Liquid::Block
|
4
|
+
include Renderer
|
5
|
+
|
6
|
+
def render(context)
|
7
|
+
svg = render_svg(super.to_s, read_config(context))
|
8
|
+
wrap_class(svg)
|
9
|
+
end
|
10
|
+
|
11
|
+
def render_svg(content, config)
|
12
|
+
raise 'Not Implemented'
|
13
|
+
end
|
14
|
+
|
15
|
+
def read_config(context)
|
16
|
+
Util.config_for(context, block_name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def wrap_class(content)
|
20
|
+
"<div class='diagrams #{block_name}'>#{content}</div>"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'open3'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
module Diagrams
|
6
|
+
class BlockdiagBlock < Block
|
7
|
+
def render_svg(code, config)
|
8
|
+
command = build_command(config)
|
9
|
+
|
10
|
+
render_with_tempfile(command, code, :svg) do |command, input, output|
|
11
|
+
"#{command} #{input} -o #{output}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def read_config(context)
|
16
|
+
Util.config_for(context, 'blockdiag').merge(Util.config_for(context, block_name))
|
17
|
+
end
|
18
|
+
|
19
|
+
def build_command(config)
|
20
|
+
command = "#{block_name} -Tsvg --nodoctype"
|
21
|
+
|
22
|
+
antialias = config.fetch('antialias', false)
|
23
|
+
|
24
|
+
if antialias && antialias != 'false'
|
25
|
+
command << ' --antialias'
|
26
|
+
end
|
27
|
+
|
28
|
+
%w(config font fontmap size).each do |key|
|
29
|
+
value = config.fetch(key, nil)
|
30
|
+
command << " --#{key}=#{value}" if value
|
31
|
+
end
|
32
|
+
|
33
|
+
command
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
%i(blockdiag seqdiag actdiag nwdiag rackdiag packetdiag).each do |tag|
|
40
|
+
Liquid::Template.register_tag(tag, Jekyll::Diagrams::BlockdiagBlock)
|
41
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module Diagrams
|
3
|
+
class GraphvizBlock < Block
|
4
|
+
CONFIGRATIONS = {
|
5
|
+
'K' => 'default_layout',
|
6
|
+
'G' => 'graph_attribute',
|
7
|
+
'N' => 'node_attribute',
|
8
|
+
'E' => 'edge_attribute'
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
def render_svg(code, config)
|
12
|
+
svg = render_with_stdin_stdout(build_command(config), code)
|
13
|
+
svg.sub!(/^<\?xml(([^>]|\n)*>\n?){4}/, '')
|
14
|
+
end
|
15
|
+
|
16
|
+
def build_command(config)
|
17
|
+
command = 'dot -Tsvg'
|
18
|
+
|
19
|
+
CONFIGRATIONS.each do |prefix, conf|
|
20
|
+
next unless config.has_key?(conf)
|
21
|
+
|
22
|
+
attrs = config[conf]
|
23
|
+
|
24
|
+
attrs = case attrs
|
25
|
+
when String
|
26
|
+
attrs
|
27
|
+
when Array
|
28
|
+
attrs.join(" -#{prefix}")
|
29
|
+
when Hash
|
30
|
+
attrs.map { |k, v| "#{k}=#{v}" }.join(" -#{prefix}")
|
31
|
+
end
|
32
|
+
|
33
|
+
command << " -#{prefix}#{attrs}"
|
34
|
+
end
|
35
|
+
|
36
|
+
command
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Liquid::Template.register_tag(:graphviz, Jekyll::Diagrams::GraphvizBlock)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module Diagrams
|
3
|
+
class PlantUMLBlock < Block
|
4
|
+
def render_svg(code, config)
|
5
|
+
render_with_stdin_stdout(build_command(config), code)
|
6
|
+
end
|
7
|
+
|
8
|
+
def build_command(config)
|
9
|
+
options = 'java'
|
10
|
+
options << ' -Djava.awt.headless=true'
|
11
|
+
options << ' -jar '
|
12
|
+
options << Util.java_classpath('plantuml.1.2020.1.jar')
|
13
|
+
options << ' -tsvg -pipe'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Liquid::Template.register_tag(:plantuml, Jekyll::Diagrams::PlantUMLBlock)
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'open3'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
module Diagrams
|
6
|
+
module Renderer
|
7
|
+
def render_with_stdin_stdout(command, content)
|
8
|
+
command = yield command if block_given?
|
9
|
+
|
10
|
+
render_with_command(command, :stdout, stdin_data: content, binmode: true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def render_with_stdin(command, content, format)
|
14
|
+
Tempfile.open(['jekyll_diagrams_output', ".#{format}"]) do |output|
|
15
|
+
output.close
|
16
|
+
command = yield command, output.path
|
17
|
+
|
18
|
+
render_with_command(command, output.path, stdin_data: content)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def render_with_tempfile(command, content, format)
|
23
|
+
Tempfile.open('jekyll_diagrams_input') do |input|
|
24
|
+
File.write(input.path, content)
|
25
|
+
|
26
|
+
Tempfile.open(['jekyll_diagrams_output', ".#{format}"]) do |output|
|
27
|
+
output.close
|
28
|
+
command = yield command, input.path, output.path
|
29
|
+
|
30
|
+
render_with_command(command, output.path)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def render_with_command(command, output, options = {})
|
36
|
+
stdout, stderr, status = Open3.capture3(command, options)
|
37
|
+
|
38
|
+
if !status.success?
|
39
|
+
raise "#{command} failed: #{stdout.empty? ? stderr : stdout}"
|
40
|
+
end
|
41
|
+
|
42
|
+
output == :stdout ? stdout : File.read(output)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module Diagrams
|
3
|
+
module Util
|
4
|
+
class << self
|
5
|
+
def diagrams_config(context)
|
6
|
+
site_config = context.registers[:site].config
|
7
|
+
new_config = site_config.fetch('jekyll-diagrams', {})
|
8
|
+
old_config = site_config.fetch('diagrams', {})
|
9
|
+
|
10
|
+
return new_config if old_config.empty?
|
11
|
+
|
12
|
+
Jekyll.warn "Configuration `diagram` in _config.yml will be depreated"
|
13
|
+
Jekyll.warn " Rename it to `jekyll-diagram` instead."
|
14
|
+
|
15
|
+
old_config.merge(new_config)
|
16
|
+
end
|
17
|
+
|
18
|
+
def config_for(context, name)
|
19
|
+
diagrams_config(context).fetch(name, {})
|
20
|
+
end
|
21
|
+
|
22
|
+
def java_classpath(jar)
|
23
|
+
File.join(vendor_path, jar)
|
24
|
+
end
|
25
|
+
|
26
|
+
def vendor_path
|
27
|
+
File.expand_path('../../vendor', __dir__)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -2,17 +2,4 @@ require 'jekyll'
|
|
2
2
|
require 'fileutils'
|
3
3
|
require File.expand_path('../lib/jekyll-diagrams', __dir__)
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
SOURCE_DIR = File.expand_path("fixtures", __dir__)
|
8
|
-
DEST_DIR = File.expand_path("dest", __dir__)
|
9
|
-
|
10
|
-
def source_dir(*files)
|
11
|
-
File.join(SOURCE_DIR, *files)
|
12
|
-
end
|
13
|
-
|
14
|
-
def dest_dir(*files)
|
15
|
-
File.join(DEST_DIR, *files)
|
16
|
-
end
|
17
|
-
|
18
|
-
require 'minitest/autorun'
|
5
|
+
require 'minitest/autorun'
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-diagrams
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zhustec
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -72,8 +72,7 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '5.0'
|
75
|
-
description: Jekyll plugins for diagrams support
|
76
|
-
and so on.
|
75
|
+
description: Jekyll plugins for diagrams support.
|
77
76
|
email:
|
78
77
|
- zhustec@foxmail.com
|
79
78
|
executables: []
|
@@ -88,16 +87,15 @@ files:
|
|
88
87
|
- Rakefile
|
89
88
|
- jekyll-diagrams.gemspec
|
90
89
|
- lib/jekyll-diagrams.rb
|
90
|
+
- lib/jekyll-diagrams/block.rb
|
91
|
+
- lib/jekyll-diagrams/blockdiag.rb
|
92
|
+
- lib/jekyll-diagrams/graphviz.rb
|
93
|
+
- lib/jekyll-diagrams/plantuml.rb
|
94
|
+
- lib/jekyll-diagrams/renderer.rb
|
95
|
+
- lib/jekyll-diagrams/util.rb
|
91
96
|
- lib/jekyll-diagrams/version.rb
|
92
|
-
- lib/jekyll/diagrams.rb
|
93
|
-
- lib/jekyll/diagrams/blockdiag.rb
|
94
|
-
- lib/jekyll/diagrams/graphviz.rb
|
95
|
-
- test/fixtures/_config.yml
|
96
|
-
- test/fixtures/_layouts/default.html
|
97
|
-
- test/fixtures/_posts/2019-08-25-blockdiag.md
|
98
|
-
- test/fixtures/_posts/2019-08-25-graphviz.md
|
99
|
-
- test/jekyll-diagrams_test.rb
|
100
97
|
- test/test_helper.rb
|
98
|
+
- vendor/plantuml.1.2020.1.jar
|
101
99
|
homepage: https://github.com/zhustec/jekyll-diagrams
|
102
100
|
licenses:
|
103
101
|
- MIT
|
@@ -110,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
108
|
requirements:
|
111
109
|
- - ">="
|
112
110
|
- !ruby/object:Gem::Version
|
113
|
-
version:
|
111
|
+
version: '0'
|
114
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
113
|
requirements:
|
116
114
|
- - ">="
|
@@ -121,11 +119,7 @@ rubyforge_project:
|
|
121
119
|
rubygems_version: 2.7.6.2
|
122
120
|
signing_key:
|
123
121
|
specification_version: 4
|
124
|
-
summary: Jekyll plugins for diagrams support
|
122
|
+
summary: Jekyll plugins for diagrams support, including Graphviz, Blockdiag, PlantUML
|
123
|
+
and so on.
|
125
124
|
test_files:
|
126
|
-
- test/fixtures/_config.yml
|
127
|
-
- test/fixtures/_layouts/default.html
|
128
|
-
- test/fixtures/_posts/2019-08-25-blockdiag.md
|
129
|
-
- test/fixtures/_posts/2019-08-25-graphviz.md
|
130
|
-
- test/jekyll-diagrams_test.rb
|
131
125
|
- test/test_helper.rb
|
data/lib/jekyll/diagrams.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'jekyll'
|
2
|
-
|
3
|
-
module Jekyll
|
4
|
-
module Diagrams
|
5
|
-
module Utils
|
6
|
-
def self.config_for(context, name)
|
7
|
-
context.registers[:site].config.fetch('diagrams', {}).fetch(name, {})
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
require 'jekyll/diagrams/graphviz'
|
14
|
-
require 'jekyll/diagrams/blockdiag'
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'open3'
|
2
|
-
require 'tempfile'
|
3
|
-
|
4
|
-
module Jekyll
|
5
|
-
module Diagrams
|
6
|
-
class BlockdiagBlock < Liquid::Block
|
7
|
-
DEFAULTS = {
|
8
|
-
}
|
9
|
-
OPTIONS = '-T svg --nodoctype'
|
10
|
-
|
11
|
-
def initialize(tag_name, text, tokens)
|
12
|
-
super
|
13
|
-
@tag_name = tag_name
|
14
|
-
end
|
15
|
-
|
16
|
-
def render(context)
|
17
|
-
code = super.to_s
|
18
|
-
config = DEFAULTS.merge(Utils.config_for(context, 'blockdiag'))
|
19
|
-
|
20
|
-
tmpfile = Tempfile.new(@tag_name).path
|
21
|
-
output = "#{tmpfile}.svg"
|
22
|
-
|
23
|
-
File.write(tmpfile, code)
|
24
|
-
cmd = "#@tag_name #{OPTIONS} #{config['options']} #{tmpfile} -o #{output}"
|
25
|
-
_, status = Open3.capture2(cmd, binmode: true)
|
26
|
-
|
27
|
-
if !status.success?
|
28
|
-
raise "Non-zero exit status '#{cmd}': #{status}"
|
29
|
-
end
|
30
|
-
|
31
|
-
svg = File.read(output)
|
32
|
-
wrap(svg.force_encoding('UTF-8'))
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def wrap(svg)
|
38
|
-
"<div class='diagrams #@tag_name'>#{svg}</div>"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
%w(blockdiag seqdiag actdiag nwdiag rackdiag packetdiag).each do |tag|
|
45
|
-
Liquid::Template.register_tag(tag, Jekyll::Diagrams::BlockdiagBlock)
|
46
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'open3'
|
2
|
-
|
3
|
-
module Jekyll
|
4
|
-
module Diagrams
|
5
|
-
class GraphvizBlock < Liquid::Block
|
6
|
-
DEFAULTS = {
|
7
|
-
'engine' => 'dot'
|
8
|
-
}
|
9
|
-
OPTIONS = '-T svg'
|
10
|
-
|
11
|
-
def initialize(tag_name, text, tokens)
|
12
|
-
super
|
13
|
-
@tag_name = tag_name
|
14
|
-
end
|
15
|
-
|
16
|
-
def render(context)
|
17
|
-
code = super.to_s
|
18
|
-
config = DEFAULTS.merge(Utils.config_for(context, 'graphviz'))
|
19
|
-
|
20
|
-
code = case @tag_name
|
21
|
-
when 'graph', 'digraph'
|
22
|
-
Jekyll.logger.warn "Warning:", "graph and digraph is depreated and will remove in the later version."
|
23
|
-
Jekyll.logger.warn "", "Using graphviz instead."
|
24
|
-
"#@tag_name {\n#{code}\n}"
|
25
|
-
when 'graphviz'
|
26
|
-
code
|
27
|
-
end
|
28
|
-
|
29
|
-
cmd = "#{config['engine']} #{OPTIONS} #{config['options']}"
|
30
|
-
svg, status = Open3.capture2(cmd, stdin_data: code, binmode: true)
|
31
|
-
|
32
|
-
if !status.success?
|
33
|
-
raise "Non-zero exit status '#{cmd}': #{status}"
|
34
|
-
end
|
35
|
-
|
36
|
-
svg.sub!(/^<\?xml(([^>]|\n)*>\n?){4}/, '')
|
37
|
-
wrap(svg.force_encoding('UTF-8'))
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def wrap(svg)
|
43
|
-
"<div class='diagrams graphviz'>#{svg}</div>"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
%w(graphviz graph digraph).each do |tag|
|
50
|
-
Liquid::Template.register_tag(tag, Jekyll::Diagrams::GraphvizBlock)
|
51
|
-
end
|
data/test/fixtures/_config.yml
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
---
|
2
|
-
title: A post with blockdiag
|
3
|
-
description: A post with blockdiag
|
4
|
-
layout: default
|
5
|
-
---
|
6
|
-
|
7
|
-
{% blockdiag %}
|
8
|
-
blockdiag {
|
9
|
-
A -> B -> C -> D;
|
10
|
-
A -> E -> F -> G;
|
11
|
-
}
|
12
|
-
{% endblockdiag %}
|
13
|
-
|
14
|
-
{% seqdiag %}
|
15
|
-
seqdiag {
|
16
|
-
browser -> webserver [label = "GET /index.html"];
|
17
|
-
browser <-- webserver;
|
18
|
-
browser -> webserver [label = "POST /blog/comment"];
|
19
|
-
webserver -> database [label = "INSERT comment"];
|
20
|
-
webserver <-- database;
|
21
|
-
browser <-- webserver;
|
22
|
-
}
|
23
|
-
{% endseqdiag %}
|
@@ -1,48 +0,0 @@
|
|
1
|
-
---
|
2
|
-
title: A post with graphviz
|
3
|
-
description: A post with graphviz
|
4
|
-
layout: default
|
5
|
-
---
|
6
|
-
|
7
|
-
{% graphviz %}
|
8
|
-
digraph {
|
9
|
-
node [shape=circle, style=filled];
|
10
|
-
S [fillcolor=green];
|
11
|
-
A [fillcolor=yellow];
|
12
|
-
B [fillcolor=yellow];
|
13
|
-
C [fillcolor=yellow];
|
14
|
-
D [shape=doublecircle, fillcolor=green];
|
15
|
-
S -> A [label=a];
|
16
|
-
S -> B [label=b];
|
17
|
-
A -> D [label=c];
|
18
|
-
B -> D [label=d];
|
19
|
-
}
|
20
|
-
{% endgraphviz %}
|
21
|
-
|
22
|
-
{% digraph %}
|
23
|
-
node [shape=circle, style=filled];
|
24
|
-
S [fillcolor=green];
|
25
|
-
A [fillcolor=yellow];
|
26
|
-
B [fillcolor=yellow];
|
27
|
-
C [fillcolor=yellow];
|
28
|
-
D [shape=doublecircle, fillcolor=green];
|
29
|
-
S -> A [label=a];
|
30
|
-
S -> B [label=b];
|
31
|
-
A -> D [label=c];
|
32
|
-
B -> D [label=d];
|
33
|
-
{% enddigraph %}
|
34
|
-
|
35
|
-
{% graphviz neato %}
|
36
|
-
digraph {
|
37
|
-
node [shape=circle, style=filled];
|
38
|
-
S [fillcolor=green];
|
39
|
-
A [fillcolor=yellow];
|
40
|
-
B [fillcolor=yellow];
|
41
|
-
C [fillcolor=yellow];
|
42
|
-
D [shape=doublecircle, fillcolor=green];
|
43
|
-
S -> A [label=a];
|
44
|
-
S -> B [label=b];
|
45
|
-
A -> D [label=c];
|
46
|
-
B -> D [label=d];
|
47
|
-
}
|
48
|
-
{% endgraphviz %}
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class TestJekyllDiagrams < Minitest::Test
|
4
|
-
def setup
|
5
|
-
@config = Jekyll.configuration({
|
6
|
-
source: source_dir,
|
7
|
-
destination: dest_dir,
|
8
|
-
url: 'http://example.org'
|
9
|
-
})
|
10
|
-
|
11
|
-
@site = Jekyll::Site.new(@config)
|
12
|
-
@site.process
|
13
|
-
@graphviz_contents = File.read(dest_dir('2019/08/25/graphviz.html'))
|
14
|
-
@blockdiag_contents = File.read(dest_dir('2019/08/25/blockdiag.html'))
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
def test_render_graphviz
|
19
|
-
assert_match %r!<div class="diagrams graphviz">!, @graphviz_contents
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_render_blockdiag
|
23
|
-
assert_match %r!<div class="diagrams \w+">!, @blockdiag_contents
|
24
|
-
end
|
25
|
-
end
|