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.

Using the helper without arguments

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'} %>

Instance Method Summary collapse

Instance Method Details

#current_menu?(path) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/partial_menu/view_helpers.rb', line 48

def current_menu?(path)
  request.path == URI(path).path unless path.blank?
end

#partial_menu(type = 'main', options = {}) ⇒ Object

:nodoc:



38
39
40
41
42
43
44
45
46
# File 'lib/partial_menu/view_helpers.rb', line 38

def partial_menu(type = 'main', options = {}) #:nodoc:
  if type.is_a? Hash
    options = type
    type = 'main'
  end
  options[:menu] = PartialMenu::Menu.new(load_menu_from_yaml(type))
  options.symbolize_keys!
  render partial: "#{type}_menu/menu", locals: options
end