booklab-sml 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/booklab-sml.rb +1 -0
- data/lib/booklab/plantuml.rb +53 -0
- data/lib/booklab/sml/rules/plantuml.rb +2 -7
- data/lib/booklab/sml/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 551b90eee459ea8cc8ec51a6b90ba28f1db3a74b57d1fe4fa6b9818957761153
|
4
|
+
data.tar.gz: d77a9300d3d03a89de457f692069aeaf41b6f441abd4484b0a77739e586ed447
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6edcc789f0f393c766002436504723880c865dd9614ed8da5a2910cf1bd9b048bfd154d281c20bd2487e0f16b2f9305d05877bbb808d5b71c5138b28d8dc3e5d
|
7
|
+
data.tar.gz: e265252f0aa382d527f623fb32ee5776e8bf3040b7822b7a9c04c32b4ccd97d5e96a55750fe07c8dd221b5526b609c91898cbbe73d50f5b9e4cfabdbdc2e7f74
|
data/lib/booklab-sml.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
require "zlib"
|
2
|
+
|
3
|
+
module BookLab
|
4
|
+
class Plantuml
|
5
|
+
class << self
|
6
|
+
def encode(text)
|
7
|
+
result = ""
|
8
|
+
compressedData = Zlib::Deflate.deflate(text)
|
9
|
+
compressedData.chars.each_slice(3) do |bytes|
|
10
|
+
#print bytes[0], ' ' , bytes[1] , ' ' , bytes[2]
|
11
|
+
b1 = bytes[0].nil? ? 0 : (bytes[0].ord & 0xFF)
|
12
|
+
b2 = bytes[1].nil? ? 0 : (bytes[1].ord & 0xFF)
|
13
|
+
b3 = bytes[2].nil? ? 0 : (bytes[2].ord & 0xFF)
|
14
|
+
result += append3bytes(b1, b2, b3)
|
15
|
+
end
|
16
|
+
result
|
17
|
+
end
|
18
|
+
|
19
|
+
def append3bytes(b1, b2, b3)
|
20
|
+
c1 = b1 >> 2
|
21
|
+
c2 = ((b1 & 0x3) << 4) | (b2 >> 4)
|
22
|
+
c3 = ((b2 & 0xF) << 2) | (b3 >> 6)
|
23
|
+
c4 = b3 & 0x3F
|
24
|
+
return encode6bit(c1 & 0x3F).chr +
|
25
|
+
encode6bit(c2 & 0x3F).chr +
|
26
|
+
encode6bit(c3 & 0x3F).chr +
|
27
|
+
encode6bit(c4 & 0x3F).chr
|
28
|
+
end
|
29
|
+
|
30
|
+
def encode6bit(b)
|
31
|
+
if b < 10
|
32
|
+
return ('0'.ord + b).chr
|
33
|
+
end
|
34
|
+
b = b - 10
|
35
|
+
if b < 26
|
36
|
+
return ('A'.ord + b).chr
|
37
|
+
end
|
38
|
+
b = b - 26
|
39
|
+
if b < 26
|
40
|
+
return ('a'.ord + b).chr
|
41
|
+
end
|
42
|
+
b = b - 26
|
43
|
+
if b == 0
|
44
|
+
return '-'
|
45
|
+
end
|
46
|
+
if b == 1
|
47
|
+
return '_'
|
48
|
+
end
|
49
|
+
return '?'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -13,13 +13,8 @@ module BookLab::SML::Rules
|
|
13
13
|
code = (attrs[:code] || "").strip
|
14
14
|
return "" if code.blank?
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
%(<img src="#{src}" class="plantuml-image" />)
|
19
|
-
else
|
20
|
-
svg_code = URI::encode(code)
|
21
|
-
%(<img src="#{renderer.config.plantuml_service_host}/svg/#{svg_code}" class="plantuml-image" />)
|
22
|
-
end
|
16
|
+
svg_code = BookLab::Plantuml.encode(code)
|
17
|
+
%(<img src="#{renderer.config.plantuml_service_host}/svg/#{svg_code}" class="plantuml-image" />)
|
23
18
|
end
|
24
19
|
end
|
25
20
|
end
|
data/lib/booklab/sml/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: booklab-sml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- README.md
|
65
65
|
- Rakefile
|
66
66
|
- lib/booklab-sml.rb
|
67
|
+
- lib/booklab/plantuml.rb
|
67
68
|
- lib/booklab/sml/base.rb
|
68
69
|
- lib/booklab/sml/config.rb
|
69
70
|
- lib/booklab/sml/renderer.rb
|