Created
November 22, 2010 09:33
-
-
Save Epyon616/709741 to your computer and use it in GitHub Desktop.
a quick way of truncating text in Ruby
This file contains hidden or 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
def truncate_words(text, url, length = 120, end_string = "... <a href='#{url}' class='more'>read more <img src='/images/black/arrow_right_8x8.png' /></a>") | |
words = text.split() | |
words[0..(length-1)].join(' ') + (words.length > length ? end_string : '') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment