jekyll-diagrams 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.travis.yml +8 -2
- data/README.md +13 -60
- data/lib/jekyll-diagrams/version.rb +1 -1
- data/lib/jekyll/diagrams.rb +11 -0
- data/lib/jekyll/diagrams/blockdiag.rb +16 -35
- data/lib/jekyll/diagrams/graphviz.rb +18 -36
- data/test/jekyll-diagrams_test.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52a77bb73a18b1e0b3d922615f50a062ce500c7f7ad1d220b3f648ad1cba8ba1
|
4
|
+
data.tar.gz: 45b4d1695a7494c8a4ecfd70b0d32f33dd31007b1d63408d44f5762d5fb47639
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 012db758b38a586e03675b7af7c37ae88628361180d5ad1dd09aa6fb029c1cbd80eb98710542de4a490796cb45303aa1c5b3377536d2a8bfddf23cbc4fd80ba1
|
7
|
+
data.tar.gz: 0b62461401ae935a95c74e34412bcdb159ddf7b5f8c83d478e496d103f65d6643b7279ea12d98e8a9cdd6387e922a2c2aec1db1a6b4081d2d26324e9dea5bf19
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -5,8 +5,14 @@ rvm:
|
|
5
5
|
- 2.5
|
6
6
|
- 2.6
|
7
7
|
|
8
|
+
addons:
|
9
|
+
apt:
|
10
|
+
packages:
|
11
|
+
- graphviz
|
12
|
+
- python3
|
13
|
+
- python3-pip
|
14
|
+
- python3-setuptools
|
15
|
+
|
8
16
|
before_install:
|
9
|
-
- sudo apt update && sudo apt install -y graphviz
|
10
|
-
- sudo apt install -y python3 python3-pip python3-setuptools
|
11
17
|
- sudo pip3 install blockdiag seqdiag actdiag nwdiag
|
12
18
|
- gem update --system && gem install bundler
|
data/README.md
CHANGED
@@ -45,12 +45,7 @@ plugins:
|
|
45
45
|
|
46
46
|
### Graphviz
|
47
47
|
|
48
|
-
You need first install graphviz with package manager on your system.
|
49
|
-
|
50
|
-
* Gentoo Linux : `emerge graphviz`
|
51
|
-
* Arch Linux : `pacman -S graphviz`
|
52
|
-
|
53
|
-
Then you can use `graphviz`, `graph`, and `digraph` Liquid Tag for creating amazing Graphviz images!
|
48
|
+
You need first install graphviz with package manager on your system. Then you can use `graphviz` Liquid Tag to create amazing Graphviz images!
|
54
49
|
|
55
50
|
```
|
56
51
|
{% graphviz %}
|
@@ -69,41 +64,18 @@ digraph {
|
|
69
64
|
{% endgraphviz %}
|
70
65
|
```
|
71
66
|
|
72
|
-
You can also use `diagraph` and `graph` tag. e.g.
|
73
|
-
|
74
|
-
```
|
75
|
-
{% digraph %}
|
76
|
-
node [shape=circle, style=filled];
|
77
|
-
S [fillcolor=green];
|
78
|
-
A [fillcolor=yellow];
|
79
|
-
B [fillcolor=yellow];
|
80
|
-
C [fillcolor=yellow];
|
81
|
-
D [shape=doublecircle, fillcolor=green];
|
82
|
-
S -> A [label=a];
|
83
|
-
S -> B [label=b];
|
84
|
-
A -> D [label=c];
|
85
|
-
B -> D [label=d];
|
86
|
-
{% enddigraph %}
|
87
|
-
```
|
88
|
-
|
89
67
|
### Blockdiag
|
90
68
|
|
91
69
|
Blockdiag contains:
|
92
70
|
|
93
|
-
* `blockdiag` :
|
94
|
-
* `seqdiag` :
|
95
|
-
* `actdiag` :
|
96
|
-
* `nwdiag` :
|
71
|
+
* `blockdiag` : generates block diagram image
|
72
|
+
* `seqdiag` : generates sequence diagram image
|
73
|
+
* `actdiag` : generates activity diagram image
|
74
|
+
* `nwdiag` : generates network diagram image
|
75
|
+
* `rackdiag` : generates rack structure diagram
|
76
|
+
* `packetdiag` : generates packet header diagram
|
97
77
|
|
98
|
-
|
99
|
-
|
100
|
-
```bash
|
101
|
-
$ pip install blockdiag seqdiag actdiag nwdiag
|
102
|
-
```
|
103
|
-
|
104
|
-
And set `$PATH` to make sure your system can find it in `$PATH`.
|
105
|
-
|
106
|
-
Then you can use `blockdiag`, `seqdiag`, `actdiag` and `nwdiag` Liquid Tag. e.g.
|
78
|
+
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.
|
107
79
|
|
108
80
|
```
|
109
81
|
{% blockdiag %}
|
@@ -131,40 +103,21 @@ seqdiag {
|
|
131
103
|
|
132
104
|
## Configuration
|
133
105
|
|
134
|
-
You
|
135
|
-
|
106
|
+
You can to provide a configuration, this is optional.
|
107
|
+
|
108
|
+
A simple example configuration is shown below:
|
136
109
|
|
137
110
|
```yaml
|
138
111
|
diagrams:
|
139
112
|
graphviz:
|
140
113
|
engine: dot
|
141
|
-
options: '-Tsvg'
|
142
114
|
blockdiag:
|
143
|
-
options: '
|
115
|
+
options: '--antialias'
|
144
116
|
```
|
145
117
|
|
146
118
|
### Graphviz
|
147
119
|
|
148
|
-
`engine` is the default image render engine. Default is set to `dot`.
|
149
|
-
|
150
|
-
```
|
151
|
-
{% graphviz neato %}
|
152
|
-
digraph {
|
153
|
-
node [shape=circle, style=filled];
|
154
|
-
S [fillcolor=green];
|
155
|
-
A [fillcolor=yellow];
|
156
|
-
B [fillcolor=yellow];
|
157
|
-
C [fillcolor=yellow];
|
158
|
-
D [shape=doublecircle, fillcolor=green];
|
159
|
-
S -> A [label=a];
|
160
|
-
S -> B [label=b];
|
161
|
-
A -> D [label=c];
|
162
|
-
B -> D [label=d];
|
163
|
-
}
|
164
|
-
{% endgraphviz %}
|
165
|
-
```
|
166
|
-
|
167
|
-
`options` is the command line options, and will be appended to the command.
|
120
|
+
`engine` is the default image render engine. Default is set to `dot`.
|
168
121
|
|
169
122
|
### Blockdiag
|
170
123
|
|
data/lib/jekyll/diagrams.rb
CHANGED
@@ -1,3 +1,14 @@
|
|
1
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
|
+
|
2
13
|
require 'jekyll/diagrams/graphviz'
|
3
14
|
require 'jekyll/diagrams/blockdiag'
|
@@ -4,62 +4,43 @@ require 'tempfile'
|
|
4
4
|
module Jekyll
|
5
5
|
module Diagrams
|
6
6
|
class BlockdiagBlock < Liquid::Block
|
7
|
+
DEFAULTS = {
|
8
|
+
}
|
9
|
+
OPTIONS = '-T svg --nodoctype'
|
10
|
+
|
7
11
|
def initialize(tag_name, text, tokens)
|
8
12
|
super
|
9
13
|
@tag_name = tag_name
|
10
14
|
end
|
11
15
|
|
12
16
|
def render(context)
|
13
|
-
|
14
|
-
|
15
|
-
@renderer = DiagRenderer.new(config['blockdiag'])
|
16
|
-
|
17
|
-
render_diagram(super)
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def render_diagram(code)
|
23
|
-
@renderer.render(code, @tag_name)
|
24
|
-
end
|
25
|
-
end
|
17
|
+
code = super.to_s
|
18
|
+
config = DEFAULTS.merge(Utils.config_for(context, 'blockdiag'))
|
26
19
|
|
27
|
-
|
28
|
-
|
29
|
-
'options' => '-Tsvg --nodoctype'
|
30
|
-
}
|
20
|
+
tmpfile = Tempfile.new(@tag_name).path
|
21
|
+
output = "#{tmpfile}.svg"
|
31
22
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
def render(code, engine)
|
37
|
-
tmp = Tempfile.new(engine).path
|
38
|
-
dest = "#{tmp}.svg"
|
39
|
-
|
40
|
-
File.write(tmp, code)
|
41
|
-
cmd = "#{engine} #{@config['options']} #{tmp} -o #{dest}"
|
42
|
-
ret, status = Open3.capture2(cmd, binmode: true)
|
23
|
+
File.write(tmpfile, code)
|
24
|
+
cmd = "#@tag_name #{OPTIONS} #{config['options']} #{tmpfile} -o #{output}"
|
25
|
+
_, status = Open3.capture2(cmd, binmode: true)
|
43
26
|
|
44
27
|
if !status.success?
|
45
28
|
raise "Non-zero exit status '#{cmd}': #{status}"
|
46
29
|
end
|
47
30
|
|
48
|
-
svg = File.read(
|
49
|
-
|
50
|
-
wrap_div(svg, engine)
|
31
|
+
svg = File.read(output)
|
32
|
+
wrap(svg.force_encoding('UTF-8'))
|
51
33
|
end
|
52
34
|
|
53
35
|
private
|
54
36
|
|
55
|
-
def
|
56
|
-
"<div class='
|
37
|
+
def wrap(svg)
|
38
|
+
"<div class='diagrams #@tag_name'>#{svg}</div>"
|
57
39
|
end
|
58
40
|
end
|
59
41
|
end
|
60
42
|
end
|
61
43
|
|
62
|
-
|
63
44
|
%w(blockdiag seqdiag actdiag nwdiag rackdiag packetdiag).each do |tag|
|
64
|
-
Liquid::Template.register_tag
|
45
|
+
Liquid::Template.register_tag(tag, Jekyll::Diagrams::BlockdiagBlock)
|
65
46
|
end
|
@@ -3,62 +3,44 @@ require 'open3'
|
|
3
3
|
module Jekyll
|
4
4
|
module Diagrams
|
5
5
|
class GraphvizBlock < Liquid::Block
|
6
|
+
DEFAULTS = {
|
7
|
+
'engine' => 'dot'
|
8
|
+
}
|
9
|
+
OPTIONS = '-T svg'
|
10
|
+
|
6
11
|
def initialize(tag_name, text, tokens)
|
7
12
|
super
|
8
13
|
@tag_name = tag_name
|
9
|
-
@engine = text.strip
|
10
14
|
end
|
11
15
|
|
12
16
|
def render(context)
|
13
|
-
|
14
|
-
|
15
|
-
@renderer = GraphvizRenderer.new(config["graphviz"])
|
16
|
-
|
17
|
-
render_diagram(super)
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
17
|
+
code = super.to_s
|
18
|
+
config = DEFAULTS.merge(Utils.config_for(context, 'graphviz'))
|
21
19
|
|
22
|
-
def render_diagram(code)
|
23
20
|
code = case @tag_name
|
24
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."
|
25
24
|
"#@tag_name {\n#{code}\n}"
|
26
25
|
when 'graphviz'
|
27
26
|
code
|
28
|
-
else
|
29
|
-
raise "unknown liquid tag name: #{@tag_name}"
|
30
27
|
end
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
class GraphvizRenderer
|
37
|
-
DEFAULTS = {
|
38
|
-
'engine' => 'dot',
|
39
|
-
'options' => '-Tsvg'
|
40
|
-
}
|
41
|
-
|
42
|
-
def initialize(config)
|
43
|
-
@config = DEFAULTS.merge(config)
|
44
|
-
end
|
45
|
-
|
46
|
-
def render(code, engine = DEFAULTS['engine'])
|
47
|
-
cmd = "#{@config['engine']} #{@config['options']}"
|
48
|
-
svg, status = Open3.capture2(
|
49
|
-
cmd,
|
50
|
-
stdin_data: code,
|
51
|
-
binmode: true
|
52
|
-
)
|
29
|
+
cmd = "#{config['engine']} #{OPTIONS} #{config['options']}"
|
30
|
+
svg, status = Open3.capture2(cmd, stdin_data: code, binmode: true)
|
53
31
|
|
54
32
|
if !status.success?
|
55
33
|
raise "Non-zero exit status '#{cmd}': #{status}"
|
56
34
|
end
|
57
35
|
|
58
|
-
svg.sub!
|
59
|
-
svg.force_encoding
|
36
|
+
svg.sub!(/^<\?xml(([^>]|\n)*>\n?){4}/, '')
|
37
|
+
wrap(svg.force_encoding('UTF-8'))
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
60
41
|
|
61
|
-
|
42
|
+
def wrap(svg)
|
43
|
+
"<div class='diagrams graphviz'>#{svg}</div>"
|
62
44
|
end
|
63
45
|
end
|
64
46
|
end
|
@@ -16,10 +16,10 @@ class TestJekyllDiagrams < Minitest::Test
|
|
16
16
|
|
17
17
|
|
18
18
|
def test_render_graphviz
|
19
|
-
assert_match %r!<div class="graphviz">!, @graphviz_contents
|
19
|
+
assert_match %r!<div class="diagrams graphviz">!, @graphviz_contents
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_render_blockdiag
|
23
|
-
assert_match %r!<div class="
|
23
|
+
assert_match %r!<div class="diagrams \w+">!, @blockdiag_contents
|
24
24
|
end
|
25
25
|
end
|
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.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zhustec
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|