Sha256: 0a4e5fed61dba636a9882122d6a567dc81d29fb5aad201fb634d9bc3b3c9013a

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require "active_support"
require "active_support/core_ext/module/delegation"

require_relative "../helper"

module Katalyst
  module Tables
    module Frontend
      module Builder
        class Base # :nodoc:
          include Helper

          attr_reader :table

          delegate :sort,
                   :table_header_cell,
                   :table_header_row,
                   :table_body_cell,
                   :table_body_row,
                   :template,
                   to: :table

          delegate :content_tag,
                   :link_to,
                   :render,
                   :translate,
                   :with_output_buffer,
                   to: :template

          def initialize(table, **options)
            @table  = table
            @header = false
            self.options(**options)
          end

          def header?
            @header
          end

          def body?
            !@header
          end

          def options(**options)
            @html_options = html_options_for_table_with(**options)
          end

          private

          def table_tag(type, value = nil, &block)
            # capture output before calling tag, to allow users to modify `options` during body execution
            value = with_output_buffer(&block) if block_given?

            content_tag(type, value, @html_options, &block)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
katalyst-tables-1.0.0 lib/katalyst/tables/frontend/builder/base.rb