Class: LogicalTabs::TabPane

Inherits:
Object
  • Object
show all
Defined in:
lib/logical_tabs/tab_pane.rb

Overview

This contains the info for a single tab and pane

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tabbed_panel, name, options = {}) ⇒ TabPane

tabbed_panel must be an instance of TabbedPanel

Name is required, is used as the primary reference to this tab

Other options:

:base_id  The string used as the beginning of the ID for CSS
          IDs for the tab and pane.  :base_id => 'foo' will
          generate a tab with ID 'foo_tab' and a panel with ID
          'foo_panel'.  Defaults to name.downcase

:tab_text The text to display in the tab.  Defaults to name.

:content  The content for the panel itself, in HTML


22
23
24
25
26
27
28
# File 'lib/logical_tabs/tab_pane.rb', line 22

def initialize(tabbed_panel, name, options = {})
  @tabbed_panel = tabbed_panel
  @name = name
  @base_id = options[:base_id] || name.underscore.gsub(/\s+/,'_')
  @tab_text = options[:tab_text] || name
  @content = options[:content] || ''
end

Instance Attribute Details

#base_idObject

Returns the value of attribute base_id.



6
7
8
# File 'lib/logical_tabs/tab_pane.rb', line 6

def base_id
  @base_id
end

#contentObject

Returns the value of attribute content.



6
7
8
# File 'lib/logical_tabs/tab_pane.rb', line 6

def content
  @content
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/logical_tabs/tab_pane.rb', line 6

def name
  @name
end

#pane_contentObject

Returns the value of attribute pane_content.



6
7
8
# File 'lib/logical_tabs/tab_pane.rb', line 6

def pane_content
  @pane_content
end

#tab_textObject

Returns the value of attribute tab_text.



6
7
8
# File 'lib/logical_tabs/tab_pane.rb', line 6

def tab_text
  @tab_text
end

#tabbed_panelObject

Returns the value of attribute tabbed_panel.



6
7
8
# File 'lib/logical_tabs/tab_pane.rb', line 6

def tabbed_panel
  @tabbed_panel
end

Instance Method Details

#composite_idObject

generates an ID for this tab_pane that includes the base_id of the containing tabbed_panel and the base_id of this tab_pane.



54
55
56
# File 'lib/logical_tabs/tab_pane.rb', line 54

def composite_id
  (@tabbed_panel.base_id + "_tp_" + @base_id).html_safe
end

#render_header(selected = false) ⇒ Object



40
41
42
43
44
45
# File 'lib/logical_tabs/tab_pane.rb', line 40

def render_header(selected = false)
  v.(:h3,
    @tab_text,
    :class => ("pane_print_header ").html_safe
  ).html_safe
end

#render_pane(selected = false) ⇒ Object

Generates HTML output for the panel Pass “true” to set this as the selected/visible panel



60
61
62
63
64
65
66
# File 'lib/logical_tabs/tab_pane.rb', line 60

def render_pane(selected = false)
  v.(:div,
    render_header + @content,
    :id => (composite_id + "_pane").html_safe,
    :class => "pane " + (selected ? "pane_selected" : "pane_unselected")
  ).html_safe
end

#render_tab(selected = false) ⇒ Object

Generates output for the tab. Pass “true” to set this as the selected tab.



32
33
34
35
36
37
38
# File 'lib/logical_tabs/tab_pane.rb', line 32

def render_tab(selected = false)
  v.(:li,
    tab_link,
    :id => (composite_id + "_tab").html_safe,
    :class => ("tab " + (selected ? "tab_selected" : "tab_unselected")).html_safe
  ).html_safe
end


48
49
50
# File 'lib/logical_tabs/tab_pane.rb', line 48

def tab_link
  v.(:a, @tab_text, :href => '#', :class => 'tab_link' ).html_safe
end