Class: Decidim::MenuItem

Inherits:
Object
  • Object
show all
Defined in:
lib/decidim/menu_item.rb

Overview

This class handles all logic regarding menu items

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, url, identifier, options = {}) ⇒ MenuItem

Builds a new menu item

Parameters:

  • label (String, Symbol)

    A compulsory label for the menu item

  • url (String, Symbol)

    The URL this item will link to

  • options (Hash) (defaults to: {})

    The options for the menu item



14
15
16
17
18
19
20
21
22
23
# File 'lib/decidim/menu_item.rb', line 14

def initialize(label, url, identifier, options = {})
  @label = label
  @url = url
  @identifier = identifier
  @position = options[:position] || Float::INFINITY
  @if = options[:if]
  @active = options[:active]
  @icon_name = options[:icon_name]
  @submenu = options[:submenu]
end

Instance Attribute Details

#activeObject (readonly)

Returns the value of attribute active.



26
27
28
# File 'lib/decidim/menu_item.rb', line 26

def active
  @active
end

#icon_nameObject (readonly)

Returns the value of attribute icon_name.



26
27
28
# File 'lib/decidim/menu_item.rb', line 26

def icon_name
  @icon_name
end

#identifierObject (readonly)

Returns the value of attribute identifier.



26
27
28
# File 'lib/decidim/menu_item.rb', line 26

def identifier
  @identifier
end

#labelObject (readonly)

Returns the value of attribute label.



26
27
28
# File 'lib/decidim/menu_item.rb', line 26

def label
  @label
end

#positionObject

Returns the value of attribute position.



25
26
27
# File 'lib/decidim/menu_item.rb', line 25

def position
  @position
end

Returns the value of attribute submenu.



26
27
28
# File 'lib/decidim/menu_item.rb', line 26

def submenu
  @submenu
end

#urlObject (readonly)

Returns the value of attribute url.



26
27
28
# File 'lib/decidim/menu_item.rb', line 26

def url
  @url
end

Instance Method Details

#visible?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
# File 'lib/decidim/menu_item.rb', line 28

def visible?
  return true if @if.nil? || @if

  false
end