Generating hierarchical menus in Rails should utilize Rails' built-in partial views instead of using some kind on HTML code generators. This gem just do that.
Usage
After installing the gem you can generate the views and the config file to create your own menus, even more than one can be generated by using name prefixes.
rails generate partial_menu:yaml
This will generate an example menu description yaml file in config/main_menu.yaml
You can have multiple menu definitiions in an app. For this you can use the --type
parameter to set the name of the file
rails generate partial_menu:yaml -t side
This will create config/side_menu.yaml
You can define your menu structure in the generated yaml file:
---
menu:
- first_item:
title: "First item"
uri: root
icon: test
- second_item: separator
- third_item:
icontype: glyph
menu:
- first_submenu: link
- second_submenu:
title: menu.second_submenu.title
uri: second
Customizing views:
rails generate partial_menu:views -d side
This will create:
app/views/side_menu/_menu.html.erb
-- menu root templateapp/views/side_menu/_item.html.erb
-- menu items templateapp/views/side_menu/_separator.html.erb
-- separator templateapp/views/side_menu/_submenu_item.html.erb
-- submenu root templateapp/views/side_menu/_item.html.erb
-- submenu items template
Installation
Add this line to your application's Gemfile:
gem 'partial_menu'
And then execute:
$ bundle
Or install it yourself as:
$ gem install partial_menu
License
The gem is available as open source under the terms of the MIT License.