Module: Bh::NavHelper
- Includes:
- BaseHelper
- Defined in:
- lib/bh/helpers/nav_helper.rb
Overview
Provides methods to include navs.
Instance Method Summary collapse
-
#link_to(*args, &block) ⇒ Object
Overrides ActionView
link_to
to be able to surround the link in a ‘<li>’ item in case the link is inside of a nav. -
#nav(options = {}) { ... } ⇒ String
Returns an HTML block tag that follows the Bootstrap documentation on how to display navs.
Instance Method Details
#link_to(*args, &block) ⇒ Object
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 ? content_tag(:li, link, (*args)) : link end |
#nav(options = {}) { ... } ⇒ String
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*.
31 32 33 34 35 |
# File 'lib/bh/helpers/nav_helper.rb', line 31 def nav( = {}, &block) @nav_link = true nav = content_tag :ul, role: 'tablist', class: nav_class(), &block nav.tap{ @nav_link = false } end |