Class: EacRailsUtils::Menus::Group

Inherits:
Node
  • Object
show all
Defined in:
lib/eac_rails_utils/menus/group.rb

Constant Summary collapse

DEFAULT_PATH_FIRST_NODE =
:main_app
SELF_LABEL_TRANSLATE_KEY_PART =
'__self'

Constants inherited from Node

Node::LABEL_TRANSLATE_KEY_PREFIX, Node::TRANSLATE_KEY_SEPARATOR

Instance Attribute Summary

Attributes inherited from Node

#custom_label

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#auto_label, #label, #parent_label_translate_key

Class Method Details

.sanitize_key(key) ⇒ Symbol

Parameters:

  • key (Object)

Returns:

  • (Symbol)


13
14
15
# File 'lib/eac_rails_utils/menus/group.rb', line 13

def sanitize_key(key)
  key.to_sym
end

Instance Method Details

#action(*path) ⇒ EacRailsUtils::Menus::Action

Parameters:

  • path (Array<Symbol>)

Returns:



29
30
31
32
# File 'lib/eac_rails_utils/menus/group.rb', line 29

def action(*path)
  child_action = ::EacRailsUtils::Menus::Action.new(path, self)
  actions[child_action.key] ||= child_action
end

#childrenArray<EacRailsUtils::Menus::Node>

Returns:



35
36
37
# File 'lib/eac_rails_utils/menus/group.rb', line 35

def children
  (groups.values + actions.values).sort
end

#group(group_key, path_first_node = nil) ⇒ EacRailsUtils::Menus::Group



40
41
42
43
# File 'lib/eac_rails_utils/menus/group.rb', line 40

def group(group_key, path_first_node = nil)
  child_group = self.class.new(group_key, self, path_first_node)
  groups[child_group.key] ||= child_group
end

#label_translate_keyString

Returns:

  • (String)


46
47
48
# File 'lib/eac_rails_utils/menus/group.rb', line 46

def label_translate_key
  [super, SELF_LABEL_TRANSLATE_KEY_PART].join(TRANSLATE_KEY_SEPARATOR)
end

#to_dropdown_menu_entries(view) ⇒ Hash

Parameters:

  • view (ActionView::Base)

Returns:

  • (Hash)


52
53
54
55
56
# File 'lib/eac_rails_utils/menus/group.rb', line 52

def to_dropdown_menu_entries(view)
  children.inject({}) do |a, e|
    a.merge(e.label => e.to_dropdown_menu_entries(view))
  end
end

#within {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



58
59
60
# File 'lib/eac_rails_utils/menus/group.rb', line 58

def within
  yield(self)
end