Class: Tabnav::Navbar

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

:nodoc:



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

def initialize(template, params, options = {}) # :nodoc:
  @template = template
  @params = params
  @html_options = options
  @tabs = []
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_tab(options = {}) {|t| ... } ⇒ 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

Yields:

  • (t)


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

def add_tab(options = {})
  options[:tab_content_partial] = @tab_content_partial if @tab_content_partial
  t = Tab.new(@template, @params, options)
  yield t
  @tabs << t
end

#renderObject

:nodoc:



25
26
27
28
29
30
31
32
33
34
# File 'lib/tabnav/navbar.rb', line 25

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