Class: TabsOnRails::Tabs::TabsBuilder

Inherits:
Builder
  • Object
show all
Defined in:
lib/tabs_on_rails/tabs.rb

Overview

Tabs Builder

The TabsBuilder is and example of custom Builder. It creates a new tab

Instance Method Summary collapse

Methods inherited from Builder

#current_tab?, #initialize

Constructor Details

This class inherits a constructor from TabsOnRails::Tabs::Builder

Instance Method Details

#close_tabsObject

Implements Builder#close_tabs.



108
109
110
# File 'lib/tabs_on_rails/tabs.rb', line 108

def close_tabs
  '</ul>'
end

#open_tabsObject

Implements Builder#open_tabs.



103
104
105
# File 'lib/tabs_on_rails/tabs.rb', line 103

def open_tabs
  '<ul>'
end

#tab_for(tab, name, options) ⇒ Object

Implements Builder#tab_for. Returns a link_to tab with name and options if tab is not the current tab, a simple tab name wrapped by a span tag otherwise.

current_tab? :foo   # => true

tab_for :foo, 'Foo', foo_path
# => <li><span>Foo</span></li>

tab_for :bar, 'Bar', bar_path
# => <li><a href="/link/to/bar">Bar</a></li>


95
96
97
98
99
100
# File 'lib/tabs_on_rails/tabs.rb', line 95

def tab_for(tab, name, options)
  content = @context.link_to_unless(current_tab?(tab), name, options) do
    @context.(:span, name)
  end
  @context.(:li, content)
end