html_truncator 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/html_truncator.rb +7 -2
- metadata +8 -7
data/lib/html_truncator.rb
CHANGED
@@ -17,9 +17,10 @@ class HTML_Truncator
|
|
17
17
|
end
|
18
18
|
|
19
19
|
class <<self
|
20
|
-
attr_accessor :ellipsable_tags
|
20
|
+
attr_accessor :ellipsable_tags, :self_closing_tags
|
21
21
|
end
|
22
22
|
self.ellipsable_tags = Set.new(%w(p ol ul li div header article nav section footer aside dd dt dl))
|
23
|
+
self.self_closing_tags = Set.new(%w(br hr img))
|
23
24
|
end
|
24
25
|
|
25
26
|
class Nokogiri::HTML::DocumentFragment
|
@@ -33,7 +34,7 @@ class Nokogiri::XML::Node
|
|
33
34
|
return ["", 1, opts] if max == 0 && !ellipsable?
|
34
35
|
inner, remaining, opts = inner_truncate(max, opts)
|
35
36
|
if inner.empty?
|
36
|
-
return [
|
37
|
+
return [self_closing? ? to_html : "", max - remaining, opts]
|
37
38
|
end
|
38
39
|
children.remove
|
39
40
|
add_child Nokogiri::HTML::DocumentFragment.parse(inner)
|
@@ -60,6 +61,10 @@ class Nokogiri::XML::Node
|
|
60
61
|
def ellipsable?
|
61
62
|
HTML_Truncator.ellipsable_tags.include? name
|
62
63
|
end
|
64
|
+
|
65
|
+
def self_closing?
|
66
|
+
HTML_Truncator.self_closing_tags.include? name
|
67
|
+
end
|
63
68
|
end
|
64
69
|
|
65
70
|
class Nokogiri::XML::Text
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html_truncator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-12-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
16
|
-
requirement: &
|
16
|
+
requirement: &79813490 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '1.4'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *79813490
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &79813250 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '2.4'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *79813250
|
36
36
|
description: Wants to truncate an HTML string properly? This gem is for you.
|
37
37
|
email: bmichel@menfin.info
|
38
38
|
executables: []
|
@@ -65,8 +65,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
65
|
version: '0'
|
66
66
|
requirements: []
|
67
67
|
rubyforge_project:
|
68
|
-
rubygems_version: 1.8.
|
68
|
+
rubygems_version: 1.8.12
|
69
69
|
signing_key:
|
70
70
|
specification_version: 3
|
71
71
|
summary: Wants to truncate an HTML string properly? This gem is for you.
|
72
72
|
test_files: []
|
73
|
+
has_rdoc:
|