Sha256: 2a4640fb1d2c18ad9f3620ec37043697d154307c7109f4140222a3c76d3c76ca

Contents?: true

Size: 1.42 KB

Versions: 25

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Katalyst
  module Tables
    module HasTableContent # :nodoc:
      extend ActiveSupport::Concern

      def initialize(object_name: nil, partial: nil, as: nil, **)
        super(**)

        @object_name = object_name || model_name&.i18n_key
        @partial     = partial
        @as          = as
      end

      def before_render
        # move @__vc_render_in_block to @row_proc to avoid slot lookup attempting to call it
        @row_proc = @__vc_render_in_block
        @__vc_render_in_block = nil
      end

      def model_name
        collection.model_name if collection.respond_to?(:model_name)
      end

      private

      def row_content(row, record)
        @current_row = row
        @current_record = record
        row_proc.call(self, record)
      ensure
        @current_row = nil
        @current_record = nil
      end

      def row_proc
        @row_proc ||= Proc.new do |table, object|
          row_renderer.render_row(table, object, view_context)
        end
      end

      def row_renderer
        @row_renderer ||= RowRenderer.new(@lookup_context,
                                          collection:,
                                          as:         @as,
                                          partial:    @partial,
                                          variants:   [:row],
                                          formats:    [:html])
      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/has_table_content.rb
katalyst-tables-3.7.0 app/components/concerns/katalyst/tables/has_table_content.rb
katalyst-tables-3.6.2 app/components/concerns/katalyst/tables/has_table_content.rb
katalyst-tables-3.6.1 app/components/concerns/katalyst/tables/has_table_content.rb
katalyst-tables-3.6.0 app/components/concerns/katalyst/tables/has_table_content.rb
katalyst-tables-3.5.5 app/components/concerns/katalyst/tables/has_table_content.rb
katalyst-tables-3.5.4 app/components/concerns/katalyst/tables/has_table_content.rb
katalyst-tables-3.5.3 app/components/concerns/katalyst/tables/has_table_content.rb
katalyst-tables-3.5.2 app/components/concerns/katalyst/tables/has_table_content.rb
katalyst-tables-3.5.1 app/components/concerns/katalyst/tables/has_table_content.rb
katalyst-tables-3.5.0 app/components/concerns/katalyst/tables/has_table_content.rb
katalyst-tables-3.4.6 app/components/concerns/katalyst/tables/has_table_content.rb
katalyst-tables-3.4.5 app/components/concerns/katalyst/tables/has_table_content.rb
katalyst-tables-3.4.4 app/components/concerns/katalyst/tables/has_table_content.rb
katalyst-tables-3.4.3 app/components/concerns/katalyst/tables/has_table_content.rb
katalyst-tables-3.4.2 app/components/concerns/katalyst/tables/has_table_content.rb
katalyst-tables-3.4.1 app/components/concerns/katalyst/tables/has_table_content.rb
katalyst-tables-3.4.0 app/components/concerns/katalyst/tables/has_table_content.rb
katalyst-tables-3.3.4 app/components/concerns/katalyst/tables/has_table_content.rb
katalyst-tables-3.3.3 app/components/concerns/katalyst/tables/has_table_content.rb