Class: HtmlGrid::Grid::Row
- Inherits:
-
Object
- Object
- HtmlGrid::Grid::Row
- Defined in:
- lib/htmlgrid/grid.rb
Defined Under Namespace
Classes: Field
Instance Method Summary collapse
- #[](x) ⇒ Object
- #add(item, x) ⇒ Object
- #each_field(x, w = 1) ⇒ Object
- #field_attribute(key, x = 0) ⇒ Object
- #field_html(cgi) ⇒ Object
-
#initialize ⇒ Row
constructor
Row.
- #initialize_row(w) ⇒ Object
- #set_attributes(attr) ⇒ Object
- #to_html(cgi) ⇒ Object
Constructor Details
Instance Method Details
#[](x) ⇒ Object
178 179 180 181 182 |
# File 'lib/htmlgrid/grid.rb', line 178 def [](x) @fields[x] rescue nil end |
#add(item, x) ⇒ Object
140 141 142 |
# File 'lib/htmlgrid/grid.rb', line 140 def add(item, x) (@fields[x] ||= Field.new).add item end |
#each_field(x, w = 1) ⇒ Object
144 145 146 147 148 |
# 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) ⇒ Object
156 157 158 |
# File 'lib/htmlgrid/grid.rb', line 156 def field_attribute(key, x = 0) @fields[x].attribute(key) end |
#field_html(cgi) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 |
# 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) ⇒ Object
133 134 135 136 137 138 |
# 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) ⇒ Object
174 175 176 |
# File 'lib/htmlgrid/grid.rb', line 174 def set_attributes(attr) @attributes = attr end |
#to_html(cgi) ⇒ Object
150 151 152 153 154 |
# File 'lib/htmlgrid/grid.rb', line 150 def to_html cgi cgi.tr(@attributes) { field_html(cgi) } end |