Module: Kin::Nav::Helper

Defined in:
lib/kin/nav/helper_mixin.rb

Overview

Mix into your Merb::GlobalHelpers module (not done automatically).

Instance Method Summary collapse

Instance Method Details

#display_navigation(name, options = {}) ⇒ String

Displays the navigation identified by name.

You can change the formatter used to generate HTML for all menus by altering Merb::Plugins.config[:nav_formatter].

Examples:

Injecting content

# Injects '5' into the :comments nav item. See
# specs/fixture/app/views/nav_specs/content_injection.html.haml
display_navigation :default, :home, :inject => { :comments => '5' }

Guard conditions

# Displays any nav items which have the :admin guard condition set.
# See specs/fixture/app/views/nav_specs/guard_*.html.haml
display_navigation :default, :home, :guard => { :admin => true }

Using a resource to generate a URL

# A resource to be passed to nav items which use a resource URL.
# See specs/fixture/app/views/nav_specs/resource_url.html.haml
display_navigation :default, :home, :resource => #<User>

Options Hash (options):

  • :formatter (Kin::Nav::Formatter)

    Overrides the default formatter.

  • :inject (Hash)

    Injects content into a nav item.



46
47
48
49
50
# File 'lib/kin/nav/helper_mixin.rb', line 46

def display_navigation(name, options = {})
  (options[:formatter] || Kin::Nav.get(name).formatter).new(
    Kin::Nav.get(name), self, options
  ).to_html
end