Module: PartialMenu::ViewHelpers
- Defined in:
- lib/partial_menu/view_helpers.rb
Overview
PartialMenu view helpers
This module serves for availability in ActionView templates. It also adds a new view helper: partial_menu
.
Instance Method Summary collapse
-
#partial_menu(type = 'main', options = {}) ⇒ Object
rubocop:disable Metrics/MethodLength == Using the helper If the helper is called without passing in the type, it will render the default menu using the default view partials.
Instance Method Details
#partial_menu(type = 'main', options = {}) ⇒ Object
rubocop:disable Metrics/MethodLength
== Using the helper
If the helper is called without passing in the type, it will render the default menu using the default view partials.
Example:
<%= partial_menu %>
… will result in menu.yaml
getting displayed using partials from app/views/partial_menu
:
<ul>
<li><a href="/">First item</a></li>
...
</ul>
Any options defined in the call will be send to render
as local variables
Example:
<%= partial_menu 'menu', {menu_id:'sidemenu'} %>
You can leave out menu type parameter:
Example:
<%= partial_menu {menu_id:'sidemenu'} %>
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/partial_menu/view_helpers.rb', line 40 def (type = 'main', = {}) unless (type.is_a? String) || (type.is_a? Hash) raise ::ArgumentError, "Expected a String or Hash, got #{type.class}" end unless .is_a? Hash raise ::ArgumentError, "Expected a Hash, got #{options.class}" end if type.is_a? Hash = type type = 'main' end [:menu] = PartialMenu::Menu.new( ( get_yaml_prefix(type, ) ), type ) .deep_symbolize_keys! render partial: "#{type}_menu/menu", locals: end |