Class: Satis::Menus::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/satis/menus/item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, link: nil, label: nil, icon: nil, link_attributes: {}, active: nil, scope: [], level: nil, type: :item, &block) ⇒ Item

Returns a new instance of Item.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/satis/menus/item.rb', line 10

def initialize(id, link: nil, label: nil, icon: nil, link_attributes: {}, active: nil, scope: [], level: nil, type: :item, &block)
  @id = id
  @label = label
  @icon = icon
  @link = link
  @link_attributes = link_attributes
  @scope = scope
  @level = level
  @type = type
  @link_attributes = @link_attributes.merge(data: { action: 'click->satis-menu#toggle' }) if type == :toggle
  @menu = Menu.new(scope + ["#{id}_menu".to_sym], level: level + 1, &block) if block_given?
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



6
7
8
# File 'lib/satis/menus/item.rb', line 6

def app
  @app
end

#iconObject (readonly)

Returns the value of attribute icon.



6
7
8
# File 'lib/satis/menus/item.rb', line 6

def icon
  @icon
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/satis/menus/item.rb', line 6

def id
  @id
end

#levelObject (readonly)

Returns the value of attribute level.



6
7
8
# File 'lib/satis/menus/item.rb', line 6

def level
  @level
end

Returns the value of attribute link.



6
7
8
# File 'lib/satis/menus/item.rb', line 6

def link
  @link
end

Returns the value of attribute link_attributes.



6
7
8
# File 'lib/satis/menus/item.rb', line 6

def link_attributes
  @link_attributes
end

Returns the value of attribute menu.



6
7
8
# File 'lib/satis/menus/item.rb', line 6

def menu
  @menu
end

#scope=(value) ⇒ Object (writeonly)

Sets the attribute scope

Parameters:

  • value

    the value to set the attribute scope to.



8
9
10
# File 'lib/satis/menus/item.rb', line 8

def scope=(value)
  @scope = value
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/satis/menus/item.rb', line 6

def type
  @type
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/satis/menus/item.rb', line 29

def active?
  active
end

#labelObject



23
24
25
26
27
# File 'lib/satis/menus/item.rb', line 23

def label
  return @label if @label

  @label ||= I18n.t(id, scope: [:menu] + @scope)
end