Sha256: 7fbdf701b9b611c1d4a7102823ea165f5107b8b7dbc5a2d8e0502b0849969022

Contents?: true

Size: 876 Bytes

Versions: 1

Compression:

Stored size: 876 Bytes

Contents

# frozen_string_literal: true

module Katalyst
  module Tables
    class BodyCellComponent < ViewComponent::Base # :nodoc:
      include Frontend::Helper

      attr_reader :record

      def initialize(table, record, attribute, heading: false, **html_options)
        super(**html_options)

        @table     = table
        @record    = record
        @attribute = attribute
        @type      = heading ? :th : :td
      end

      def before_render
        # fallback if no content block is given
        with_content(value.to_s) unless content?
      end

      def call
        content # ensure content is set before rendering options

        content_tag(@type, content, **@html_options)
      end

      # @return the object for this row.
      def object
        @record
      end

      def value
        @record.public_send(@attribute)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
katalyst-tables-2.0.0 app/components/katalyst/tables/body_cell_component.rb