Class: SiteMenu

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Tree, Mongoid::Tree::Traversal
Defined in:
app/models/site_menu.rb

Overview

SiteMenu

is a Mongoid::Tree of menu-entries

Fields:

  name:
    [String] The Label of the menu-item
  target:
    [String] The URL to call on click
  position:
    [Integer] The position in menus. (default order)
  role_needed:
    [Integer] The user (at least) must have this role.

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) current_child?(view_context)

Returns:

  • (Boolean)


29
30
31
32
33
34
35
# File 'app/models/site_menu.rb', line 29

def current_child?(view_context)
  return true if view_context.current_page?(self.target)
  self.children.each do |child|
    return true if child.current_child?(view_context)
  end
  false
end

- (Boolean) has_child_path?(path)

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
46
# File 'app/models/site_menu.rb', line 37

def has_child_path?(path)
  child = nil
  self.traverse do |t|
    if t.target == path
      child = t
      break
    end
  end
  !child.nil?
end