Class: EasyAdmin::SidebarBuilder
- Inherits:
-
Object
- Object
- EasyAdmin::SidebarBuilder
- Defined in:
- lib/easy_admin/configuration.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
- #group(label, icon: nil, expanded: false, &block) ⇒ Object
-
#initialize ⇒ SidebarBuilder
constructor
A new instance of SidebarBuilder.
- #item(label, path = nil, icon: nil, active: false, resource: nil, &block) ⇒ Object
Constructor Details
#initialize ⇒ SidebarBuilder
Returns a new instance of SidebarBuilder.
22 23 24 25 |
# File 'lib/easy_admin/configuration.rb', line 22 def initialize @items = [] @current_group = nil end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
20 21 22 |
# File 'lib/easy_admin/configuration.rb', line 20 def items @items end |
Instance Method Details
#group(label, icon: nil, expanded: false, &block) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/easy_admin/configuration.rb', line 53 def group(label, icon: nil, expanded: false, &block) group_config = { label: label, icon: icon, expanded: , children: [] } if block_given? old_items = @items @items = [] instance_eval(&block) group_config[:children] = @items group_config[:expanded] = || @items.any? { |child| child[:active] } @items = old_items end @items << group_config end |
#item(label, path = nil, icon: nil, active: false, resource: nil, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/easy_admin/configuration.rb', line 27 def item(label, path = nil, icon: nil, active: false, resource: nil, &block) item_config = { label: label, path: path, icon: icon, active: active, resource: resource } if block_given? # This is a parent item with children old_items = @items @items = [] @current_group = item_config instance_eval(&block) item_config[:children] = @items item_config[:expanded] = item_config[:children].any? { |child| child[:active] } @items = old_items end @items << item_config end |