data-table 1.0.1 → 2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Guardfile +48 -0
- data/README.md +128 -12
- data/Rakefile +5 -0
- data/assigments_table.html +56 -0
- data/data-table.gemspec +19 -12
- data/examples/all_features.rb +161 -0
- data/lib/data-table.rb +62 -3
- data/lib/data-table/column.rb +75 -0
- data/lib/data-table/enum.rb +57 -0
- data/lib/data-table/table.rb +443 -0
- data/lib/data-table/version.rb +2 -2
- data/rebuild_gem.rb +11 -0
- data/spec/column_spec.rb +41 -0
- data/spec/data_table_spec.rb +22 -0
- data/spec/enum_spec.rb +36 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/table_spec.rb +100 -0
- metadata +91 -17
- data/lib/data-table/data_table.rb +0 -385
- data/lib/data-table/data_table_column.rb +0 -60
@@ -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
|