Created
June 1, 2009 10:18
-
-
Save jerome/121340 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module WordTruncateHelper | |
def word_truncate(text, *args) | |
options = args.extract_options! | |
unless args.empty? | |
options[:size] = args[0] || 75 | |
options[:omission] = args[1] || "..." | |
end | |
options.reverse_merge!(:size => 75, :omission => "...") | |
text.scan(/(\S+)(\s+)/)[0..options[:size]].flatten.join << options[:omission] if text | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment