Class: Facades::Patterns::Tabs::TabBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/facades/patterns/tabs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tpl, options = {}) ⇒ TabBuilder

Returns a new instance of TabBuilder.



17
18
19
# File 'lib/facades/patterns/tabs.rb', line 17

def initialize(tpl, options = {})
  @view, @options, @tabs = tpl, options, []
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



15
16
17
# File 'lib/facades/patterns/tabs.rb', line 15

def options
  @options
end

#tabsObject

Returns the value of attribute tabs.



15
16
17
# File 'lib/facades/patterns/tabs.rb', line 15

def tabs
  @tabs
end

#viewObject (readonly)

Returns the value of attribute view.



14
15
16
# File 'lib/facades/patterns/tabs.rb', line 14

def view
  @view
end

Instance Method Details

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

Adds a new panel to the tabbed area.

Parameters:

  • title (String)

    The text to be used in the navigation link.

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

    A hash of html attributes to be added to the tab panel.



46
47
48
49
50
# File 'lib/facades/patterns/tabs.rb', line 46

def panel(title, options = {}, &block)
  panel = TabPanel.new(title, options)
  tabs << panel
  concat (:section, capture(&block), panel.options)
end

#render(&block) ⇒ Object

Renders the resulting tab area including a list navigation.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/facades/patterns/tabs.rb', line 27

def render(&block)
  klasses = options.delete(:class) || ""
  options.merge!(:class => klasses.split(" ").push("tabbed").join(" "))          
  rendered = view.capture(self, &block)
  output   = (:ul, { :class =>'tab-navigation' }) do
    tabs.each_with_index do |tab, ind|
      link_opts = ( ind == 0 ? { :class => 'active' } : {} )
      concat (:li, link_to(tab.title, "##{tab.tab_id}"), link_opts)
    end
  end
  output << rendered
  concat (:div, output, options)
end