Module: Caboose::PagesHelper

Defined in:
app/helpers/caboose/pages_helper.rb

Instance Method Summary collapse

Instance Method Details

#ab_testing_analytics_codeObject


31
32
33
# File 'app/helpers/caboose/pages_helper.rb', line 31

def ab_testing_analytics_code
  return "var _gaq = _gaq || [];\n_gaq.push(['_setCustomVar', 1, 'caboose_ab_variants', #{Caboose.json(AbTesting.analytics_string)}]);"            
end

50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/helpers/caboose/pages_helper.rb', line 50

def nav_link(p, css_class = nil, style = nil) 
  str = "<a "
  str << "class='#{css_class}' " if css_class
  str << "style='#{style}' " if style
  if p.redirect_url && p.redirect_url.strip.length > 0
    str << "href='#{p.redirect_url}' target='_blank'"
  else
    str << "href='/#{p.uri}'"
  end
  str << ">#{p.title}</a>"
  return str
end

#pages_list(page) ⇒ Object


3
4
5
6
7
8
9
# File 'app/helpers/caboose/pages_helper.rb', line 3

def pages_list(page)
  is_admin = @logged_in_user && @logged_in_user.is_allowed('all', 'all')
  str = "<ul>"
  str << pages_list_helper(page, is_admin, true)      
  str << "</ul>"
  return str
end

#pages_list_helper(page, is_admin, is_top) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/caboose/pages_helper.rb', line 11

def pages_list_helper(page, is_admin, is_top)
  if is_admin || ((@logged_in_user && Page.permissible_actions(@logged_in_user, page.id).include?('edit')) ? true : false)
    str = "<li><a class='content' href='/admin/pages/#{page.id}/content'>#{page.title}</a><a class='icon3-settings' href='/admin/pages/#{page.id}'>Settings</a>"
    str << "<a title='Hide Page' href='#' data-page='#{page.id}' class='pub icon3-visible'>Hide Page</a>" if !page.hide && !is_top
    str << "<a title='Show Page' href='#' data-page='#{page.id}' class='pub icon3-hidden'>Show Page</a>" if page.hide
  else
    str = "<li class='disabled'><span class='content'>#{page.title}</span>"
  end
  pchildren = page.children.select([:id, :title, :hide])
  if pchildren && pchildren.count > 0
    str << "<ul>"
    pchildren.each do |p|
      str << pages_list_helper(p, is_admin, false)
    end
    str << "</ul>"
  end
  str << "</li>"
  return str
end

#pages_roles_with_prefix(top_roles, prefix) ⇒ Object


35
36
37
38
39
40
# File 'app/helpers/caboose/pages_helper.rb', line 35

def pages_roles_with_prefix(top_roles, prefix)
  arr = []
  top_roles.each do |r|        
    arr = pages_roles_with_prefix_helper(arr, r, prefix, "")
  end
end

#pages_roles_with_prefix_helper(arr, role, prefix, str) ⇒ Object


42
43
44
45
46
47
48
# File 'app/helpers/caboose/pages_helper.rb', line 42

def pages_roles_with_prefix_helper(arr, role, prefix, str)      
  arr << "#{str}#{role.name}"
  role.children.each do |r|
    arr = pages_roles_with_prefix_helper(arr, r, prefix, "#{prefix}#{str}")
  end
  return arr
end