Sha256: f775b34b733aa0005deeb1cb6c6f7e7d63477c9a9a6604d8351056f200f4d974

Contents?: true

Size: 1.05 KB

Versions: 12

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 = URI.encode(string) if result.blank?
        result
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
activeadmin-2.7.0 lib/active_admin/views/components/tabs.rb
activeadmin-2.6.1 lib/active_admin/views/components/tabs.rb
activeadmin-2.6.0 lib/active_admin/views/components/tabs.rb
activeadmin-2.5.0 lib/active_admin/views/components/tabs.rb
activeadmin-2.4.0 lib/active_admin/views/components/tabs.rb
activeadmin-2.3.1 lib/active_admin/views/components/tabs.rb
activeadmin-2.3.0 lib/active_admin/views/components/tabs.rb
activeadmin-2.2.0 lib/active_admin/views/components/tabs.rb
activeadmin-2.1.0 lib/active_admin/views/components/tabs.rb
activeadmin-2.0.0 lib/active_admin/views/components/tabs.rb
activeadmin-2.0.0.rc2 lib/active_admin/views/components/tabs.rb
activeadmin-2.0.0.rc1 lib/active_admin/views/components/tabs.rb