Class: Mmmenu

Inherits:
Object
  • Object
show all
Defined in:
lib/mmmenu.rb,
lib/mmmenu/level.rb,
lib/mmmenu/version.rb

Defined Under Namespace

Classes: Engine, Level

Constant Summary collapse

VERSION =
'0.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, &block) ⇒ Mmmenu

Returns a new instance of Mmmenu.



8
9
10
11
12
13
14
15
16
# File 'lib/mmmenu.rb', line 8

def initialize(options, &block)
  @items          = options[:items] || Mmmenu::Level.new(&block).to_a
  @current_path   = options[:request].path.chomp('/')
  @request_params = options[:request].params
  @request_type   = options[:request].method.to_s.downcase
  @item_markup            = []
  @current_item_markup    = []
  @level_markup           = []
end

Instance Attribute Details

#current_itemObject

Returns the value of attribute current_item.



6
7
8
# File 'lib/mmmenu.rb', line 6

def current_item
  @current_item
end

Instance Method Details

#buildObject



43
44
45
46
47
# File 'lib/mmmenu.rb', line 43

def build
  result = build_level[:output]
  @current_item = @deepest_current_item
  result
end

#current_item_markup(level, options = {}, &block) ⇒ Object



29
30
31
32
# File 'lib/mmmenu.rb', line 29

def current_item_markup(level, options={}, &block)
  level -= 1
  @current_item_markup[level] = { :block => block, :options => options }
end

#item_markup(level, options = {}, &block) ⇒ Object

The following two methods define the markup for each menu item on the current and lower levels (unless lower levels are not redefined later). Example:

@menu.item_markup(0, options) do |link, text, options|
  "<a href=\"#{link}\" #{options}>#{text}</a>"
end


25
26
27
28
# File 'lib/mmmenu.rb', line 25

def item_markup(level, options={}, &block)
  level -= 1
  @item_markup[level] = { :block => block, :options => options }
end

#level_markup(level = 1, &block) ⇒ Object

Defines the markup wrapper for the current menu level and lower menu levels (unless lower levels are not redefined later). Example:

@menu.level_markup(0) { |level_content| "<div>#{level_content}</div>" }


38
39
40
41
# File 'lib/mmmenu.rb', line 38

def level_markup(level=1, &block)
  level -= 1
  @level_markup[level] = block
end