Sha256: 9d7835f1c71adecb06f5936e5abbc6ddea90dab2ced9d9e70125d309a91ef3c2

Contents?: true

Size: 1000 Bytes

Versions: 2

Compression:

Stored size: 1000 Bytes

Contents

module Trestle
  class Table
    extend ActiveSupport::Autoload

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

    attr_reader :columns, :options
    attr_writer :row

    def initialize(options={})
      @options = options
      @columns = []
    end

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

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

    def row
      @row || Row.new
    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

2 entries across 2 versions & 1 rubygems

Version Path
trestle-0.8.2 lib/trestle/table.rb
trestle-0.8.0 lib/trestle/table.rb