refinerycms 0.9.5.10 → 0.9.5.11
Sign up to get free protection for your applications and to get access to all the features.
@@ -25,53 +25,50 @@ module Refinery::HtmlTruncationHelper
|
|
25
25
|
|
26
26
|
# Like the Rails _truncate_ helper but doesn't break HTML tags, entities, and optionally. words.
|
27
27
|
def truncate(text, *args)
|
28
|
+
return super unless args.include?(:preserve_html_tags)
|
28
29
|
return if text.nil?
|
30
|
+
|
29
31
|
options = args.extract_options!
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
max_length = options[:length] || 30
|
34
|
-
omission = options[:omission] || "..."
|
35
|
-
# use :link => link_to('more', post_path), or something to that effect
|
36
|
-
|
37
|
-
doc = Hpricot(text.to_s)
|
38
|
-
omission_length = Hpricot(omission).inner_text.mb_chars.length
|
39
|
-
content_length = doc.inner_text.mb_chars.length
|
40
|
-
actual_length = max_length - omission_length
|
32
|
+
max_length = options[:length] || 30
|
33
|
+
omission = options[:omission] || "..."
|
34
|
+
# use :link => link_to('more', post_path), or something to that effect
|
41
35
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
word_length = actual_length - (truncated_doc.inner_html.mb_chars.length - truncated_doc.inner_html.rindex(' '))
|
47
|
-
truncated_doc = doc.truncate(word_length)
|
48
|
-
end
|
36
|
+
doc = Hpricot(text.to_s)
|
37
|
+
omission_length = Hpricot(omission).inner_text.mb_chars.length
|
38
|
+
content_length = doc.inner_text.mb_chars.length
|
39
|
+
actual_length = max_length - omission_length
|
49
40
|
|
50
|
-
|
41
|
+
if content_length > max_length
|
42
|
+
truncated_doc = doc.truncate(actual_length)
|
43
|
+
|
44
|
+
if (options[:preserve_full_words] || false)
|
45
|
+
word_length = actual_length - (truncated_doc.inner_html.mb_chars.length - truncated_doc.inner_html.rindex(' '))
|
46
|
+
truncated_doc = doc.truncate(word_length)
|
47
|
+
end
|
48
|
+
|
49
|
+
last_child = truncated_doc.children.last
|
50
|
+
if last_child.inner_html.nil?
|
51
|
+
truncated_doc.inner_html + omission + options[:link] if options[:link]
|
52
|
+
else
|
53
|
+
last_child.inner_html = last_child.inner_html.gsub(/\W.[^\s]+$/, "") + omission
|
54
|
+
last_child.inner_html += options[:link] if options[:link]
|
55
|
+
truncated_doc
|
56
|
+
end
|
57
|
+
else
|
58
|
+
if options[:link]
|
59
|
+
last_child = doc.children.last
|
51
60
|
if last_child.inner_html.nil?
|
52
|
-
|
61
|
+
doc.inner_html + options[:link]
|
53
62
|
else
|
54
|
-
last_child.inner_html = last_child.inner_html.gsub(/\W.[^\s]+$/, "") +
|
55
|
-
|
56
|
-
|
57
|
-
end
|
63
|
+
last_child.inner_html = last_child.inner_html.gsub(/\W.[^\s]+$/, "") + options[:link]
|
64
|
+
doc
|
65
|
+
end
|
58
66
|
else
|
59
|
-
|
60
|
-
last_child = doc.children.last
|
61
|
-
if last_child.inner_html.nil?
|
62
|
-
doc.inner_html + options[:link]
|
63
|
-
else
|
64
|
-
last_child.inner_html = last_child.inner_html.gsub(/\W.[^\s]+$/, "") + options[:link]
|
65
|
-
doc
|
66
|
-
end
|
67
|
-
else
|
68
|
-
text.to_s
|
69
|
-
end
|
67
|
+
text.to_s
|
70
68
|
end
|
71
69
|
end
|
72
70
|
end
|
73
|
-
|
74
|
-
|
71
|
+
|
75
72
|
end
|
76
73
|
|
77
74
|
module HpricotTruncator
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: refinerycms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.5.
|
4
|
+
version: 0.9.5.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Resolve Digital
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2009-11-
|
14
|
+
date: 2009-11-19 00:00:00 +13:00
|
15
15
|
default_executable: refinery
|
16
16
|
dependencies: []
|
17
17
|
|