Class: Facades::Patterns::Tabs::TabBuilder
- Inherits:
-
Object
- Object
- Facades::Patterns::Tabs::TabBuilder
- Defined in:
- lib/facades/patterns/tabs.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#tabs ⇒ Object
Returns the value of attribute tabs.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Instance Method Summary collapse
-
#initialize(tpl, options = {}) ⇒ TabBuilder
constructor
A new instance of TabBuilder.
-
#panel(title, options = {}, &block) ⇒ Object
Adds a new panel to the tabbed area.
-
#render(&block) ⇒ Object
Renders the resulting tab area including a list navigation.
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, = {}) @view, @options, @tabs = tpl, , [] end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
15 16 17 |
# File 'lib/facades/patterns/tabs.rb', line 15 def @options end |
#tabs ⇒ Object
Returns the value of attribute tabs.
15 16 17 |
# File 'lib/facades/patterns/tabs.rb', line 15 def tabs @tabs end |
#view ⇒ Object (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.
46 47 48 49 50 |
# File 'lib/facades/patterns/tabs.rb', line 46 def panel(title, = {}, &block) panel = TabPanel.new(title, ) tabs << panel concat content_tag(:section, capture(&block), panel.) 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 = .delete(:class) || "" .merge!(:class => klasses.split(" ").push("tabbed").join(" ")) rendered = view.capture(self, &block) output = content_tag(:ul, { :class =>'tab-navigation' }) do tabs.each_with_index do |tab, ind| link_opts = ( ind == 0 ? { :class => 'active' } : {} ) concat content_tag(:li, link_to(tab.title, "##{tab.tab_id}"), link_opts) end end output << rendered concat content_tag(:div, output, ) end |