Sha256: 299b436d5a902fbac0970a4882ae1934d155dd1fb0409752d8a7cb2dc9a2aa88

Contents?: true

Size: 1.11 KB

Versions: 25

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module Katalyst
  module Tables
    # Adds dom ids to the table and row components.
    # See [documentation](/docs/identifiable.md) for more details.
    module Identifiable
      extend ActiveSupport::Concern

      module Defaults
        extend self

        # Returns the default dom id for the table, uses the collection's
        # model name's route_key as a sensible default.
        def default_table_id(collection = self.collection)
          collection.model_name.route_key
        end
      end

      included do
        include Defaults
      end

      def initialize(generate_ids: false, **)
        super(**)

        @generate_ids = generate_ids
      end

      def identifiable?
        @generate_ids
      end

      def id
        html_attributes[:id]
      end

      def before_render
        if identifiable?
          update_html_attributes(id: default_table_id(collection)) if id.nil?

          @body_row_callbacks << Proc.new do |row, record|
            row.update_html_attributes(id: dom_id(record))
          end
        end

        super
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
katalyst-tables-3.8.0 app/components/concerns/katalyst/tables/identifiable.rb
katalyst-tables-3.7.0 app/components/concerns/katalyst/tables/identifiable.rb
katalyst-tables-3.6.2 app/components/concerns/katalyst/tables/identifiable.rb
katalyst-tables-3.6.1 app/components/concerns/katalyst/tables/identifiable.rb
katalyst-tables-3.6.0 app/components/concerns/katalyst/tables/identifiable.rb
katalyst-tables-3.5.5 app/components/concerns/katalyst/tables/identifiable.rb
katalyst-tables-3.5.4 app/components/concerns/katalyst/tables/identifiable.rb
katalyst-tables-3.5.3 app/components/concerns/katalyst/tables/identifiable.rb
katalyst-tables-3.5.2 app/components/concerns/katalyst/tables/identifiable.rb
katalyst-tables-3.5.1 app/components/concerns/katalyst/tables/identifiable.rb
katalyst-tables-3.5.0 app/components/concerns/katalyst/tables/identifiable.rb
katalyst-tables-3.4.6 app/components/concerns/katalyst/tables/identifiable.rb
katalyst-tables-3.4.5 app/components/concerns/katalyst/tables/identifiable.rb
katalyst-tables-3.4.4 app/components/concerns/katalyst/tables/identifiable.rb
katalyst-tables-3.4.3 app/components/concerns/katalyst/tables/identifiable.rb
katalyst-tables-3.4.2 app/components/concerns/katalyst/tables/identifiable.rb
katalyst-tables-3.4.1 app/components/concerns/katalyst/tables/identifiable.rb
katalyst-tables-3.4.0 app/components/concerns/katalyst/tables/identifiable.rb
katalyst-tables-3.3.4 app/components/concerns/katalyst/tables/identifiable.rb
katalyst-tables-3.3.3 app/components/concerns/katalyst/tables/identifiable.rb