Class: Xebec::NavBar

Inherits:
Object
  • Object
show all
Defined in:
lib/xebec/nav_bar.rb

Constant Summary collapse

DEFAULT_NAME =
:default

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, html_attributes = nil) ⇒ NavBar

Create a new NavBar object.

Parameters:

  • name (String) (defaults to: nil)

    the name of the navigation bar; defaults to :default

  • html_attributes (Hash) (defaults to: nil)

    additional HTML attributes for the navigation bar, e.g. { :id => ‘my-navbar’ }



19
20
21
22
23
24
# File 'lib/xebec/nav_bar.rb', line 19

def initialize(name = nil, html_attributes = nil)
  @name = name || DEFAULT_NAME
  @html_attributes = html_attributes || {}
  @items = []
  @current = nil
end

Instance Attribute Details

#currentObject

Returns the value of attribute current.



12
13
14
# File 'lib/xebec/nav_bar.rb', line 12

def current
  @current
end

#html_attributesObject (readonly)

Returns the value of attribute html_attributes.



11
12
13
# File 'lib/xebec/nav_bar.rb', line 11

def html_attributes
  @html_attributes
end

#itemsObject (readonly)

Returns the value of attribute items.



10
11
12
# File 'lib/xebec/nav_bar.rb', line 10

def items
  @items
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/xebec/nav_bar.rb', line 9

def name
  @name
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/xebec/nav_bar.rb', line 40

def empty?
  items.empty?
end

#inspectObject



48
49
50
# File 'lib/xebec/nav_bar.rb', line 48

def inspect
  "<NavBar #{name}: #{items.map(&:name).join('|')}>"
end

Add a navigation item to this bar.

To customize the link text, set the internationalization key navbar.{{nav bar name}}.{{nav item name}}.

Parameters:

  • name (String, Symbol)

    the name of the item

  • href (String, Proc) (defaults to: nil)

    the URL of the item; optional

See Also:



36
37
38
# File 'lib/xebec/nav_bar.rb', line 36

def nav_item(name, href = nil)
  items << Xebec::NavItem.new(name, href)
end

#to_sObject



44
45
46
# File 'lib/xebec/nav_bar.rb', line 44

def to_s
  "<NavBar #{name}>"
end