Module: Odania::TextHelper

Defined in:
lib/odania/text_helper.rb

Class Method Summary collapse

Class Method Details

.truncate_words(text, length = 30, end_string = '...') ⇒ Object

Returns a string that has a max of length words. Tags are stripped first



7
8
9
10
11
# File 'lib/odania/text_helper.rb', line 7

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