Module: Bh::NavHelper

Includes:
BaseHelper
Defined in:
lib/bh/helpers/nav_helper.rb

Overview

Provides methods to include navs.

Instance Method Summary collapse

Instance Method Details

Overrides ActionView link_to to be able to surround the link in a ‘<li>’ item in case the link is inside of a nav.



39
40
41
42
# File 'lib/bh/helpers/nav_helper.rb', line 39

def link_to(*args, &block)
  link = super *args, &block
  @nav_link ? (:li, link, nav_list_item_options(*args)) : link
end

Returns an HTML block tag that follows the Bootstrap documentation on how to display navs.

The skeleton of the nav is an unordered list; its content is passed as a block as a list of navigation items. Since the most common use for a nav is to display a menu of links, a variable is set inside the block so that every call to link_to generates a link *surrounded by a list item*.

Examples:

An justified nav with two links.

nav layout: :justified do
  link_to 'Home', '/'
  link_to 'Profile', '/profile'
end

Parameters:

  • options (Hash) (defaults to: {})

    the display options for the nav.

Options Hash (options):

  • :as (#to_s) — default: 'tabs'

    the style to use for the nav. Valid values are: :tabs and :pills.

  • :layout (#to_s) — default: nil

    if set, the layout of the nav. Valid values are: :justified and :stacked.

Yields:

  • block the content of the nav

Returns:

  • (String)

    an HTML block tag for a nav.

See Also:



31
32
33
34
35
# File 'lib/bh/helpers/nav_helper.rb', line 31

def nav(options = {}, &block)
  @nav_link = true
  nav =  :ul, role: 'tablist', class: nav_class(options), &block
  nav.tap{ @nav_link = false }
end