html_truncator 0.4.1 → 0.4.2

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
  SHA1:
3
- metadata.gz: c5d32333126a13d95485d8099cc9b0c428888524
4
- data.tar.gz: 10bf2180590da61247191344cb28f030f0da0f8b
3
+ metadata.gz: 59f26ce17968dfae9237e9bd066c1f2c5fa82591
4
+ data.tar.gz: f55ce8ae96a87392d408cb55ddc5d70590d782c3
5
5
  SHA512:
6
- metadata.gz: 6d53be5769d4a135570d97163cb362c307a7933ce8e456beafd7f1536a8f60a667fff3c130a4cd6fcfe9b7966e80af7c12effc1fbb1539181656dfae2e08395f
7
- data.tar.gz: 184db5d95e09c142c11ea64687c062ca654489f15a896c125caec0f4357034fc2f63531ebe4bf67e43b7e37f725173fe5629f22c1f6e244fc2923cccad0d742a
6
+ metadata.gz: 2685ebd8e24a34c8a4885f63ed78f2715f557b0c3eb43f8c8fc8f987823a692571d0b10b01ae911af1cd11324359bc19742844ffc54f813bd3dc51eea2a18352
7
+ data.tar.gz: e7d8e184e074a7357dd80c819972b397e66adbfbba9d081939ef80cce06ec84a7eda138cb5ae3448ce7aeaf80cca760f6153d8501f6ae9191757b94165bec5f7
data/README.md CHANGED
@@ -119,6 +119,23 @@ HTML_Truncator.truncate("<p>Lorem ipsum dolor sit amet.</p>", 3).html_truncated?
119
119
  # => true
120
120
  ```
121
121
 
122
+ You can ignore images in the text by overriding the `self_closing_tags` attribute:
123
+
124
+ ```ruby
125
+ HTML_Truncator.self_closing_tags.delete "img"
126
+ HTML_Truncator.truncate("<p>Lorem ipsum <img src='...'>dolor sit amet.</p>", 3)
127
+ # => "<p>Lorem ipsum dolor…</p>"
128
+ ```
129
+
130
+ If you already have parsed an HTML document with Nokogiri, you can use it
131
+ directly to truncate:
132
+
133
+ ```ruby
134
+ document = Nokogiri::HTML::DocumentFragment.parse(text)
135
+ # Doing something with this document
136
+ options = HTML_Truncator::DEFAULT_OPTIONS.merge(length_in_char: true)
137
+ document.truncate(12, options)
138
+ ```
122
139
 
123
140
  Alternatives
124
141
  ------------
@@ -75,7 +75,7 @@ class Nokogiri::XML::Text
75
75
  if opts[:length_in_chars]
76
76
  count = content.length
77
77
  return [to_xhtml, count, opts] if count <= max && max > 0
78
- words = content.scan(/\s*\S+/)
78
+ words = content.scan(/[[:space:]]*[[:graph:]]+/)
79
79
  if words.size > 1
80
80
  words.inject('') do |string, word|
81
81
  if string.length + word.length > max
@@ -90,7 +90,7 @@ class Nokogiri::XML::Text
90
90
  txt.content = content.slice(0, max)
91
91
  [txt.to_xhtml, count, opts]
92
92
  else
93
- words = to_xhtml.scan(/\s*\S+/)
93
+ words = to_xhtml.scan(/[[:space:]]*[[:graph:]]+/)
94
94
  count = words.length
95
95
  return [to_xhtml, count, opts] if count <= max && max > 0
96
96
  [words.slice(0, max).join, count, opts]
@@ -1,3 +1,3 @@
1
1
  class HTML_Truncator
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_truncator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Michel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-12 00:00:00.000000000 Z
11
+ date: 2017-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  version: '0'
70
70
  requirements: []
71
71
  rubyforge_project:
72
- rubygems_version: 2.4.5
72
+ rubygems_version: 2.5.2
73
73
  signing_key:
74
74
  specification_version: 4
75
75
  summary: Wants to truncate an HTML string properly? This gem is for you.