Sha256: 943561d84331cfdf9ea6495bb22687be3d1766a303f6831d05ac39ee10fa106c

Contents?: true

Size: 904 Bytes

Versions: 2

Compression:

Stored size: 904 Bytes

Contents

module PaginatedTable
  class ColumnDescription
    attr_reader :name

    def initialize(row, name, options = {}, &block)
      @row = row
      @name = name
      @block = block
      @options = options
    end

    def render_header
      @options.fetch(:title, @name.to_s.titleize)
    end

    def render_cell(datum)
      if @block
        @block.call(datum)
      else
        datum.send(@name)
      end
    end

    def sortable?
      @options.fetch(:sortable, true)
    end

    def span
      @options.fetch(:span, false)
    end

    def html_attributes
      html_attributes = {}
      if @options[:class]
        html_attributes[:class] = Array(@options[:class]).join(' ')
      end
      if @options[:style]
        html_attributes[:style] = @options[:style]
      end
      if span
        html_attributes[:colspan] = @row.colspan(span)
      end
      html_attributes
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
paginated_table-0.0.9 lib/paginated_table/column_description.rb
paginated_table-0.0.8 lib/paginated_table/column_description.rb