Created
January 21, 2010 03:04
-
-
Save timnovinger/282544 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
# TRUNCATE BY WORD COUNT | |
def snippet (text, wordcount, separator="...") | |
text.split[0..(wordcount-1)].join(" ") + (text.split.size > wordcount ? separator : "") | |
end | |
## EXAMPLE USAGE | |
<%= snippet(p.content, 20, "... <a href='/notes/#{p.slug}'>read more</a>") %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment