Module: Navtastic

Defined in:
lib/navtastic.rb,
lib/navtastic/item.rb,
lib/navtastic/menu.rb,
lib/navtastic/version.rb,
lib/navtastic/renderer.rb

Overview

Main module containing some convenience methods

Defined Under Namespace

Classes: Item, Menu, Renderer

Constant Summary collapse

VERSION =

Current Navtastic version

'0.0.0'.freeze

Class Method Summary collapse

Class Method Details

.all_menusArray

A list of all defined menus


58
59
60
# File 'lib/navtastic.rb', line 58

def self.all_menus
  @menu_store.keys
end

.define(name) {|menu, params| ... } ⇒ Object

Define a new menu to be rendered later

Examples:

Define a new menu

Navtastic.define :main do |menu, params|
  menu.item "Home", "/"
end

Yields:

  • (menu, params)

    block to generate a new menu

Yield Parameters:

  • menu (Menu)

    the menu to be initialized

  • params (Hash)

    runtime parameters

Raises:

  • (ArgumentError)

    if no block was given


27
28
29
30
31
32
# File 'lib/navtastic.rb', line 27

def self.define(name, &block)
  raise ArgumentError, "no block given" unless block_given?

  name = name.to_sym if name.is_a? String
  @menu_store[name] = block
end

.render(name, current_url, params = {}) ⇒ Renderer

Render a stored menu

Raises:

  • (KeyError)

    if the menu was not defined


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/navtastic.rb', line 43

def self.render(name, current_url, params = {})
  name = name.to_sym if name.is_a? String
  block = @menu_store[name]

  raise KeyError, "menu not defined: #{name.inspect}" if block.nil?

  menu = Menu.new
  block.call(menu, params)
  menu.current_url!(current_url)
  Renderer.render(menu)
end