Class: Spree::BackendConfiguration::MenuItem

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

Overview

An item which should be drawn in the admin menu

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sections, icon, condition: nil, label: nil, partial: nil, url: nil, position: nil, match_path: nil) ⇒ MenuItem

Returns a new instance of MenuItem.

Parameters:

  • sections (Array<Symbol>)

    The sections which are contained within this admin menu section.

  • icon (String)

    The icon to draw for this menu item

  • condition (Proc) (defaults to: nil)

    A proc which returns true if this menu item should be drawn. If nil, it will be replaced with a proc which always returns true.

  • label (Symbol) (defaults to: nil)

    The translation key for a label to use for this menu item.

  • partial (String) (defaults to: nil)

    A partial to draw within this menu item for use in declaring a submenu

  • url (String) (defaults to: nil)

    A url where this link should send the user to

  • position (Integer) (defaults to: nil)

    The position in which the menu item should render nil will cause the item to render last

  • match_path (String, Regexp, callable) (defaults to: nil)

    (nil) If the #url to determine the active tab is ambigous you can pass a String, Regexp or callable to identify this menu item. The callable accepts a request object and returns a Boolean value.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/spree/backend_configuration/menu_item.rb', line 27

def initialize(
  sections,
  icon,
  condition: nil,
  label: nil,
  partial: nil,
  url: nil,
  position: nil,
  match_path: nil
)

  @condition = condition || -> { true }
  @sections = sections
  @icon = icon
  @label = label || sections.first
  @partial = partial
  @url = url
  @position = position
  @match_path = match_path
end

Instance Attribute Details

#conditionObject (readonly)

Returns the value of attribute condition.



7
8
9
# File 'lib/spree/backend_configuration/menu_item.rb', line 7

def condition
  @condition
end

#iconObject (readonly)

Returns the value of attribute icon.



7
8
9
# File 'lib/spree/backend_configuration/menu_item.rb', line 7

def icon
  @icon
end

#labelObject (readonly)

Returns the value of attribute label.



7
8
9
# File 'lib/spree/backend_configuration/menu_item.rb', line 7

def label
  @label
end

#match_pathObject (readonly)

Returns the value of attribute match_path.



7
8
9
# File 'lib/spree/backend_configuration/menu_item.rb', line 7

def match_path
  @match_path
end

#partialObject (readonly)

Returns the value of attribute partial.



7
8
9
# File 'lib/spree/backend_configuration/menu_item.rb', line 7

def partial
  @partial
end

#positionObject

Returns the value of attribute position.



9
10
11
# File 'lib/spree/backend_configuration/menu_item.rb', line 9

def position
  @position
end

#sectionsObject (readonly)

Returns the value of attribute sections.



7
8
9
# File 'lib/spree/backend_configuration/menu_item.rb', line 7

def sections
  @sections
end

Instance Method Details

#urlObject



48
49
50
51
52
53
54
# File 'lib/spree/backend_configuration/menu_item.rb', line 48

def url
  if @url.respond_to?(:call)
    @url.call
  else
    @url
  end
end