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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a29e8fb23fa84105ae92ce79ebb41e9b5f6093a96b9753df6e4e86a0240d7018
4
- data.tar.gz: 2e374bba32a962c3fea73af545930bd4537fe4219b4d145d500c789229c248cf
3
+ metadata.gz: 551b90eee459ea8cc8ec51a6b90ba28f1db3a74b57d1fe4fa6b9818957761153
4
+ data.tar.gz: d77a9300d3d03a89de457f692069aeaf41b6f441abd4484b0a77739e586ed447
5
5
  SHA512:
6
- metadata.gz: a63bdb80125013ec3cfb85987f63d200c239f09aef363ab1a6e2091094677753d65982fe2fb9aef35abdff52907b8d046660a15e28d03145598f6e5b8447dc67
7
- data.tar.gz: 337b5b5def18137040cda6191e50ad2e6150ea9326c30b10d1fb78ebb34815086fc2c1fed564bb1b89d66dcc3269bdbe561505192c51179d3e264539971d26de
6
+ metadata.gz: 6edcc789f0f393c766002436504723880c865dd9614ed8da5a2910cf1bd9b048bfd154d281c20bd2487e0f16b2f9305d05877bbb808d5b71c5138b28d8dc3e5d
7
+ data.tar.gz: e265252f0aa382d527f623fb32ee5776e8bf3040b7822b7a9c04c32b4ccd97d5e96a55750fe07c8dd221b5526b609c91898cbbe73d50f5b9e4cfabdbdc2e7f74
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support/concern"
4
+ require "booklab/plantuml"
4
5
  require "booklab/sml/version"
5
6
  require "booklab/sml/utils"
6
7
  require "booklab/sml/rules"
@@ -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
- src = attrs[:src]
17
- if src
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module BookLab
4
4
  module SML
5
- VERSION = "0.4.0"
5
+ VERSION = "0.5.0"
6
6
  end
7
7
  end
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.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