module Facades module Helpers module Navigation ## # Constructs a navigation list containing # a variable number of list items and links. # def nav(options = {}, &block) Navigator.new(self, options).render(&block) end alias :navigation :nav ## # 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. # 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 content_tag(wrapper, link_to(link.text, link.href, link.options), wrap_attrs) end link_to(link.text, link.href, link.options) end class Navigator attr_reader :view, :path attr_accessor :options, :nested, :links def initialize(tpl, options = {}, nested = false) @view, @options, @nested, @links = tpl, options, nested, [] @path = view.request.path end delegate :content_tag, :concat, :link_to, :to => :view ## # Renders the resulting html list, wrapped in a