Sha256: bf9a44fca58179d353fec0fc001b566994e563367b0eb7eca3d8b087a168d4bd

Contents?: true

Size: 1.39 KB

Versions: 6

Compression:

Stored size: 1.39 KB

Contents

module Trestle
  class Table
    require_relative "table/automatic"
    require_relative "table/builder"
    require_relative "table/column"
    require_relative "table/actions_column"
    require_relative "table/select_column"
    require_relative "table/row"

    attr_reader :columns
    attr_writer :row
    attr_accessor :options

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

    def with_options(opts={})
      dup.tap do |table|
        table.options = options.merge(opts)
      end
    end

    def admin
      Trestle.lookup(options[:admin]) if options.key?(:admin)
    end

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

    def autolink?
      options[:autolink] != false
    end

    def header?
      options[:header] != false
    end

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

    def row
      @row || Row.new
    end

    class Renderer
      delegate :options, :header?, to: :@table

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

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

      def columns
        @columns ||= row.columns
      end

      def id
        options[:id]
      end

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

      def data
        options[:data]
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
trestle-0.9.8 lib/trestle/table.rb
trestle-0.9.7 lib/trestle/table.rb
trestle-0.9.6 lib/trestle/table.rb
trestle-0.9.5 lib/trestle/table.rb
trestle-0.9.4 lib/trestle/table.rb
trestle-0.9.3 lib/trestle/table.rb