public
Created

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7
#{{ 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.