Sha256: b3f909126291c9d1bbd86caad41af1a8b74b8f21b94937aeb220b7878fe1a333
Contents?: true
Size: 421 Bytes
Versions: 8
Compression:
Stored size: 421 Bytes
Contents
require 'sanitize' module Odania module TextHelper class << self # Returns a string that has a max of length words. Tags are stripped first def truncate_words(text, length = 30, end_string = '...') return '' if text.blank? words = Sanitize.clean(text, Sanitize::Config::RESTRICTED).split() (words[0..(length-1)].join(' ') + (words.length > length ? end_string : '')).html_safe end end end end
Version data entries
8 entries across 8 versions & 1 rubygems