Skip to content
This repository has been archived by the owner on Oct 26, 2021. It is now read-only.

Commit

Permalink
String#chars is deprecated. Using String#mb_chars, with a workaround …
Browse files Browse the repository at this point in the history
…for older versions.
  • Loading branch information
danielmorrison committed Feb 4, 2009
1 parent a58d913 commit bace9a4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/awesomeness/core_ext/string.rb
Expand Up @@ -6,4 +6,8 @@ class String
def widont
self.gsub(/([^\s])\s+([^\s]+)(\s*)$/, '\1 \2\3')
end

def mb_chars
chars
end unless ''.respond_to?(:mb_chars)
end
6 changes: 3 additions & 3 deletions lib/awesomeness/text_helper.rb
Expand Up @@ -9,12 +9,12 @@ module TextHelper
# though it will not be the exact length.
def awesome_truncate(text, length = 30, truncate_string = "…")
return if text.nil?
l = length - truncate_string.chars.length
text.chars.length > length ? text[/\A.{#{l}}\w*\;?/m][/.*[\w\;]/m] + truncate_string : text
l = length - truncate_string.mb_chars.length
text.mb_chars.length > length ? text[/\A.{#{l}}\w*\;?/m][/.*[\w\;]/m] + truncate_string : text
end

def truncate_with_title(text, length = 30, truncate_string = "…")
if text.chars.length > length
if text.mb_chars.length > length
content_tag :span, truncate(text), :title => text
else
text
Expand Down

0 comments on commit bace9a4

Please sign in to comment.