jekyll-plantuml-lite 0.0.2
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/lib/encoder.rb +51 -0
- data/lib/jekyll-plantuml-lite.rb +18 -0
- data/lib/main.rb +10 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c9394b0425d8ae43ce0e988f3d420b43394352d130b0442af3fc8c321af323d4
|
4
|
+
data.tar.gz: bfb9798de588dd54b1d18f575833695abc8e6c02a35375bf5ec11dde759e0ff7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '08c230a7972a10ddb4e9f4363b30d5dc6cfed079591bf483898921f039f50d0e495f96ab98ee96842687a2fe33b2a36110fbb9ecb91be549e15043ab9c203de5'
|
7
|
+
data.tar.gz: '05681f4a94a41bebc41fb5cd8a1f55529936a7c87b4f53704f312643135e5b53c7201b4c888aeb17499c2343da0f913d4082de4a8101c7bb89bffcf7d882efd0'
|
data/lib/encoder.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require "zlib"
|
2
|
+
|
3
|
+
class Encoder
|
4
|
+
MAPPING_ARRAY = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_"
|
5
|
+
RAW_DEFLATE = -Zlib::MAX_WBITS
|
6
|
+
|
7
|
+
def encode(plantuml_content)
|
8
|
+
utf8_content = plantuml_content.strip.encode("UTF-8")
|
9
|
+
compressed = Zlib::Deflate.new(Zlib::BEST_COMPRESSION, RAW_DEFLATE).deflate(utf8_content, Zlib::FINISH)
|
10
|
+
bytes = compressed.bytes
|
11
|
+
|
12
|
+
current_index = 0
|
13
|
+
result = ""
|
14
|
+
|
15
|
+
while(current_index < bytes.length)
|
16
|
+
result += encode_three_bytes(
|
17
|
+
bytes[current_index].to_i,
|
18
|
+
bytes[current_index+1].to_i,
|
19
|
+
bytes[current_index+2].to_i
|
20
|
+
)
|
21
|
+
current_index += 3
|
22
|
+
end
|
23
|
+
|
24
|
+
return result
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
#
|
30
|
+
# Three bytes get divided into sextets and their decimal representation is the index
|
31
|
+
# of the character in the MAPPING_ARRAY.
|
32
|
+
#
|
33
|
+
# | Byte | 77 | 97 | 110 |
|
34
|
+
# | Bits | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 0 |
|
35
|
+
# | Sextet value | 19 | 22 | 5 | 46 |
|
36
|
+
# | Mapping array | J | M | 5 | k |
|
37
|
+
#
|
38
|
+
def encode_three_bytes(byte_1, byte_2, byte_3)
|
39
|
+
sextet_1 = byte_1 >> 2
|
40
|
+
sextet_2 = (((byte_1 & 0b00000011) << 4) | ((byte_2 & 0b11110000) >> 4))
|
41
|
+
sextet_3 = ((byte_2 & 0b00001111) << 2) | ((byte_3 & 0b11000000) >> 6)
|
42
|
+
sextet_4 = byte_3 & 0b00111111
|
43
|
+
|
44
|
+
result = ""
|
45
|
+
result += MAPPING_ARRAY[sextet_1]
|
46
|
+
result += MAPPING_ARRAY[sextet_2]
|
47
|
+
result += MAPPING_ARRAY[sextet_3]
|
48
|
+
result += MAPPING_ARRAY[sextet_4]
|
49
|
+
return result
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "jekyll"
|
2
|
+
require "liquid"
|
3
|
+
require_relative "main.rb"
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
class JekyllPlantUmlLite < Liquid::Block
|
7
|
+
def initialize(tag_name, text, tokens)
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def render(context)
|
12
|
+
content = super
|
13
|
+
return Main.new.to_plantuml content
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Liquid::Template.register_tag('plantuml', Jekyll::JekyllPlantUmlLite)
|
data/lib/main.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require_relative "encoder.rb"
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
class Main
|
5
|
+
def to_plantuml(content)
|
6
|
+
encoded_content = Encoder.new.encode(content)
|
7
|
+
server_response = Net::HTTP.get(URI("https://www.plantuml.com/plantuml/svg/#{encoded_content}"))
|
8
|
+
return server_response.sub("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>", "").force_encoding("utf-8")
|
9
|
+
end
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-plantuml-lite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maciej Toporowicz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-02-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Generating PlantUML diagrams in Jekyll using a PlantUML server.
|
14
|
+
email: maciej@toporowicz.it
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/encoder.rb
|
20
|
+
- lib/jekyll-plantuml-lite.rb
|
21
|
+
- lib/main.rb
|
22
|
+
homepage: https://github.com/maciejtoporowicz/jekyll-plantuml-lite
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata:
|
26
|
+
source_code_uri: https://github.com/maciejtoporowicz/jekyll-plantuml-lite
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubygems_version: 3.3.7
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Generated PlantUML diagrams in Jekyll
|
46
|
+
test_files: []
|