Sha256: 355667d0473d7ed37cb0cd81f89ac249ea0e2d179313f823dc811eb909cff9be

Contents?: true

Size: 1.49 KB

Versions: 8

Compression:

Stored size: 1.49 KB

Contents

module Pageflow
  module Admin
    class Tabs
      # @api private
      def initialize
        @tabs = {}
      end

      # Display additional tabs on admin resource pages.
      #
      # @param [Symbol] resource_name A resource name like `:entry`,
      #   `:user`, `:account` or `:site`.
      # @param [Hash] options
      # @option options [Symbol] :name Unique identifier.
      # @option options [Arbre::Component] :component Component to
      #   render as tab contents
      # @option options [Symbol] :required_role (`nil`) Requires the
      #   current user to either have an account or entry membership
      #   with at least the given role. By default all users can see
      #   the tab.
      # @option options [Symbol] :required_account_role (`nil`)
      #   Requires the current user to have an account membership with
      #   at least the given role. By default all users can see the
      #   tab. This option only takes effect for the entry resource.
      # @option options [Boolean] :admin_only (`false`) Allow only
      #   admins to see the tab.
      def register(resource_name, options)
        @tabs[resource_name] ||= []
        @tabs[resource_name] << options
      end

      # @api private
      def find_by_resource(resource)
        @tabs.fetch(resource_name(resource), []).map do |options|
          Tab.new(options, resource)
        end
      end

      private

      def resource_name(resource)
        resource.class.model_name.param_key.to_sym
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pageflow-17.0.4 lib/pageflow/admin/tabs.rb
pageflow-17.0.3 lib/pageflow/admin/tabs.rb
pageflow-17.0.2 lib/pageflow/admin/tabs.rb
pageflow-17.0.1 lib/pageflow/admin/tabs.rb
pageflow-17.0.0 lib/pageflow/admin/tabs.rb
pageflow-16.2.0 lib/pageflow/admin/tabs.rb
pageflow-16.1.0 lib/pageflow/admin/tabs.rb
pageflow-16.0.0 lib/pageflow/admin/tabs.rb