Sha256: 49ea5c2c497d1e1386bf1ab5f39e74bca960a141d52826620231414da9843467

Contents?: true

Size: 726 Bytes

Versions: 12

Compression:

Stored size: 726 Bytes

Contents

module TableBuilder
  class Body < Rows
    self.tag_name = :tbody

    include ActionView::RecordIdentifier
    
    def row(options = {}, &block)
      table.collection.each_with_index do |record, ix|
        super(record, options_for_record(record, ix, options))
      end
    end

    protected

      def build
        row do |row, record| 
          row.cell *table.columns.map { |column| record.send(column.attribute_name) }
        end if @rows.empty?
      end
    
      def options_for_record(record, ix, options = {})
        options = options.dup
        options[:id] = dom_id(record) if record.respond_to?(:new_record?)
        add_class!(options, 'alternate') if ix % 2 == 1
        options
      end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
adva-0.2.4 vendor/gems/table_builder/lib/table_builder/body.rb
adva-0.2.3 vendor/gems/table_builder/lib/table_builder/body.rb
adva-0.2.2 vendor/gems/table_builder/lib/table_builder/body.rb
adva-0.2.1 vendor/gems/table_builder/lib/table_builder/body.rb
adva-0.2.0 vendor/gems/table_builder/lib/table_builder/body.rb
adva-0.1.4 vendor/gems/table_builder/lib/table_builder/body.rb
adva-0.1.3 vendor/gems/table_builder/lib/table_builder/body.rb
adva-0.1.2 vendor/gems/table_builder/lib/table_builder/body.rb
adva-0.1.1 vendor/gems/table_builder/lib/table_builder/body.rb
adva-0.1.0 vendor/gems/table_builder/lib/table_builder/body.rb
adva_cms-0.0.1 vendor/gems/table_builder/lib/table_builder/body.rb
adva-0.0.1 adva_cms/vendor/gems/table_builder/lib/table_builder/body.rb