Class: Interview::TabBox

Inherits:
Control show all
Includes:
HasControls
Defined in:
lib/interview/tab_box.rb

Instance Attribute Summary

Attributes included from HasControls

#controls

Attributes inherited from Control

#parent

Instance Method Summary collapse

Methods included from HasControls

#add_control, #add_controls, included, #initialize, #siblings

Methods inherited from Control

#ancestors, build, definition, #find_attribute, #find_attribute!, inherited, #initialize, #set_attributes, #set_defaults

Instance Method Details

#renderObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/interview/tab_box.rb', line 6

def render
  if @controls.none? { |c| c.active }
    @controls.first.active = true
  end
  
  html = Builder::XmlMarkup.new
  html.ul class: 'nav nav-tabs tab_box' do
    @controls.each do |control|
      html_class = control.active ? 'active' : ''
      html.li class: html_class do
        html.a control.caption, href: "##{control.caption}", :'data-toogle' => 'tab'
      end
    end
  end
  html.div class: 'tab-content' do
    @controls.each do |control|
      html << control.render
    end
  end
  return html.target!
end