Module: SiteMenusHelper

Defined in:
app/helpers/site_menus_helper.rb

Overview

:nodoc:

Instance Method Summary (collapse)

Instance Method Details

- (Object) build_submenu_box(menu, &block)



60
61
62
63
64
65
66
67
68
# File 'app/helpers/site_menus_helper.rb', line 60

def build_submenu_box(menu,&block)
  menu = menu.first if menu.is_a?(Mongoid::Criteria)
  if menu && menu.target && (menu.role_needed||0) <= current_role
    yield( submenu_header(menu) ) +
    menu.children.map { |child|
      raw( build_submenu_box(child,&block) )
    }.join("") + close_submenu(menu)
  end
end

- (Object) close_submenu(menu)



106
107
108
# File 'app/helpers/site_menus_helper.rb', line 106

def close_submenu(menu)
  menu.children.any? ? "</ul>" : ""
end

- (Object) current_root(view_context)



87
88
89
90
91
92
93
94
# File 'app/helpers/site_menus_helper.rb', line 87

def current_root(view_context)
  SiteMenu.roots.each do |root|
    if root.current_child?(view_context)
      Rails.logger.info("******** CURRENT ROOT = #{root.target} ****** ")
      return root
    end
  end
end

- (Boolean) current_root_menu_include?(menu)

Is path included in any current_root’s path?

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/site_menus_helper.rb', line 19

def current_root_menu_include?(menu)
  begin
    if current_root(self)
      current_root(self).traverse(:depth_first) do |menu_item|
        @current_root = menu_item if menu && menu_item && current_page?(menu_item.target) && menu.target[0] != '#'
      end
    end
  rescue => e
    Rails.logger.info("** NO ROOT PATH FOUND #{e.inspect}")
    return false
  end
  @current_root != nil
end

- (Boolean) current_root_menu_include_path?(path)

Returns:

  • (Boolean)


45
46
47
48
49
# File 'app/helpers/site_menus_helper.rb', line 45

def current_root_menu_include_path?(path)
  return true if current_page?(path) && path[0] != '#'
  search_item = SiteMenu.where(:target => path).first
  current_root_menu_include?(search_item)
end

- (Boolean) current_root_path_include?(menu)

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
42
43
# File 'app/helpers/site_menus_helper.rb', line 33

def current_root_path_include?(menu)
  path_menus = []
  menu.traverse { |m|
    path_menus << m if current_page?(m.target) && menu && menu.target && menu.target[0] != '#'
  }
  menu.ancestors.each do |anc|
    path_menus << anc if current_page?(anc.target) && menu.target[0] != '#'
  end
  path_menus.compact!
  path_menus.any?
end

if the link is a link to the current-page display it with a different css-class to inform the user about ‘here you are’.



53
54
55
56
57
58
# File 'app/helpers/site_menus_helper.rb', line 53

def menu_link_to(name,path,options={})
  style = "hmenu"
  style = "hmenu_current" if current_page?(path)
  options.merge!( { :class => style } )
  link_to( name, path, options )
end

- (Object) root_menus_including(menu)

Detect the root-menu-items including ‘path’



8
9
10
11
12
13
14
# File 'app/helpers/site_menus_helper.rb', line 8

def root_menus_including(menu)
  root_menus = []
  SiteMenu.roots.each do |root|
    root_menus << root if root.current_child?(self)
  end
  root_menus.flatten.uniq.compact
end


110
111
112
113
114
115
116
# File 'app/helpers/site_menus_helper.rb', line 110

def site_menu_manage_buttons(menu)
  ("<span style='height: 10px; vertical-align: middle;'>" +
  ui_button( 'edit',t(:edit), edit_site_menu_path(menu)) + sc(:nbsp) +
  ui_button( 'delete',t(:delete), menu, :method => :delete, :confirm => t(:are_you_sure)) + sc(:nbsp) +
  ui_button( 'add', t(:add_submenu_item), new_site_menu_path(:parent => menu.to_param)) +
  "</span>").html_safe
end


96
97
98
99
100
101
102
103
104
# File 'app/helpers/site_menus_helper.rb', line 96

def submenu_header(menu)
  if current_page?(menu.target)
    header = "<div class='hmenu_current'>" + link_to(menu.name,menu.target) + "</div>"
  else
    header = link_to(menu.name,menu.target)
  end
  header += raw("<ul>") if menu.children.any?
  header
end


70
71
72
73
74
75
76
77
# File 'app/helpers/site_menus_helper.rb', line 70

def submenu_margin_left
  margin = 0
  main_menu(false) do |name,html|
    break  if current_root_menu_include_path?(html[/(.*) href=\"(.*)\" (.*)$/,2])
    margin += (strip_links( (html||name||' ') ).length-1)*1.38
  end
  margin.to_i
end


79
80
81
82
83
84
85
# File 'app/helpers/site_menus_helper.rb', line 79

def submenus(upto=4)
  rc=(0..upto).to_a.map { |level|
   level if content_for?("submenu_level_#{level}".to_sym)
  }.compact
  Rails.logger.info("==== SUBMENUS #{rc.inspect}")
  rc
end