Module: TaggableHelper

Included in:
Radius::LibraryTags, Radius::TaggableTags
Defined in:
app/helpers/taggable_helper.rb

Instance Method Summary collapse

Instance Method Details

#available_pointer_pagesObject



22
23
24
25
26
27
# File 'app/helpers/taggable_helper.rb', line 22

def available_pointer_pages()
  root = Page.respond_to?(:homepage) ? Page.homepage : Page.find_by_parent_id(nil)
  options = pointer_option_branch(root)
  options.unshift ['<none>', nil]
  options
end

#clean_html(text) ⇒ Object



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

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

#pointer_option_branch(page, depth = 0) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/taggable_helper.rb', line 29

def pointer_option_branch(page, depth=0)
  options = []
  unless page.virtual? || page.sheet? || page.has_pointer?
    options << ["#{". " * depth}#{h(page.title)}", page.id]
    page.children.each do |child|
      options += pointer_option_branch(child, depth + 1)
    end
  end
  options
end

#scrub_html(text) ⇒ Object



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

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

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



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

def truncate_words(text='', options={})
  return '' if text.blank?
  options.reverse_merge!(:length => 30, :omission => '&hellip;')
  words = text.split
  length = options[:length].to_i
  options[:omission] = '' unless words.size > length
  words[0..(length-1)].join(" ") + options[:omission]
end