Class: Tastymenu::Course

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
lib/tastymenu/course.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_controller, parent_menu, html_options = {}) {|_self| ... } ⇒ Course

Returns a new instance of Course.

Yields:

  • (_self)

Yield Parameters:



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

def initialize(request_controller, parent_menu, html_options = {})
  @html_options = html_options.symbolize_keys
  @parent_menu = parent_menu
  @request_controller = request_controller
  @menus = []
  self[:class] = "#{self[:class]} menu menu-#{level}".strip
  yield self if block_given?
end

Instance Attribute Details

Returns the value of attribute menus.



5
6
7
# File 'lib/tastymenu/course.rb', line 5

def menus
  @menus
end

#parent_menuObject (readonly)

Returns the value of attribute parent_menu.



5
6
7
# File 'lib/tastymenu/course.rb', line 5

def parent_menu
  @parent_menu
end

#request_controllerObject (readonly)

Returns the value of attribute request_controller.



5
6
7
# File 'lib/tastymenu/course.rb', line 5

def request_controller
  @request_controller
end

Instance Method Details

#htmlObject



39
40
41
42
43
44
45
46
# File 'lib/tastymenu/course.rb', line 39

def html
  html_options = @html_options.dup
  html_options[:class] = "#{html_options[:class]} selected".strip if selected?
  ('ul',
    @menus.inject('') {|html, menu| html << menu.html(@menus.last == menu) },
    html_options
  )
end

#levelObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/tastymenu/course.rb', line 17

def level
  @level ||= begin
    level = 1
    menu = parent_menu
    while menu
      level += 1
      menu = menu.parent_menu
    end
    level
  end
end


33
34
35
36
37
# File 'lib/tastymenu/course.rb', line 33

def menu(name, url_options = {}, html_options = {}, &block)
  menu = Tastymenu::Item.new(self, name, url_options, html_options, &block)
  @menus << menu
  menu
end

#selected?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/tastymenu/course.rb', line 29

def selected?
  @parent_menu && menus.any? {|menu| menu.selected?}
end