Module: TableHelpers

Defined in:
lib/table_helpers.rb

Instance Method Summary collapse

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
# 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 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

    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((:th, column_name, :width => widths[i]))
    else
      headers.push((:th, column_name.html_safe).html_safe)
    end
    i += 1
  end

  headers.join.html_safe
end

#table_data(options = {}, &block) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/table_helpers.rb', line 65

def table_data(options = {}, &block)
  options[:label_size] ||= nil

  t = TableData.new(options[:label_size])

  result = (:table, :class => 'info') do
    block.call(t)
  end
end

#table_list(html_options = {}, &block) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/table_helpers.rb', line 53

def table_list(html_options = {}, &block)
  raise "need a block" unless block_given?
  
  t = TableList.new self
  
  result = capture do
     :table, html_options do
      block.call(t)
    end
  end
end