Module: TableHelpers
- Defined in:
- lib/table_helpers.rb
Instance Method Summary collapse
- #get_sortable_table_headers(columns = [], widths = {}) ⇒ Object
- #get_table_headers(columns = [], widths = {}) ⇒ Object
- #table_data(options = {}, &block) ⇒ Object
- #table_list(html_options = {}, &block) ⇒ Object
Instance Method Details
#get_sortable_table_headers(columns = [], widths = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/table_helpers.rb', line 22 def get_sortable_table_headers(columns=[], widths={}) headers = [] p = params i = 1 for j in 0 .. columns.length - 1 column_name = columns[j][0] sort_columns = columns[j][1..columns[j].length-1] if sort_columns.present? if params[:order_by] == sort_columns.join(', ') link = link_to(column_name, p.merge('order_by' => "#{sort_columns.join(' DESC, ') + ' DESC'}"), :class=> "sortdown") elsif params[:order_by] == sort_columns.join(' DESC, ') + ' DESC' link = link_to(column_name, p.merge('order_by' => sort_columns.join(', ')), :class=> "sortup") else link = link_to(column_name, p.merge('order_by' => sort_columns.join(', ')), :class=> "sort-none") end if widths.has_key?(i) headers.push("<th width=\"%s\">%s</th>" % [widths[i],link]) else headers.push("<th>%s</th>" % [link]) end elsif column_name.present? headers.push('<th>%s</th>' % column_name) else headers.push('<th></th>') end i += 1 j += 1 end headers.join.html_safe end |
#get_table_headers(columns = [], widths = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/table_helpers.rb', line 5 def get_table_headers(columns=[], widths={}) headers = [] i = 1 for column_name in columns if widths.has_key?(i) headers.push(content_tag(:th, column_name, :width => widths[i])) else headers.push(content_tag(:th, column_name.html_safe).html_safe) end i += 1 end headers.join.html_safe end |
#table_data(options = {}, &block) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/table_helpers.rb', line 71 def table_data( = {}, &block) [:label_size] ||= nil t = TableData.new([:label_size]) result = content_tag(:table, :class => 'info') do block.call(t) end end |
#table_list(html_options = {}, &block) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/table_helpers.rb', line 59 def table_list( = {}, &block) raise "need a block" unless block_given? t = TableList.new self result = capture do content_tag :table, do block.call(t) end end end |