class Qwik::WabisabiTable
Attributes
table[R]
Public Class Methods
add_new_col(table)
click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-table.rb, line 44 def self.add_new_col(table) each_tr(table) {|tr, row| tr << [:td, ''] } end
add_new_row(table, max_col=nil)
click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-table.rb, line 73 def self.add_new_row(table, max_col=nil) max_col = max_col(table) if max_col.nil? tr = [:tr] (max_col).times { tr << [:td, ''] } table << tr end
each_td(table) { |td, col, row| ... }
click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-table.rb, line 65 def self.each_td(table) each_tr(table) {|tr, row| tr.each_child_with_index {|td, col| yield(td, col, row) } } end
each_tr(table) { |tr, row| ... }
click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-table.rb, line 59 def self.each_tr(table) table.each_child_with_index {|tr, row| yield(tr, row) } end
error_check(table)
click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-table.rb, line 10 def self.error_check(table) each_td(table) {|td, col, row| if 2 < td.length # Error! return true end } return false # No error. end
fill_empty_td(table, max_col=nil)
click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-table.rb, line 31 def self.fill_empty_td(table, max_col=nil) max_col = max_col(table) if max_col.nil? table.each_child_with_index {|tr, row| col_len = tr.children.length if col_len < max_col (max_col - col_len).times { tr << [:td, ''] } end } return nil end
make_th(table)
click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-table.rb, line 98 def self.make_th(table) each_td(table) {|td, col, row| td[0] = :th if row == 0 || col == 0 } end
max_col(table)
click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-table.rb, line 50 def self.max_col(table) max_col = 0 each_tr(table) {|tr, row| col_len = tr.children.length max_col = col_len if max_col < col_len } return max_col end
prepare(table)
click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-table.rb, line 19 def self.prepare(table) fill_empty_td(table) add_new_col(table) add_new_row(table) replace_with_input(table) make_th(table) set_new_col_and_new_row(table) add_new_col_button(table) add_new_row_button(table) return table end
replace_with_input(table)
click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-table.rb, line 82 def self.replace_with_input(table) max_len = Array.new(0) each_td(table) {|td, col, row| name = "t_#{col}_#{row}" text = td[1] len = text.length len = 1 if len < 1 max_len[col] ||= 0 max_len[col] = len if max_len[col] < len td[1] = [:input, {:name=>name, :value=>text}] } each_td(table) {|td, col, row| td[1].set_attr(:size=>max_len[col].to_s) } end
set_new_col_and_new_row(table)
click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-table.rb, line 104 def self.set_new_col_and_new_row(table) last_tr = table.last last_tr.set_attr(:class=>'new_row') each_tr(table) {|tr, row| tr.last.set_attr(:class=>'new_col') } end