jekyll-remote-plantuml 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/jekyll-remote-plantuml.rb +56 -0
- data/lib/plantuml-config.rb +15 -0
- data/lib/plantuml-encode64.rb +87 -0
- data/lib/plantuml-loader.rb +122 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f3d50bbea5bd6cde9c986bac6a241469e2991e0c
|
4
|
+
data.tar.gz: 72f51fb9ca50fcea5f745a36510ca302c6afe927
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 996b4c79ec386508ff8a5070ea2a6c5fca9159ca339d79510c37bba54510d2ab122692050530c012eb68faa2b18f8ecbaded16d664e33cc6eb48036c1352376e
|
7
|
+
data.tar.gz: cf5960abd36745dc8be6a555dbc7322af86a6c21bb782456d77256117bc37da7c190a518298677c067acaa6f81b23abfebe1d454034bda65c32245a2d6905fa8
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2015 Patrick Allain
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
# this software and associated documentation files (the "Software"), to deal in
|
7
|
+
# the Software without restriction, including without limitation the rights to
|
8
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
# subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# 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, FITNESS
|
17
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'jekyll'
|
23
|
+
require 'plantuml-config'
|
24
|
+
require 'plantuml-encode64'
|
25
|
+
require 'plantuml-loader'
|
26
|
+
|
27
|
+
#
|
28
|
+
|
29
|
+
# Jekyll plugin for plantuml generation
|
30
|
+
#
|
31
|
+
# Any generation is store localy to prevent any further call
|
32
|
+
# on a remote provider.
|
33
|
+
module Jekyll
|
34
|
+
|
35
|
+
class PlantUmlBlock < Liquid::Block
|
36
|
+
|
37
|
+
# Plugin initilializer
|
38
|
+
def initialize(tag_name, markup, tokens)
|
39
|
+
super
|
40
|
+
@markup = markup;
|
41
|
+
end
|
42
|
+
|
43
|
+
# Render
|
44
|
+
def render(context)
|
45
|
+
output = super(context);
|
46
|
+
code, pconf, baseurl = PlantUmlEncode64.new(output).encode(), PlantUmlConfig::DEFAULT, Jekyll.configuration({})['baseurl'];
|
47
|
+
p = {:url => pconf[:url], :type => pconf[:type], :code => code }
|
48
|
+
Jekyll.logger.debug "Generate html with input params :", p;
|
49
|
+
d = RemoteLoader.instance.savedRemoteBinary(p);
|
50
|
+
return "<img src=\"%{baseurl}%{uri}\" />" % d.merge({ :baseurl => baseurl });
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
Liquid::Template.register_tag('uml', Jekyll::PlantUmlBlock)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Config for plantuml plugin.
|
2
|
+
|
3
|
+
require 'singleton';
|
4
|
+
|
5
|
+
class PlantUmlConfig
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
DEFAULT = {
|
9
|
+
:assets => 'assets/images/plantuml/',
|
10
|
+
:type => 'png',
|
11
|
+
:encode => 'encode64',
|
12
|
+
:url => 'http://www.plantuml.com/plantuml/{type}/{code}'
|
13
|
+
}
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2015 Patrick Allain
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
# this software and associated documentation files (the "Software"), to deal in
|
7
|
+
# the Software without restriction, including without limitation the rights to
|
8
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
# subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# 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, FITNESS
|
17
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
class PlantUmlEncode64
|
23
|
+
|
24
|
+
def initialize(input)
|
25
|
+
@input = input;
|
26
|
+
end
|
27
|
+
|
28
|
+
# Public : proceed to the encoding for plantuml servlet
|
29
|
+
#
|
30
|
+
# Returns the encoded uml to send to the servlet
|
31
|
+
def encode()
|
32
|
+
require 'zlib';
|
33
|
+
o = @input.force_encoding("utf-8");
|
34
|
+
o = Zlib::Deflate.new(nil, -Zlib::MAX_WBITS).deflate(o, Zlib::FINISH)
|
35
|
+
return PlantUmlEncode64.encode64(o);
|
36
|
+
end
|
37
|
+
|
38
|
+
# Internal : Encode is some special base 64.
|
39
|
+
#
|
40
|
+
# @param a deflate string
|
41
|
+
# Returns a encoded string
|
42
|
+
def self.encode64(input)
|
43
|
+
len, i, out = input.length, 0, "";
|
44
|
+
while i < len do
|
45
|
+
i1 = (i+1 < len) ? input[i+1].ord : 0;
|
46
|
+
i2 = (i+2 < len) ? input[i+2].ord : 0;
|
47
|
+
out += append3bytes(input[i].ord, i1, i2);
|
48
|
+
i += 3;
|
49
|
+
end
|
50
|
+
return out
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.encode6bit(b)
|
54
|
+
if b < 10 then
|
55
|
+
return (48 + b).chr;
|
56
|
+
end
|
57
|
+
|
58
|
+
b -= 10;
|
59
|
+
if b < 26 then
|
60
|
+
return (65 + b).chr;
|
61
|
+
end
|
62
|
+
|
63
|
+
b -= 26;
|
64
|
+
if b < 26 then
|
65
|
+
return (97 + b).chr;
|
66
|
+
end
|
67
|
+
|
68
|
+
b -= 26;
|
69
|
+
if b == 0 then
|
70
|
+
return '-';
|
71
|
+
end
|
72
|
+
|
73
|
+
return (b == 1) ? '_' : '?';
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.append3bytes(b1, b2, b3)
|
77
|
+
c1 = (b1 >> 2)
|
78
|
+
c2 = ((b1 & 0x3) << 4) | (b2 >> 4)
|
79
|
+
c3 = ((b2 & 0xF) << 2) | (b3 >> 6)
|
80
|
+
c4 = b3 & 0x3F;
|
81
|
+
r = encode6bit(c1 & 0x3F)
|
82
|
+
r += encode6bit(c2 & 0x3F);
|
83
|
+
r += encode6bit(c3 & 0x3F);
|
84
|
+
return r + encode6bit(c4 & 0x3F);
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2015 Patrick Allain
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
# this software and associated documentation files (the "Software"), to deal in
|
7
|
+
# the Software without restriction, including without limitation the rights to
|
8
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
# subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# 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, FITNESS
|
17
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
# Remote loader to retrieve binary or text file from remote url
|
23
|
+
# depending of the parameters provide and the method use
|
24
|
+
#
|
25
|
+
|
26
|
+
require 'digest'
|
27
|
+
require 'fileutils'
|
28
|
+
require 'jekyll';
|
29
|
+
|
30
|
+
require 'singleton'
|
31
|
+
require 'open-uri'
|
32
|
+
require 'plantuml-config'
|
33
|
+
|
34
|
+
# Load data from a remote url.
|
35
|
+
|
36
|
+
#
|
37
|
+
# data is loaded once time. If we can found data in cache, just use
|
38
|
+
# the cache instead of making lot of remote call.
|
39
|
+
class RemoteLoader
|
40
|
+
include Singleton
|
41
|
+
|
42
|
+
# Callback for plain text content
|
43
|
+
CONTENT_CALLBACKS = {
|
44
|
+
'svg' => { :matcher => /\<\?xml.*?\>/, :replacement => '' }
|
45
|
+
}
|
46
|
+
|
47
|
+
# Initialization of the loaded dir
|
48
|
+
#
|
49
|
+
# Define the constant for the prefix url for binary file
|
50
|
+
# and the directory where all file will be saved
|
51
|
+
def initialize()
|
52
|
+
conf = Jekyll.configuration({});
|
53
|
+
pconf = PlantUmlConfig::DEFAULT.merge(conf['plantuml'] || {});
|
54
|
+
dirname = conf['source'] + File::SEPARATOR + pconf[:assets].gsub(/\//, File::SEPARATOR).sub(/\/*$/, '').sub(/^\/*/, '');
|
55
|
+
Jekyll.logger.info "Directory for storage remote data : %s" % [dirname],
|
56
|
+
unless File.directory?(dirname) then
|
57
|
+
Jekyll.logger.info "Create directory %s because this seems to be missing" % [dirname]
|
58
|
+
FileUtils.mkdir_p(dirname)
|
59
|
+
end
|
60
|
+
@prefixUrl = pconf[:assets];
|
61
|
+
@dirname = dirname;
|
62
|
+
end
|
63
|
+
|
64
|
+
# Internal : get the url from a config
|
65
|
+
#
|
66
|
+
# @param a hash with {:url, :code, :type } inside it
|
67
|
+
# Returns the url for remote to retrieve
|
68
|
+
def createRemoteUri(params)
|
69
|
+
uri = params[:url];
|
70
|
+
uri = uri.gsub(/\{code\}/, params[:code])
|
71
|
+
uri = uri.gsub(/\{type\}/, params[:type])
|
72
|
+
return uri;
|
73
|
+
end
|
74
|
+
|
75
|
+
# Internal : get the data for the remote connection
|
76
|
+
#
|
77
|
+
# @param a hash with {:url, :code, :type } inside it
|
78
|
+
# Returns the data as a hash
|
79
|
+
def getData(params)
|
80
|
+
ruri = createRemoteUri(params);
|
81
|
+
fn = Digest::SHA256.hexdigest(ruri) + "." + params[:type]
|
82
|
+
return { :remoteUri => ruri, :uri => @prefixUrl + fn, :path => @dirname + File::SEPARATOR + fn }
|
83
|
+
end
|
84
|
+
|
85
|
+
# Public : get and saved the remote uri from a parameters hash
|
86
|
+
# if the same content has already been downloaded previously,
|
87
|
+
# just retrieve return the file information.
|
88
|
+
#
|
89
|
+
# @param a hash with {:url, :code, :type } inside it
|
90
|
+
# Returns a hash with { :remoteUri, :uri, :path }
|
91
|
+
def savedRemoteBinary(params)
|
92
|
+
Jekyll.logger.debug "Plantuml remote loader params :", params;
|
93
|
+
data = getData(params);
|
94
|
+
unless File.exist?(data[:path]) then
|
95
|
+
Jekyll.logger.info "Starting download content at %{remoteUri} done into file %{path}." % data;
|
96
|
+
open(data[:path], 'wb') do |file|
|
97
|
+
file << open(data[:remoteUri]).read
|
98
|
+
Jekyll.logger.info "End download content at %{remoteUri} done into file %{path}." % data;
|
99
|
+
end
|
100
|
+
else
|
101
|
+
Jekyll.logger.info "File %{path} has been found. Not download at %{remoteUri} will be made." % data;
|
102
|
+
end
|
103
|
+
return data;
|
104
|
+
end
|
105
|
+
|
106
|
+
# Public : get and saved the remote uri from a parameters hash
|
107
|
+
# if the same content has already been downloaded previously,
|
108
|
+
# just return the file content.
|
109
|
+
#
|
110
|
+
# @param a hash with {:url, :code, :type } inside it
|
111
|
+
# Returns the content of the remote
|
112
|
+
def loadText(params)
|
113
|
+
d = savedRemoteBinary(params);
|
114
|
+
content = File.read(d[:path]);
|
115
|
+
tc = CONTENT_CALLBACKS[params[:type].downcase];
|
116
|
+
if tc then
|
117
|
+
content = content.gsub(tc[:matcher], tc[:replacement]);
|
118
|
+
end
|
119
|
+
return content;
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-remote-plantuml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Patouche
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-20 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: 0.11.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.11.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Jekyll to use plantuml with remote provider without any local plantuml.jar
|
56
|
+
installation
|
57
|
+
email: patralla@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/jekyll-remote-plantuml.rb
|
63
|
+
- lib/plantuml-config.rb
|
64
|
+
- lib/plantuml-encode64.rb
|
65
|
+
- lib/plantuml-loader.rb
|
66
|
+
homepage: http://rubygems.org/gems/jekyll-remote-plantuml
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 2.2.2
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: Jekyll remote plantuml
|
90
|
+
test_files: []
|