Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # drop this in a ruby file in my_rails_app/config/initializers
- # restart your rails and app you're good to go!
- class String
- # remove middle from strings exceeding max length.
- def ellipsize(options={})
- max = options[:max] || 40
- delimiter = options[:delimiter] || "..."
- return self if self.size <= max
- remainder = max - delimiter.size
- offset = remainder / 2
- (self[0,offset + (remainder.odd? ? 1 : 0)].to_s + delimiter + self[-offset,offset].to_s)[0,max].to_s
- end unless defined? ellipsize
- end
Add Comment
Please, Sign In to add comment