Class: Sinatra::Tabs::TabsContainer
- Inherits:
-
Object
- Object
- Sinatra::Tabs::TabsContainer
- Defined in:
- lib/sinatra/tabs.rb
Instance Method Summary collapse
- #end_body ⇒ Object
- #header ⇒ Object
-
#initialize(tabs_ids) ⇒ TabsContainer
constructor
A new instance of TabsContainer.
- #start_body ⇒ Object
- #tab(id) ⇒ Object
Constructor Details
#initialize(tabs_ids) ⇒ TabsContainer
Returns a new instance of TabsContainer.
31 32 33 34 |
# File 'lib/sinatra/tabs.rb', line 31 def initialize(tabs_ids) @tabs_ids=tabs_ids @first_tab=true end |
Instance Method Details
#end_body ⇒ Object
60 61 62 |
# File 'lib/sinatra/tabs.rb', line 60 def end_body "</div>\n</div>" end |
#header ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sinatra/tabs.rb', line 35 def header tabs_li=@tabs_ids.map {|v| "<li role='presentation' class='#{@tabs_ids.keys.first==v[0] ? 'active':''}'> <a href='#tab-#{v[0]}' aria-control='tab-#{v[0]}' role='tab' data-toggle='tab'>#{v[1]}</a></li> " } "<ul class='nav nav-tabs' role='tablist'> #{tabs_li.join("\n")} </ul> " end |
#start_body ⇒ Object
47 48 49 50 |
# File 'lib/sinatra/tabs.rb', line 47 def start_body @first_tab=true "<div class='tab-content'>" end |
#tab(id) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/sinatra/tabs.rb', line 51 def tab(id) raise "No id in tabs" if @tabs_ids[id].nil? close_prev= @first_tab ? "" : "</div>" current_tab="<div role='tabpanel' class='tab-pane #{@first_tab ? 'active':''}' id='tab-#{id}'>" @first_tab=false "#{close_prev}\n#{current_tab}" end |