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’ }



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

def initialize(name = nil, html_attributes = nil)
  @name = name || DEFAULT_NAME
  @html_attributes = html_attributes || {}
  @items = []
  @current = nil
  @current_is_link = Xebec.current_is_link
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

Returns the value of attribute current_is_link.



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

def current_is_link
  @current_is_link
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)


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

def empty?
  items.empty?
end

#inspectObject



51
52
53
# File 'lib/xebec/nav_bar.rb', line 51

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

  • html_options (Hash) (defaults to: {})

    additional html_options to be passed to link_to

See Also:



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

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

#to_sObject



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

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