Skip to content

Instantly share code, notes, and snippets.

@tylerlee
Created July 9, 2012 23:46
Show Gist options
  • Save tylerlee/3079874 to your computer and use it in GitHub Desktop.
Save tylerlee/3079874 to your computer and use it in GitHub Desktop.
coffescript truncate
# 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