data-table 1.0.1 → 2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,60 +0,0 @@
1
- class DataTableColumn
2
-
3
- attr_reader :name
4
- attr_accessor :display, :index, :options, :css_class, :attributes
5
-
6
- def initialize(name, description="", opts={}, &renderer)
7
- @name, @description, = name, description
8
- @data_type = opts[:data_type] || :text
9
- @help_text = opts[:help_text] || ""
10
- @css_class = opts[:css_class]
11
- @attributes = opts[:attributes] || {}
12
- @width = opts[:width]
13
- @options = opts
14
-
15
- @display = true
16
- @index = 0
17
- @renderer = renderer
18
- end
19
-
20
- def render_cell(cell_data, row=nil, row_index=0, col_index=0)
21
- html = ""
22
- if @renderer && row
23
- cell_data = cell_data.to_s
24
- html << case @renderer.arity
25
- when 1; @renderer.call(cell_data).to_s
26
- when 2; @renderer.call(cell_data, row).to_s
27
- when 3; @renderer.call(cell_data, row, row_index).to_s
28
- when 4; @renderer.call(cell_data, row, row_index, self).to_s
29
- when 5; @renderer.call(cell_data, row, row_index, self, col_index).to_s
30
- end
31
- else
32
- html << cell_data.to_s
33
- end
34
-
35
- html << "</td>"
36
- # Doing this here b/c you can't change @css_class if this is done before the renderer is called
37
- html = "<td class='#{css_class_names}' #{custom_attributes}>" + html
38
- end
39
-
40
- def render_column_header
41
- header = "<th class='#{css_class_names}' #{custom_attributes}"
42
- header << "title='#{@help_text}' " if @help_text
43
- header << "style='width: #{@width}'" if @width
44
- header << ">#{@description}</th>"
45
- header
46
- end
47
-
48
- def custom_attributes
49
- @attributes.map{|k, v| "#{k}='#{v}'"}.join ' '
50
- end
51
-
52
- def css_class_names
53
- class_names = []
54
- class_names << @name.to_s
55
- class_names << @data_type.to_s
56
- class_names << @css_class
57
- class_names.compact.join(' ')
58
- end
59
-
60
- end