Class: TabsOnRails::Tabs::TabsBuilder
- Defined in:
- lib/tabs_on_rails/tabs/tabs_builder.rb
Overview
Tabs Builder
The TabsBuilder is and example of custom Builder.
Instance Method Summary collapse
-
#close_tabs(options = {}) ⇒ Object
Returns an unordered list close tag.
-
#open_tabs(options = {}) ⇒ Object
Returns an unordered list open tag.
-
#tab_for(tab, name, url_options, item_options = {}) ⇒ Object
Returns a link_to
tab
withname
andoptions
iftab
is not the current tab, a simple tab name wrapped by a span tag otherwise.
Methods inherited from Builder
Constructor Details
This class inherits a constructor from TabsOnRails::Tabs::Builder
Instance Method Details
#close_tabs(options = {}) ⇒ Object
Returns an unordered list close tag.
The options
hash is ignored here. It exists only for coherence with the parent Builder API.
close_tag
# => "</ul>"
close_tag :class => "centered"
# => "</ul>"
Implements Builder#close_tabs.
77 78 79 |
# File 'lib/tabs_on_rails/tabs/tabs_builder.rb', line 77 def close_tabs( = {}) "</ul>".html_safe end |
#open_tabs(options = {}) ⇒ Object
Returns an unordered list open tag.
The options
hash is used to customize the HTML attributes of the tag.
open_tag
# => "<ul>"
open_tag :class => "centered"
# => "<ul class=\"centered\">"
Implements Builder#open_tabs.
60 61 62 |
# File 'lib/tabs_on_rails/tabs/tabs_builder.rb', line 60 def open_tabs( = {}) @context.tag("ul", , open = true) end |
#tab_for(tab, name, url_options, item_options = {}) ⇒ Object
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 class="current"><span>Foo</span></li>"
tab_for :bar, 'Bar',
# => "<li><a href="/link/to/bar">Bar</a></li>"
You can pass a hash of item_options
to customize the behavior and the style of the li element.
# Pass a custom class to the element
tab_for :bar, 'Bar', , :class => "custom"
# => "<li class="custom"><a href="/link/to/bar">Bar</a></li>"
Implements Builder#tab_for.
40 41 42 43 44 45 46 |
# File 'lib/tabs_on_rails/tabs/tabs_builder.rb', line 40 def tab_for(tab, name, , = {}) [:class] = [:class].to_s.split(" ").push(@options[:active_class] || "current").join(" ") if current_tab?(tab) content = @context.link_to_unless(current_tab?(tab), name, ) do @context.content_tag(:span, name) end @context.content_tag(:li, content, ) end |