This is a Ruby lib to create a tree of menus. Very nice. Really!
BTW this document is written with a certain portion of humor (insanity).
- Deeply nestable
- You can have menus and entries mixed on every level.
- Simple role based access control with permission inheritance that can be optionally switched of (see
rbac_spec.rb
for details.)
Before your dirty hands touch a single line of code be sure to run the tests by invoking
rspec
Otherwise we’ll find and punish you! Promised.
- First versions are about building a valid data structure needed to create menus.
- The data model will be enhanced with information to later support authorization and visibility decisions.
- Internationalization will also be prepared.
- Then the problem of rendering menus will be targeted. This might become a framework specific renderer and thus end up in a separate repository but is surely part of the big picture.
menu = VeryNiceMenu.build('Main Menu', :allowed_for => [:admin])
menu.submenu("Main Menu - Submenu 1") do |submenu|
submenu.entry("My Entry")
end
submenu = menu.submenus.first
entry = submenu.entries.first
menu.allowed_for?(:admin)
=> true
menu.allowed_for?(:everyone)
=> false
submenu.allowed_for?(:admin)
=> true
submenu.allowed_for?(:everyone)
=> false
entry.allowed_for?(:admin)
=> true
entry.allowed_for?(:everyone)
=> false