Class: Tabnav::Navbar

Inherits:
Tab
  • Object
show all
Defined in:
lib/tabnav/navbar.rb

Instance Attribute Summary collapse

Attributes inherited from Tab

#link_options, #link_url, #name

Instance Method Summary collapse

Methods inherited from Tab

#active?, #has_link?, #highlights_on, #links_to, #named, #render

Constructor Details

#initialize(template, params, html_options = {}) ⇒ Navbar

:nodoc:



3
4
5
6
7
8
# File 'lib/tabnav/navbar.rb', line 3

def initialize(template, params, html_options = {}) # :nodoc:
  @top_level = html_options.delete(:top_level)
  super
  @tabs = []
  @tab_content_partial = @partial
end

Instance Attribute Details

#tab_content_partial=(value) ⇒ Object (writeonly)

Optionally specifies a partial to be used to render the tab content.



11
12
13
# File 'lib/tabnav/navbar.rb', line 11

def tab_content_partial=(value)
  @tab_content_partial = value
end

Instance Method Details

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

Creates a sub Navbar and adds it to the navbar.

options is an optional hash of options which will be used to create the li containing the sub navbar.

yields the created Navbar



27
28
29
# File 'lib/tabnav/navbar.rb', line 27

def add_sub_nav(options = {}, &block)
  add_item(Navbar, options, &block)
end

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

Creates a Tab and adds it to the navbar.

options is an optional hash of options which will be used to create the li for the tab.

yields the created Tab



18
19
20
# File 'lib/tabnav/navbar.rb', line 18

def add_tab(options = {}, &block)
  add_item(Tab, options, &block)
end

#render_navbarObject

:nodoc:



31
32
33
34
35
36
37
38
39
40
# File 'lib/tabnav/navbar.rb', line 31

def render_navbar # :nodoc:
  return ''.html_safe if @tabs.empty?
  @template. :ul, @top_level ? @html_options : nil do
    contents = ''.html_safe
    @tabs.each do |tab|
      contents << tab.render
    end
    contents
  end
end