74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'vendor/plugins/refinery/lib/refinery/html_truncation_helper.rb', line 74
def truncate(max_length)
return self if inner_text.mb_chars.length <= max_length
truncated_node = if self.is_a?(Hpricot::Doc)
self.dup
else
self.class.send(:new, self.name, self.attributes.respond_to?("map") ? self.attributes : nil)
end
truncated_node.children = []
each_child do |node|
remaining_length = max_length - truncated_node.inner_text.mb_chars.length
break if remaining_length <= 0
truncated_node.children << node.truncate(remaining_length)
end
truncated_node
end
|