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
153 154 155 156 157 158 159 |
# File 'lib/htmlgrid/grid.rb', line 153 def [](x) begin @fields[x] rescue StandardError nil end end |
#add(item, x) ⇒ Object
121 122 123 |
# File 'lib/htmlgrid/grid.rb', line 121 def add(item, x) (@fields[x] ||= Field.new).add item end |
#each_field(x, w = 1) ⇒ Object
124 125 126 127 128 |
# File 'lib/htmlgrid/grid.rb', line 124 def each_field(x, w=1) x.upto([x+w, @width].min - 1) { |xx| yield(@fields[xx]) } end |
#field_attribute(key, x = 0) ⇒ Object
134 135 136 |
# File 'lib/htmlgrid/grid.rb', line 134 def field_attribute(key, x=0) @fields[x].attribute(key) end |
#field_html(cgi) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/htmlgrid/grid.rb', line 137 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
115 116 117 118 119 120 |
# File 'lib/htmlgrid/grid.rb', line 115 def initialize_row w if(w > @width) @width.upto(w-1) { |ii| @fields[ii] ||= Field.new } @width = w end end |
#set_attributes(attr) ⇒ Object
150 151 152 |
# File 'lib/htmlgrid/grid.rb', line 150 def set_attributes(attr) @attributes = attr end |
#to_html(cgi) ⇒ Object
129 130 131 132 133 |
# File 'lib/htmlgrid/grid.rb', line 129 def to_html cgi cgi.tr(@attributes) { field_html(cgi) } end |