jekyll-graphviz 0.1.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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +73 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/jekyll-graphviz.gemspec +33 -0
- data/lib/jekyll/graphviz.rb +12 -0
- data/lib/jekyll/graphviz/block.rb +35 -0
- data/lib/jekyll/graphviz/renderer.rb +86 -0
- data/lib/jekyll/graphviz/version.rb +5 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7cd56a8d30dbd430bafd40b578c38fa075f2712d
|
4
|
+
data.tar.gz: 09e373b945c734a0c6d911a55ea2e33d5cddd5ff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 532b8b40af6c152542d0824f722250afc2da1d5868607e3f48367aa7d67068834fcf90c9979d4bcd20884ddbf65d8037ba0e17120e7967e4fb255664fb121bcc
|
7
|
+
data.tar.gz: 12da6ef7adb5a20824abf7a247f7e363a38414ae8821122882cfc28bce01ff96b32e1196ccfb0e2f6b062066e404bd917534ced202286cf3d69806986b1c5c92
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Keiichiro Ui
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Jekyll::Graphviz
|
2
|
+
|
3
|
+
A liquid tag to convert with Graphviz for Jekyll.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
group :jekyll_plugins do
|
11
|
+
gem 'jekyll-graphviz'
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install jekyll-graphviz
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
~~~~~~~~~~~~~~~~~~~~~~~
|
26
|
+
---
|
27
|
+
---
|
28
|
+
|
29
|
+
{% graph some graph title %}
|
30
|
+
a -- b
|
31
|
+
b -- c
|
32
|
+
c -- a
|
33
|
+
{% endgraph %}
|
34
|
+
|
35
|
+
{% digraph some digraph title %}
|
36
|
+
a -> b
|
37
|
+
b -> c
|
38
|
+
c -> a
|
39
|
+
{% enddigraph %}
|
40
|
+
|
41
|
+
{% graphviz %}
|
42
|
+
digraph "some graphviz title" {
|
43
|
+
a -> b
|
44
|
+
b -> c
|
45
|
+
c -> a
|
46
|
+
}
|
47
|
+
{% enddigraphviz %}
|
48
|
+
~~~~~~~~~~~~~~~~~~~~~~~
|
49
|
+
|
50
|
+
### Configs and Default Values
|
51
|
+
|
52
|
+
~~~~~~~~~~~~~~~~~~~~~~~yaml
|
53
|
+
# _config.yaml
|
54
|
+
graphviz:
|
55
|
+
options: "-Tsvg" # 'dot' command option
|
56
|
+
command: "dot" # execute this string. specify full path to 'dot' if you need
|
57
|
+
~~~~~~~~~~~~~~~~~~~~~~~
|
58
|
+
|
59
|
+
## Development
|
60
|
+
|
61
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
62
|
+
|
63
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
64
|
+
|
65
|
+
## Contributing
|
66
|
+
|
67
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jekyll-graphviz. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
68
|
+
|
69
|
+
|
70
|
+
## License
|
71
|
+
|
72
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
73
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "jekyll/graphviz"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jekyll/graphviz/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jekyll-graphviz"
|
8
|
+
spec.version = Jekyll::Graphviz::VERSION
|
9
|
+
spec.authors = ["Keiichiro Ui"]
|
10
|
+
spec.email = ["keiichiro.ui@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A liquid tag to convert with Graphviz for Jekyll}
|
13
|
+
spec.homepage = "https://github.com/kui/jekyll-graphviz"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "jekyll", ENV['JEKYLL_VERSION'] ? "~> #{ENV['JEKYLL_VERSION']}" : ">= 2.0"
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "minitest"
|
33
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "jekyll"
|
2
|
+
require "jekyll/graphviz/version"
|
3
|
+
require "jekyll/graphviz/block"
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
module Graphviz
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
Liquid::Template.register_tag('graphviz', Jekyll::Graphviz::Block)
|
11
|
+
Liquid::Template.register_tag('graph', Jekyll::Graphviz::Block)
|
12
|
+
Liquid::Template.register_tag('digraph', Jekyll::Graphviz::Block)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "liquid/block"
|
2
|
+
require "jekyll/graphviz/renderer"
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
module Graphviz
|
6
|
+
class Block < Liquid::Block
|
7
|
+
def initialize tag_name, text, tokens
|
8
|
+
super
|
9
|
+
@tag_name = tag_name
|
10
|
+
@title = text.strip
|
11
|
+
end
|
12
|
+
|
13
|
+
def render context
|
14
|
+
config = context.registers[:site].config
|
15
|
+
@renderer = Jekyll::Graphviz::Renderer.new(config["graphviz"])
|
16
|
+
render_graph super
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def render_graph code
|
22
|
+
case @tag_name
|
23
|
+
when 'graphviz' then render_graphviz code
|
24
|
+
when 'graph' then render_graphviz %[graph "#{@title}" {\n#{code}\n}]
|
25
|
+
when 'digraph' then render_graphviz %[digraph "#{@title}" {\n#{code}\n}]
|
26
|
+
else raise "unknown liquid tag name: #{@tag_name}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def render_graphviz code
|
31
|
+
@renderer.render code, @title
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require "digest/md5"
|
2
|
+
require "open3"
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
class Graphviz::Renderer
|
6
|
+
|
7
|
+
DIV_CLASS_ATTR = "graphviz-wrapper"
|
8
|
+
DEFAULT_OPTIONS = "-Tsvg"
|
9
|
+
DEFAULT_EXECUTABLE = "dot"
|
10
|
+
|
11
|
+
def initialize config = nil
|
12
|
+
@config = config || {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def render code, title = nil
|
16
|
+
title = gen_title(title, code)
|
17
|
+
svg = generate_svg code
|
18
|
+
svg = remove_declarations svg
|
19
|
+
svg = remove_xmlns_attrs svg
|
20
|
+
svg = add_desc_attrs svg, title
|
21
|
+
svg = insert_desc_elements svg, title, code
|
22
|
+
svg = wrap_with_div svg
|
23
|
+
svg
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def gen_title title, code
|
29
|
+
if title.nil? or title.empty?
|
30
|
+
then "graphviz-#{digest code}"
|
31
|
+
else title
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def digest str
|
36
|
+
Digest::MD5.hexdigest str
|
37
|
+
end
|
38
|
+
|
39
|
+
def generate_svg code
|
40
|
+
svg, status = Open3.capture2(cmd, stdin_data: code, binmode: true)
|
41
|
+
raise "Non-zero exit status '#{cmd}': #{status}" unless status.success?
|
42
|
+
svg.force_encoding 'UTF-8'
|
43
|
+
svg
|
44
|
+
end
|
45
|
+
|
46
|
+
def remove_declarations svg
|
47
|
+
svg
|
48
|
+
.sub(/<!DOCTYPE .+?>/im,'')
|
49
|
+
.sub(/<\?xml .+?\?>/im,'')
|
50
|
+
end
|
51
|
+
|
52
|
+
def remove_xmlns_attrs svg
|
53
|
+
svg
|
54
|
+
.sub(%[xmlns="http://www.w3.org/2000/svg"], '')
|
55
|
+
.sub(%[xmlns:xlink="http://www.w3.org/1999/xlink"], '')
|
56
|
+
end
|
57
|
+
|
58
|
+
def add_desc_attrs svg, title
|
59
|
+
svg
|
60
|
+
.sub("<svg", %[<svg aria-label="#{CGI::escapeHTML title}"])
|
61
|
+
.sub("<svg", %[<svg role="img"])
|
62
|
+
end
|
63
|
+
|
64
|
+
def insert_desc_elements svg, title, desc
|
65
|
+
inserted_elements = %[<title>#{CGI::escapeHTML title}</title>\n] +
|
66
|
+
%[<desc>#{CGI::escapeHTML desc}</desc>\n]
|
67
|
+
svg.sub(/(<svg [^>]*>)/, "\\1\n#{inserted_elements}")
|
68
|
+
end
|
69
|
+
|
70
|
+
def wrap_with_div svg
|
71
|
+
%[<div class="#{DIV_CLASS_ATTR}">#{svg}</div>]
|
72
|
+
end
|
73
|
+
|
74
|
+
def cmd
|
75
|
+
"#{exec} #{opts}"
|
76
|
+
end
|
77
|
+
|
78
|
+
def exec
|
79
|
+
@config && @config["executable"] || DEFAULT_EXECUTABLE
|
80
|
+
end
|
81
|
+
|
82
|
+
def opts
|
83
|
+
@config && @config["options"] || DEFAULT_OPTIONS
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-graphviz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Keiichiro Ui
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- keiichiro.ui@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- jekyll-graphviz.gemspec
|
85
|
+
- lib/jekyll/graphviz.rb
|
86
|
+
- lib/jekyll/graphviz/block.rb
|
87
|
+
- lib/jekyll/graphviz/renderer.rb
|
88
|
+
- lib/jekyll/graphviz/version.rb
|
89
|
+
homepage: https://github.com/kui/jekyll-graphviz
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata:
|
93
|
+
allowed_push_host: https://rubygems.org
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.4.5.1
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: A liquid tag to convert with Graphviz for Jekyll
|
114
|
+
test_files: []
|