Module: LibraryHelper

Included in:
Library::LibraryTags
Defined in:
app/helpers/library_helper.rb

Instance Method Summary collapse

Instance Method Details

#clean_html(text) ⇒ Object



5
6
7
# File 'app/helpers/library_helper.rb', line 5

def clean_html(text)
  Sanitize.clean(text, Sanitize::Config::RELAXED)
end

#strip_html(text) ⇒ Object



9
10
11
# File 'app/helpers/library_helper.rb', line 9

def strip_html(text)
  Sanitize.clean(text)
end

#truncate_words(text = '', options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'app/helpers/library_helper.rb', line 13

def truncate_words(text='', options={})
  return '' if text.blank?
  ellipsis = options[:ellipsis] || '…'
  limit = (options[:limit] || 64).to_i
  text = strip_html(text) if options[:strip]
  words = text.split
  ellipsis = '' unless words.size > limit
  words[0..(limit-1)].join(" ") + ellipsis
end