Skip to content

Instantly share code, notes, and snippets.

@danielcooper
Created July 29, 2012 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielcooper/3202515 to your computer and use it in GitHub Desktop.
Save danielcooper/3202515 to your computer and use it in GitHub Desktop.
#{{ some_text | truncate: 20, '' }}
def truncate(input, length = 50, truncate_string = "...")
if input.nil? then return end
l = length.to_i - truncate_string.length
l = 0 if l < 0
input.length > length.to_i ? input[0...l] + truncate_string : input
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment