Sha256: c3798d1e4b68c223f6735f8d947347ae5b37ed56494aaaf38c56ba937ba1e7eb

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module Trestle
  class Table
    extend ActiveSupport::Autoload

    autoload :Automatic
    autoload :Builder
    autoload :Column
    autoload :ActionsColumn
    autoload :SelectColumn
    autoload :Row

    attr_reader :columns, :options, :admin
    attr_writer :row

    def initialize(options={})
      @options = options
      @admin = Trestle.lookup(options[:admin]) if options.key?(:admin)

      @columns = []
    end

    def sortable?
      options[:sortable] == true
    end

    def renderer(template)
      Renderer.new(self, template)
    end

    def row
      @row || Row.new(self)
    end

    class Renderer
      delegate :options, to: :@table

      def initialize(table, template)
        @table, @template = table, template
      end

      def row
        @row ||= @table.row.renderer(@template)
      end

      def columns
        @columns ||= @table.columns.map { |column| column.renderer(@template) }
      end

      def classes
        ["trestle-table", options[:class]].compact
      end

      def data
        options[:data]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trestle-0.8.5 lib/trestle/table.rb