Sha256: b514cd5344cbc22ef25293f6a7aaaf5ebe72109ca170b5aacc5e94fd69ed081a

Contents?: true

Size: 996 Bytes

Versions: 1

Compression:

Stored size: 996 Bytes

Contents

module TabsHelper
  def tabs_labels tabs
    any_active_tab = any_active_tabs tabs
    labelsHTML = ''
    tabs.each_with_index do |tab, index|
      active_tab_class = tab_class tab, index, any_active_tab
      labelsHTML += content_tag :li, class: active_tab_class do
        link_to "#tab-#{tab.id}", data: {toggle: 'tab'} do
          tab.label
        end
      end
    end

    raw labelsHTML
  end

  def tabs_content tabs
    any_active_tab = any_active_tabs tabs
    contentsHTML = ''
    tabs.each_with_index do |tab, index|
      active_tab_class = tab_class tab, index, any_active_tab
      contentsHTML += content_tag :li, class: "#{active_tab_class} tab-pane", id: "tab-#{tab.id}" do
          tab.content
      end
    end

    raw contentsHTML
  end

protected
  def tab_class tab, index, any_active_tab
    if tab.is_active || (!any_active_tab && index == 0)
      'active'
    else
      ''
    end
  end

  def any_active_tabs tabs
    tabs.any? {|tab| tab.is_active}
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
comfypress-0.1.4 app/helpers/tabs_helper.rb