Created
July 9, 2012 23:46
-
-
Save tylerlee/3079874 to your computer and use it in GitHub Desktop.
coffescript truncate
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
# Public: Truncates a piece of text | |
# | |
# content - the string to be truncated | |
# length - the length at which to cut the string | |
# omission - defaults to '...' | |
# | |
# | |
# Examples | |
# | |
# truncate(account.get('Title'), 30) | |
# | |
# Returns a String | |
exports.truncate = (content, length, omission = "...") -> | |
if ( content.length > length ) | |
@_htmlSafe(content.substr(0, length) + omission) | |
else | |
@_htmlSafe(content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment