abbreviato 0.8.5 → 0.8.8
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 +5 -5
- data/lib/abbreviato/truncated_sax_document.rb +11 -3
- data/lib/abbreviato/version.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4b26ce55364c125faf5446912cfcf708bee335eb2e084179af383867b1e5e85d
|
4
|
+
data.tar.gz: 21ce5525a2c8d128348fdfd3b84523834b7d438c67a9e120bc44d1e42a7ddf9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2fa25c5df52264aafde82a093684d176ccae3ce319e19e02ba35bece2c18ecf0a2458c2890a8d0304e20837d0984c863490df14ae0ce7d699d5aee03072aae9
|
7
|
+
data.tar.gz: b1d8cbcce4e066bf65a0bae35399e660eb08bfb8ce8076f0bba5b8739158160606d9444733aeffd1a73df8e81911e8037050ab83b314cde5576ec0962cfe9dfd
|
@@ -68,7 +68,7 @@ class TruncatedSaxDocument < Nokogiri::XML::SAX::Document
|
|
68
68
|
encoded_string = @html_coder.encode(decoded_string, :named)
|
69
69
|
string_to_append = if encoded_string.bytesize > remaining_length
|
70
70
|
# This is the line which prevents HTML entities getting truncated - treat them as a single char
|
71
|
-
str =
|
71
|
+
str = truncate_string(decoded_string)
|
72
72
|
str << tail if remaining_length - str.bytesize >= tail.bytesize
|
73
73
|
str
|
74
74
|
else
|
@@ -170,10 +170,18 @@ class TruncatedSaxDocument < Nokogiri::XML::SAX::Document
|
|
170
170
|
@estimated_length >= max_length
|
171
171
|
end
|
172
172
|
|
173
|
-
def truncate_string(
|
173
|
+
def truncate_string(decoded_string)
|
174
174
|
@truncated = true
|
175
175
|
truncate_length = remaining_length - tail.bytesize
|
176
|
-
|
176
|
+
truncated_string = ''
|
177
|
+
decoded_string.split('').each do |char|
|
178
|
+
encoded_char = @html_coder.encode(char)
|
179
|
+
break if encoded_char.bytesize > truncate_length
|
180
|
+
|
181
|
+
truncated_string += encoded_char
|
182
|
+
truncate_length -= encoded_char.bytesize
|
183
|
+
end
|
184
|
+
truncated_string.scrub('')
|
177
185
|
end
|
178
186
|
|
179
187
|
def overridden_tag_length(tag_name, rendered_tag_with_attributes)
|
data/lib/abbreviato/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abbreviato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jorge Manrubia
|
@@ -254,8 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
254
254
|
- !ruby/object:Gem::Version
|
255
255
|
version: '0'
|
256
256
|
requirements: []
|
257
|
-
|
258
|
-
rubygems_version: 2.4.5.5
|
257
|
+
rubygems_version: 3.0.2
|
259
258
|
signing_key:
|
260
259
|
specification_version: 4
|
261
260
|
summary: A tool for efficiently truncating HTML strings to a specific bytesize
|