Class: Madmin::Menu::Item

Inherits:
Object
  • Object
show all
Includes:
Node
Defined in:
lib/madmin/menu.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Node

#add, #items

Constructor Details

#initialize(label:, url: nil, position: 99, parent: nil, **options) ⇒ Item

Returns a new instance of Item.



60
61
62
63
64
65
66
67
# File 'lib/madmin/menu.rb', line 60

def initialize(label:, url: nil, position: 99, parent: nil, **options)
  @label = label
  @url = url
  @position = position
  @parent = parent
  @if = options.delete(:if)
  @children = {}
end

Instance Attribute Details

#children ⇒ Object (readonly)

Returns the value of attribute children.



58
59
60
# File 'lib/madmin/menu.rb', line 58

def children
  @children
end

#label ⇒ Object (readonly)

Returns the value of attribute label.



58
59
60
# File 'lib/madmin/menu.rb', line 58

def label
  @label
end

#parent ⇒ Object (readonly)

Returns the value of attribute parent.



58
59
60
# File 'lib/madmin/menu.rb', line 58

def parent
  @parent
end

#position ⇒ Object (readonly)

Returns the value of attribute position.



58
59
60
# File 'lib/madmin/menu.rb', line 58

def position
  @position
end

#url ⇒ Object (readonly)

Returns the value of attribute url.



58
59
60
# File 'lib/madmin/menu.rb', line 58

def url
  @url
end

Instance Method Details

#human_label ⇒ Object



69
70
71
72
73
74
75
# File 'lib/madmin/menu.rb', line 69

def human_label
  @human_label ||= if label.is_a?(Symbol)
    I18n.t("activerecord.models.#{label}", count: 2, default: [:"madmin.navigation.#{label}", label.to_s.pluralize(I18n.locale).titleize])
  else
    label
  end
end