class HtmlGrid::Grid::Row

Public Class Methods

new() click to toggle source

Row

# File lib/htmlgrid/grid.rb, line 127
def initialize
  @width = 1
  @fields = [Field.new]
  @attributes = {}
end

Public Instance Methods

[](x) click to toggle source
# File lib/htmlgrid/grid.rb, line 178
def [](x)
  @fields[x]
rescue
  nil
end
add(item, x) click to toggle source
# File lib/htmlgrid/grid.rb, line 140
def add(item, x)
  (@fields[x] ||= Field.new).add item
end
each_field(x, w = 1) { |fields| ... } click to toggle source
# File lib/htmlgrid/grid.rb, line 144
def each_field(x, w = 1)
  x.upto([x + w, @width].min - 1) { |xx|
    yield(@fields[xx])
  }
end
field_attribute(key, x = 0) click to toggle source
# File lib/htmlgrid/grid.rb, line 156
def field_attribute(key, x = 0)
  @fields[x].attribute(key)
end
field_html(cgi) click to toggle source
# File lib/htmlgrid/grid.rb, line 160
def field_html(cgi)
  html = ""
  span = 1
  @fields.each { |field|
    if span < 2
      html << field.to_html(cgi)
      span = field.colspan
    else
      span -= 1
    end
  }
  html
end
initialize_row(w) click to toggle source
# File lib/htmlgrid/grid.rb, line 133
def initialize_row w
  if w > @width
    @width.upto(w - 1) { |ii| @fields[ii] ||= Field.new }
    @width = w
  end
end
set_attributes(attr) click to toggle source
# File lib/htmlgrid/grid.rb, line 174
def set_attributes(attr)
  @attributes = attr
end
to_html(cgi) click to toggle source
# File lib/htmlgrid/grid.rb, line 150
def to_html cgi
  cgi.tr(@attributes) {
    field_html(cgi)
  }
end