Class: NavigationMenu

Inherits:
Object
  • Object
show all
Defined in:
lib/dti-navigation-menu/lib/dti-navigation-menu.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, i_href = nil, markup_classes = nil, &block) ⇒ NavigationMenu

Returns a new instance of NavigationMenu.



4
5
6
7
8
# File 'lib/dti-navigation-menu/lib/dti-navigation-menu.rb', line 4

def initialize(title, i_href = nil, markup_classes = nil, &block)
  @title, @href, @markup_classes = title, i_href, markup_classes
  @items = []
  block.call(self) if block
end

Instance Attribute Details

#hrefObject

Returns the value of attribute href.



2
3
4
# File 'lib/dti-navigation-menu/lib/dti-navigation-menu.rb', line 2

def href
  @href
end

#itemsObject

Returns the value of attribute items.



2
3
4
# File 'lib/dti-navigation-menu/lib/dti-navigation-menu.rb', line 2

def items
  @items
end

#markup_classesObject

Returns the value of attribute markup_classes.



2
3
4
# File 'lib/dti-navigation-menu/lib/dti-navigation-menu.rb', line 2

def markup_classes
  @markup_classes
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/dti-navigation-menu/lib/dti-navigation-menu.rb', line 2

def title
  @title
end

Instance Method Details

#descendents?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/dti-navigation-menu/lib/dti-navigation-menu.rb', line 20

def descendents?
  (@items.length > 0) ? true : false
end

#each(&block) ⇒ Object



16
17
18
# File 'lib/dti-navigation-menu/lib/dti-navigation-menu.rb', line 16

def each(&block)
  @items.each(&block)
end

#item(title, i_href = nil, markup_classes = nil, &block) ⇒ Object



10
11
12
13
14
# File 'lib/dti-navigation-menu/lib/dti-navigation-menu.rb', line 10

def item(title, i_href = nil, markup_classes = nil, &block)
  menu_item = NavigationMenu.new title, i_href, markup_classes
  block.call menu_item if block
  @items << menu_item
end


24
25
26
# File 'lib/dti-navigation-menu/lib/dti-navigation-menu.rb', line 24

def link_id
  @title.downcase.gsub(/[^a-z0-9 ]/i,'').tr(' ','_').gsub(/[\_]{2,}/,'_')
end