Module: TabsHelper

Defined in:
app/helpers/tabs_helper.rb

Instance Method Summary collapse

Instance Method Details

#tab(text = nil, link_url = nil, **opts, &block) ⇒ Array<ActiveSupport::SafeBuffer>

Build a tab and add it to the container generated by #tabs.

Parameters:

  • text (String) (defaults to: nil)

    Link text.

  • link_url (String) (defaults to: nil)

    Link URL.

  • opts (Hash)

    a customizable set of options

Options Hash (**opts):

  • :is_active (Boolean)

    Is the tab active?

  • :class (String)

    Additional classes to add to the tab.

Yield Returns:

  • (ActiveSupport::SafeBuffer)

    Pass an optional block instead of text and link_url to customize the content of the tab link.

Returns:

  • (Array<ActiveSupport::SafeBuffer>)

    The in-progress @building_tabs array.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/tabs_helper.rb', line 23

def tab(text = nil, link_url = nil, **opts, &block)
  active = opts[:is_active] || false
  opts.delete :is_active
  opts[:class] = if opts[:class]
                   "#{opts[:class]} tabs--tab#{active ? ' tab__active' : ''}"
                 else
                   "tabs--tab#{active ? ' tab__active' : ''}"
                 end

  @building_tabs << if block_given?
                      link_to link_url, **opts, &block
                    else
                      link_to text, link_url, **opts
                    end
end

#tabs { ... } ⇒ ActiveSupport::SafeBuffer

Build a tab container in which to place tabs. Intended for use with a block using #tab.

Yields:

  • Yields to a block that may modify @building_tabs to add tabs.

Returns:

  • (ActiveSupport::SafeBuffer)


6
7
8
9
10
11
12
# File 'app/helpers/tabs_helper.rb', line 6

def tabs
  @building_tabs = []
  yield
  tabs = @building_tabs.join("\n")
  @building_tabs = []
  tag.div raw(tabs), class: 'tabs'
end