Module: Facades::Helpers::Navigation
- Included in:
- Facades::Helpers
- Defined in:
- lib/facades/helpers/navigation.rb
Defined Under Namespace
Classes: NavigationLink, Navigator
Instance Method Summary collapse
-
#nav(options = {}, &block) ⇒ Object
(also: #navigation)
Constructs a navigation list containing a variable number of list items and links.
-
#nav_link(text, href, options = {}) ⇒ Object
Similar to link_to, but adds the class ‘active’ if the link’s href is in an active state.
Instance Method Details
#nav(options = {}, &block) ⇒ Object Also known as:
Constructs a navigation list containing a variable number of list items and links.
9 10 11 |
# File 'lib/facades/helpers/navigation.rb', line 9 def nav( = {}, &block) Navigator.new(self, ).render(&block) end |
#nav_link(text, href, options = {}) ⇒ Object
Similar to link_to, but adds the class ‘active’ if the link’s href is in an active state. If the options :proc, or :matcher is passed, they are used to determine active state. If not the current request.path is used.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/facades/helpers/navigation.rb', line 20 def nav_link(text, href, = {}) .merge!(:path => request.path) wrapper = .delete(:wrapper) link = NavigationLink.new(text, href, ) current = link.active? link. = Navigator.merge_html_classes('active', link.) if current if wrapper if wrapper.is_a?(Hash) wrap_attrs = wrapper wrapper = wrap_attrs.delete(:tag) || :li else wrap_attrs = {} end wrap_attrs = Navigator.merge_html_classes('active', wrap_attrs) if current return content_tag(wrapper, link_to(link.text, link.href, link.), wrap_attrs) end link_to(link.text, link.href, link.) end |