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

Instance Method Details

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(options = {}, &block)
  Navigator.new(self, options).render(&block)
end

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, options = {})
  options.merge!(:path => request.path)
  wrapper = options.delete(:wrapper)
  link    = NavigationLink.new(text, href, options)
  current = link.active?
  link.options = Navigator.merge_html_classes('active', link.options) 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 (wrapper, link_to(link.text, link.href, link.options), wrap_attrs)
  end
  
  link_to(link.text, link.href, link.options)
end