Sha256: d2fc04aed3f12687af6928bcf8541be163481636e08601e0e152692f9d9123fb

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

module ActiveAdmin
  module Views
    class Tabs < ActiveAdmin::Component
      builder_method :tabs

      def tab(title, options = {}, &block)
        title = title.to_s.titleize if title.is_a? Symbol
        @menu << build_menu_item(title, options, &block)
        @tabs_content << build_content_item(title, options, &block)
      end

      def build(&block)
        @menu = ul(class: "nav nav-tabs", role: "tablist")
        @tabs_content = div(class: "tab-content")
      end

      def build_menu_item(title, options, &block)
        fragment = options.fetch(:id, fragmentize(title))

        html_options = options.fetch(:html_options, {})
        li html_options do
          link_to title, "##{fragment}"
        end
      end

      def build_content_item(title, options, &block)
        options = options.reverse_merge(id: fragmentize(title))
        div(options, &block)
      end

      private

      def fragmentize(string)
        result = string.parameterize
        result = CGI.escape(string) if result.blank?
        result
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/activeadmin-2.9.0/lib/active_admin/views/components/tabs.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/activeadmin-2.9.0/lib/active_admin/views/components/tabs.rb
activeadmin-2.9.0 lib/active_admin/views/components/tabs.rb
activeadmin-2.8.1 lib/active_admin/views/components/tabs.rb