content_truncate 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/content_truncate.rb +1 -1
- data/lib/content_truncate/version.rb +1 -1
- data/test/content_truncate_test.rb +5 -1
- metadata +1 -1
data/lib/content_truncate.rb
CHANGED
@@ -20,7 +20,7 @@ module ContentTruncate
|
|
20
20
|
while position && position <= limit_length
|
21
21
|
prev_index, position = position, self.index(sep, position+1)
|
22
22
|
end
|
23
|
-
return self[0
|
23
|
+
return self[0...(prev_index+sep.length)].strip
|
24
24
|
end
|
25
25
|
sep = separators.shift
|
26
26
|
end
|
@@ -5,7 +5,7 @@ require_relative '../lib/content_truncate'
|
|
5
5
|
class ContentTruncateTest < Test::Unit::TestCase
|
6
6
|
|
7
7
|
def mock_string
|
8
|
-
"Truncate a string down to \n x characters. <br/>
|
8
|
+
"Truncate a string down to \n x characters. <br/>Beware of truncating \n text that has HTML elements in it."
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_content_truncate_for_no_separator
|
@@ -23,4 +23,8 @@ class ContentTruncateTest < Test::Unit::TestCase
|
|
23
23
|
def test_content_truncate_for_missing_char
|
24
24
|
assert_equal "Truncate a string down to \n x characters. <br/>", mock_string.content_truncate(60, "。", "<br/>")
|
25
25
|
end
|
26
|
+
|
27
|
+
def test_content_truncate_for_include_sep
|
28
|
+
assert_equal "Truncate a string down to \n x characters. <br/>", mock_string.content_truncate(48, "。", "<br/>")
|
29
|
+
end
|
26
30
|
end
|