jekyll-plantuml-base64 0.1.4.36

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 44aadf5dcb505f68c5bb567f12178a05d12b447b1a69848f91ae74db7a442da2
4
+ data.tar.gz: 527964e789b049de5c30332dc6ae0deeb2f51a5cf07b70f82d9f8fff82d9e876
5
+ SHA512:
6
+ metadata.gz: 03523a9a51538d487f5ec43c9ed81a848aeb0624e91d87138666ca39e1a81552f4a8dbc89e508c08299e86e205e71475d3ee353ef0a376589eb84bd3d402c0cd
7
+ data.tar.gz: eaa7f896b954308586b8b4db09bf6a0e693b5328f602550a2634752992d57ee6c8a0e28344595c65527b9e090b68bace2a3f5bab280a8413c49c178f7923439b
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
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.
data/README.md ADDED
@@ -0,0 +1,123 @@
1
+ # jekyll-plantuml-base64
2
+
3
+ [![Build Status](https://travis-ci.org/RobbiNespu/jekyll-plantuml-base64.svg?branch=master)](https://travis-ci.org/RobbiNespu/jekyll-plantuml-base64)
4
+ [![Gem Version](https://badge.fury.io/rb/jekyll-plantuml-base64.svg)](https://badge.fury.io/rb/jekyll-plantuml-base64)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/aafba8fb4df9ac92e485/maintainability)](https://codeclimate.com/github/RobbiNespu/jekyll-plantuml-base64/maintainability)
6
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/cd56b207f327603662a1/test_coverage)](https://codeclimate.com/github/robbinespu/jekyll-plantuml-base64/test_coverage)
7
+ [![security](https://hakiri.io/github/RobbiNespu/jekyll-plantuml-base64/master.svg)](https://hakiri.io/github/RobbiNespu/jekyll-plantuml-base64/master)
8
+
9
+ A Jekyll plugin to simplify the creation of diagrams and flowcharts in your posts and pages with PlantUML as base64 image.
10
+ forked from: [https://github.com/Patouche/jekyll-remote-plantuml](https://github.com/Patouche/jekyll-remote-plantuml)
11
+
12
+ A plugin for jekyll to use plantuml diagram inside your [Jekyll](http://jekyllrb.com/) for you website. Origin of this code will use external resource to build plantuml diagram. Once created, the diagram is store on the filesystem to prevent any unnecessary diagram generation. So, using this plugin, provide a simple way to integrate plantuml diagramm without the [Graphiz](http://www.graphviz.org/) software or the using the [plantuml](http://sourceforge.net/projects/plantuml/files/plantuml.jar/download) jar file but I modified by convert that file into base64 and displayed on your website.
13
+
14
+ ## Installation
15
+
16
+ Option 1:
17
+ To install this plugin on Jekyll, you just have to follow the guideline of Jekyll [documentation](http://jekyllrb.com/docs/plugins/)
18
+
19
+ Option 2:
20
+ Use rubygems, by adding `gem 'jekyll-plantuml-base64', '~> 0.1.4.34'` on your gemfile then `bundle install`
21
+
22
+ Option 3:
23
+ Pull the gems directly from git by adding `gem 'jekyll-remote-plantuml', '0.1.4.34', git: 'https://github.com/RobbiNespu/jekyll-remote-plantuml'` on your gemfile and then `bundle install`
24
+ ## Usage
25
+
26
+ To use the jekyll-plantuml-base64 plugin, you just have to wrap you text between `{% plantuml %}` and `{% endplantuml %}` tags.
27
+
28
+ For example, to create a basic shema between Bob and Alice, you can write the following code :
29
+
30
+ ``` text
31
+ {% plantuml %}
32
+ Bob -> Alice : Hello
33
+ {% endplantuml %}
34
+ ```
35
+
36
+ This will retrieve the binary from a remote provider and add it into the folder defined in your configuration.
37
+
38
+ ![Bob and Alice generated](./images/bob-alice.png)
39
+
40
+ The origin will generated html will have be something like :
41
+
42
+ ``` html
43
+ <img src="/assets/images/plantuml/765f88ab868d9706e797ff2c90c67a549a144c52adf0bf2e247d355cf981b9aa.png" />
44
+ ```
45
+ Any update of the uml will regenerated the image file using the remote. If the uml is not modified, no request will be made on the remote provider.
46
+
47
+ but this code will convert them nto base64 format
48
+ ```html
49
+ <img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAK0AAAA2CAIAAAA6bI6UAAAAKXRFWHRjb3B5bGVmdABHZW5lcmF0
50
+ ZWQgYnkgaHR0cDovL3BsYW50dW1sLmNvbREwORwAAAEAaVRYdHBsYW50dW1sAAEAAAB4nDWOTW+C
51
+ QBCG75v4H+YIaSRgTT84mbbaxkBqXOFiPKwwJZvCLFlmaf33XSU9zrzPO/OsBlaWXdfOxHGj7cAn
52
+ mMNRYmWoPs3ECqm+hWLXKuIiz2BEO2hDkESLeBFH8fMZWd0HBX2T+SGoTNfrFoF1h6EI3ncZDMbZ
53
+ CqHWA1t9duzbodiqUcHe0ZVL4ToFhzwEuf5fwppGbQ11SCy2ZT5B8GFY9oZv8MNy/qIZJFovBWU+
54
+ HS0nwRSSZRRHyd2j+OzRKtbUgLwMjF0KmSb3K97wS7mW/afK1D5OoThs5k8iU9Q41XgvJPFqvI+9
55
+ +EyKP+zJYyYQDMQMAAAHgUlEQVR4Xu1ceUwUVxxeUfEuVVTilWpMPVprjfGKGqOJTYONiX9Ua63W
56
+ P0x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tepPJTnAJvsggVfREdH
83
+ oTKNjR0RnvfG0JMqwyjwKZ+dVANFDuqBT/nspBpopu+p6sgIGqaQz06qgeL7ByaQz06qgWb6nqqO
84
+ jKBhCvnspBoovp9oAvnspBoocmAC+eykGii+p2oC+eykGijqRBPIZyfVQPE9VRPIZyfVQPF7pHrg
85
+ Uz47qQaKHNQDn/LZSTXQfw606qZwkdRrOjKMAp/y2Uk10H8O+KSODKPAs3x26hiozIG8bsq2pmTF
86
+ Je1YlmBfGo9LhJ/b7VoyjALX8tmpbaAyB3J4PB6Xy+VwONJ4gt8/328I8CmfHX4N1MtBYWEhUuN0
87
+ OjHSxge0/p1HQ4BD+ezQMlAvB1g3vF4vxiA+WXxA69/7NAQ4lM8OLQP1coC8oDeCgzXEzQe0/t1X
88
+ Q4BD+ezQMlAvB+iHyGAANpISPoA7wf3grnBvNTU1yjs2FBzKZ4eWgXo5EHhzIHIg4IPIgYAP/wGD
89
+ zxhdIJCj5gAAAABJRU5ErkJggg==
90
+ ">
91
+ ```
92
+ Mean, i do not need to really install this file because during CI/CD build process, the plugin will convert them into base64. Anyway, it will execute every time you build. If you have a lots of image and heavy / big images then pls consider using original plugins.
93
+
94
+
95
+ ## Configuration
96
+
97
+ For now, the configuration is really poor. You can just change the remote provider and the location where are store the binary files.
98
+
99
+ ``` yaml
100
+ plantuml:
101
+ url: 'http://www.plantuml.com/plantuml/png/{code}'
102
+ assets: '_images/plantuml/'
103
+ ```
104
+
105
+ check file plantuml-config.rb
106
+ ```ruby
107
+ DEFAULT = {
108
+ :assets => 'assets/img/plantuml/',
109
+ :type => 'png',
110
+ :encode => 'encode64',
111
+ :url => 'http://www.plantuml.com/plantuml/{type}/{code}'
112
+ }
113
+ ```
114
+
115
+ ### Notes
116
+
117
+ I'm sorry if it's sad code for a ruby developper which I'm not. I tried to do my best and to share it with the community. So please be lenient.
118
+
119
+ If you have any request, please leave a message and don't hesitate for any pull request.
120
+
121
+ ## License
122
+
123
+ This plugin is under the MIT license. See [LICENSE.txt](./LICENSE.txt) file for more details.
@@ -0,0 +1,62 @@
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
+ host,port = Jekyll.configuration({})['host'], Jekyll.configuration({})['port']
48
+ p = {:url => pconf[:url], :type => pconf[:type], :code => code }
49
+ Jekyll.logger.debug "Generate html with input params :", p;
50
+ #d = RemoteLoader.instance.savedRemoteBinary(p);
51
+ d = RemoteLoader.instance.savedRemoteBinaryBase64(p);
52
+ #puts d
53
+ return "#{d}"
54
+ #return "<img src=\"http://#{host}:#{port}/%{baseurl}%{uri}\" />" % d.merge({ :baseurl => baseurl });
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+
61
+ Liquid::Template.register_tag('plantuml', Jekyll::PlantUmlBlock);
62
+
@@ -0,0 +1,43 @@
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 'singleton';
23
+
24
+ #
25
+
26
+ # Jelyll plugin configuration for plantuml plugin.
27
+ # This will define default value for any missing value in configuration
28
+ #
29
+ # @todo : for now, all of this value are not use.
30
+ class PlantUmlConfig
31
+ include Singleton
32
+
33
+ # Default configuration as a constant hash
34
+ # If a definition cannot be found in the jekyll configuration, this configuration
35
+ # will be use
36
+ DEFAULT = {
37
+ :assets => 'assets/img/plantuml/',
38
+ :type => 'png',
39
+ :encode => 'encode64',
40
+ :url => 'http://www.plantuml.com/plantuml/{type}/{code}'
41
+ }
42
+
43
+ end
@@ -0,0 +1,90 @@
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
+ # Encode the uml code into a string to provide for building the image with a remote provider.
23
+ #
24
+ # This code is inspired by the page of plantuml website http://plantuml.sourceforge.net/codephp.html
25
+ class PlantUmlEncode64
26
+
27
+ def initialize(input)
28
+ @input = input;
29
+ end
30
+
31
+ # Public : proceed to the encoding for plantuml servlet
32
+ #
33
+ # Returns the encoded uml to send to the servlet
34
+ def encode()
35
+ require 'zlib';
36
+ o = @input.force_encoding("utf-8");
37
+ o = Zlib::Deflate.new(nil, -Zlib::MAX_WBITS).deflate(o, Zlib::FINISH)
38
+ return PlantUmlEncode64.encode64(o);
39
+ end
40
+
41
+ # Internal : Encode is some special base 64.
42
+ #
43
+ # @param a deflate string
44
+ # Returns a encoded string
45
+ def self.encode64(input)
46
+ len, i, out = input.length, 0, "";
47
+ while i < len do
48
+ i1 = (i+1 < len) ? input[i+1].ord : 0;
49
+ i2 = (i+2 < len) ? input[i+2].ord : 0;
50
+ out += append3bytes(input[i].ord, i1, i2);
51
+ i += 3;
52
+ end
53
+ return out
54
+ end
55
+
56
+ def self.encode6bit(b)
57
+ if b < 10 then
58
+ return (48 + b).chr;
59
+ end
60
+
61
+ b -= 10;
62
+ if b < 26 then
63
+ return (65 + b).chr;
64
+ end
65
+
66
+ b -= 26;
67
+ if b < 26 then
68
+ return (97 + b).chr;
69
+ end
70
+
71
+ b -= 26;
72
+ if b == 0 then
73
+ return '-';
74
+ end
75
+
76
+ return (b == 1) ? '_' : '?';
77
+ end
78
+
79
+ def self.append3bytes(b1, b2, b3)
80
+ c1 = (b1 >> 2)
81
+ c2 = ((b1 & 0x3) << 4) | (b2 >> 4)
82
+ c3 = ((b2 & 0xF) << 2) | (b3 >> 6)
83
+ c4 = b3 & 0x3F;
84
+ r = encode6bit(c1 & 0x3F)
85
+ r += encode6bit(c2 & 0x3F);
86
+ r += encode6bit(c3 & 0x3F);
87
+ return r + encode6bit(c4 & 0x3F);
88
+ end
89
+
90
+ end
@@ -0,0 +1,143 @@
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
+ initConf = conf['plantuml'] || {};
54
+ pconf = PlantUmlConfig::DEFAULT.merge(initConf);
55
+ dirname = conf['source'] + File::SEPARATOR + pconf[:assets].gsub(/\//, File::SEPARATOR).sub(/\/*$/, '').sub(/^\/*/, '');
56
+ Jekyll.logger.info "Directory for storage remote data : %s" % [dirname],
57
+ unless File.directory?(dirname) then
58
+ Jekyll.logger.info "Create directory %s because this seems to be missing" % [dirname]
59
+ FileUtils.mkdir_p(dirname)
60
+ end
61
+ @prefixUrl = pconf[:assets];
62
+ @dirname = dirname;
63
+ end
64
+
65
+ # Internal : get the url from a config
66
+ #
67
+ # @param a hash with {:url, :code, :type } inside it
68
+ # Returns the url for remote to retrieve
69
+ def createRemoteUri(params)
70
+ uri = params[:url];
71
+ uri = uri.gsub(/\{code\}/, params[:code])
72
+ uri = uri.gsub(/\{type\}/, params[:type])
73
+ return uri;
74
+ end
75
+
76
+ # Internal : get the data for the remote connection
77
+ #
78
+ # @param a hash with {:url, :code, :type } inside it
79
+ # Returns the data as a hash
80
+ def getData(params)
81
+ ruri = createRemoteUri(params);
82
+ fn = Digest::SHA256.hexdigest(ruri) + "." + params[:type]
83
+ return { :remoteUri => ruri, :uri => @prefixUrl + fn, :path => @dirname + File::SEPARATOR + fn }
84
+ end
85
+
86
+ # Public : get and saved the remote uri from a parameters hash
87
+ # if the same content has already been downloaded previously,
88
+ # just retrieve return the file information.
89
+ #
90
+ # @param a hash with {:url, :code, :type } inside it
91
+ # Returns a hash with { :remoteUri, :uri, :path }
92
+ def savedRemoteBinary(params)
93
+ Jekyll.logger.debug "Plantuml remote loader params :", params;
94
+ data = getData(params);
95
+ unless File.exist?(data[:path]) then
96
+ Jekyll.logger.info "Starting download content at %{remoteUri} done into file %{path}." % data;
97
+ open(data[:path], 'wb') do |file|
98
+ file << open(data[:remoteUri]).read
99
+ Jekyll.logger.info "End download content at %{remoteUri} done into file %{path}." % data;
100
+ end
101
+ else
102
+ Jekyll.logger.info "File %{path} has been found. Not download at %{remoteUri} will be made." % data;
103
+ end
104
+ return data;
105
+ end
106
+
107
+
108
+ def savedRemoteBinaryBase64(params)
109
+ Jekyll.logger.debug "Plantuml remote loader params :", params;
110
+ data = getData(params);
111
+ unless File.exist?(data[:path]) then
112
+ Jekyll.logger.info "Starting download content at %{remoteUri} done into file %{path}." % data;
113
+ open(data[:path], 'wb') do |file|
114
+ file << open(data[:remoteUri]).read
115
+ Jekyll.logger.info "End download content at %{remoteUri} done into file %{path}." % data;
116
+ end
117
+ else
118
+ Jekyll.logger.info "File %{path} has been found. Not download at %{remoteUri} will be made." % data;
119
+ end
120
+ Jekyll.logger.info "turn data into base64 format" % data;
121
+ echo = "cat %{path}" %data;
122
+ base64 = `#{echo} | base64`
123
+ #Jekyll.logger.info "ZZZZZ we got > #{base64}"
124
+ #return base64
125
+ return "<img src=\"data:image/png;base64, #{base64}\">"
126
+ end
127
+
128
+ # Public : get and saved the remote uri from a parameters hash
129
+ # if the same content has already been downloaded previously,
130
+ # just return the file content.
131
+ #
132
+ # @param a hash with {:url, :code, :type } inside it
133
+ # Returns the content of the remote
134
+ def loadText(params)
135
+ d = savedRemoteBinary(params);
136
+ content, tc = File.read(d[:path]), CONTENT_CALLBACKS[params[:type].downcase];
137
+ if tc then
138
+ content = content.gsub(tc[:matcher], tc[:replacement]);
139
+ end
140
+ return content;
141
+ end
142
+
143
+ end
@@ -0,0 +1,14 @@
1
+ require 'minitest/autorun'
2
+ require 'plantuml-encode64'
3
+
4
+ class PlantUmlEncode64Test < Minitest::Test
5
+
6
+ def setup
7
+ Jekyll.logger.log_level = :debug
8
+ end
9
+
10
+ def test_encode_one
11
+ assert_equal "SyfFqhLppCbCJbMmKiX8pSd91m00", PlantUmlEncode64.new("Bob->Alice : hello").encode()
12
+ end
13
+
14
+ end
@@ -0,0 +1,66 @@
1
+ require 'minitest/autorun'
2
+ require 'plantuml-loader'
3
+ require 'plantuml-config'
4
+ require 'jekyll'
5
+
6
+ class RemoteLoaderTest < Minitest::Test
7
+
8
+ GENERATION_FOLDER = PlantUmlConfig::DEFAULT[:assets].sub(/^\/*/, '');
9
+
10
+ ROOT_FOLDER = GENERATION_FOLDER.sub(/^([^\/]+).*$/, '\1');
11
+
12
+ GENERATED = "_images/plantuml/1fc2071adfcf94c83cb527ea98c29cae1656a085ff72acb12db7518fe93f1869.png";
13
+
14
+ def setup
15
+ Jekyll.logger.log_level = :debug
16
+ d = d = Jekyll.configuration({})['source'] + File::SEPARATOR + GENERATION_FOLDER;
17
+ if !File.exist?(d) then
18
+ FileUtils.mkdir_p(d);
19
+ end
20
+ end
21
+
22
+ def teardown
23
+ d = Jekyll.configuration({})['source'] + File::SEPARATOR + ROOT_FOLDER;
24
+ if File.exist?(d) then
25
+ FileUtils.remove_dir(d);
26
+ end
27
+ end
28
+
29
+ def test_createUri
30
+ params = { :url => "http://someurl.com/{type}/{code}", :type => "inputType", :code => "inputCode" };
31
+ assert_equal "http://someurl.com/inputType/inputCode", RemoteLoader.instance.createRemoteUri(params), "uri generation";
32
+ end
33
+
34
+ def test_savedRemoteBinary_checkDownload
35
+ #skip('Remote connection made')
36
+ params = { :url => "http://www.plantuml.com/plantuml/{type}/{code}", :type => "png", :code => "SyfFKj2rKt3CoKnELR1Io4ZDoSa70000" };
37
+
38
+ obj = RemoteLoader.instance.savedRemoteBinary(params);
39
+ assert_equal GENERATED, obj[:uri], "file created with defined hash";
40
+ assert File.exist?(obj[:path]), "file exist";
41
+ end
42
+
43
+ def test_savedRemoteBinary_downloadOnlyOnce
44
+ #skip('Remote connection made')
45
+ params = { :url => "http://www.plantuml.com/plantuml/{type}/{code}", :type => "png", :code => "SyfFKj2rKt3CoKnELR1Io4ZDoSa70000" };
46
+
47
+ obj = RemoteLoader.instance.savedRemoteBinary(params);
48
+ assert_equal GENERATED, obj[:uri], "file created with defined hash";;
49
+ assert File.exist?(obj[:path]), "file exist";;
50
+ mtime = File.mtime(obj[:path]);
51
+
52
+ obj2 = RemoteLoader.instance.savedRemoteBinary(params);
53
+ assert_equal mtime, File.mtime(obj2[:path]), "file not modified";;
54
+ end
55
+
56
+ def test_loadText
57
+ #skip('Remote connection made')
58
+ params = { :url => "http://www.plantuml.com/plantuml/{type}/{code}", :type => "svg", :code => "SyfFKj2rKt3CoKnELR1Io4ZDoSa70000" };
59
+
60
+ content = RemoteLoader.instance.loadText(params);
61
+ refute_nil content, "retrieve content must not be null";
62
+ assert_match /^\<svg/, content, "start with svg tag";
63
+ assert_match /<\/svg>$/, content, "end with svg tag";
64
+ end
65
+
66
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-plantuml-base64
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4.36
5
+ platform: ruby
6
+ authors:
7
+ - Robbi Nespu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-04-28 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: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
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: '5.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.4'
55
+ description: jekyll plugin to include plantuml diagram in jekyll website as base64
56
+ image
57
+ email: robbinespu@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE.txt
63
+ - README.md
64
+ - lib/jekyll-remote-plantuml.rb
65
+ - lib/plantuml-config.rb
66
+ - lib/plantuml-encode64.rb
67
+ - lib/plantuml-loader.rb
68
+ - test/test_plantuml-encode64.rb
69
+ - test/test_plantuml-loader.rb
70
+ homepage: https://robbinespu.gitlab.io/blog/2020/05/11/jekyll-features-plantuml-base64/
71
+ licenses:
72
+ - MIT
73
+ metadata:
74
+ source_code_uri: http://github.com/RobbiNespu/jekyll-plantuml-base64
75
+ bug_tracker_uri: http://github.com/RobbiNespu/jekyll-plantuml-base64/issues
76
+ post_install_message: Thanks for installing!
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.1.2
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Jekyll plugin for plantuml base64 image format
95
+ test_files:
96
+ - test/test_plantuml-encode64.rb
97
+ - test/test_plantuml-loader.rb