dining-table 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/VERSION +1 -1
- data/dining-table.gemspec +3 -3
- data/lib/dining-table/columns/column.rb +1 -0
- data/lib/dining-table/table.rb +4 -0
- data/spec/html_table_spec.rb +30 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5624a9625e338420410c971d0d7d14105cddd1a9
|
4
|
+
data.tar.gz: 55197b3b204db1726e9678761b490e4c26266f67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb6e4942a3224b25c866977ae72a1759e6793d49564848d6ee7a417351a9b92bdf4655757f8589c16ae9388b79bf3c7560cb09f9b268b1d4e75b50807ddf3011
|
7
|
+
data.tar.gz: 1a3d5ee3346a3d7ee25f30fb28e45a003f3f656f607af4e4ce19c0af713a01fc7fcf70dbd4f4282b6fe3da507840fe706c92cf19e439cc2284115f0b9d7f8b9d
|
data/README.md
CHANGED
@@ -95,7 +95,7 @@ class CarTable < DiningTable::Table
|
|
95
95
|
end
|
96
96
|
```
|
97
97
|
|
98
|
-
Please note how the collection passed in when creating the table
|
98
|
+
Please note how the collection passed in when creating the table object (`@cars` in `CarTable.new(@cars, self)`) is available as `collection`.
|
99
99
|
|
100
100
|
Similarly to `skip_header`, if for some reason you don't want a footer (even though at least one column defines one), call `skip_footer`:
|
101
101
|
|
@@ -107,6 +107,15 @@ class CarTable < DiningTable::Table
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
```
|
110
|
+
#### Empty collection
|
111
|
+
|
112
|
+
Note that when the collection to be presented in the table is empty, `dining-table` can't determine table headers
|
113
|
+
that aren't explicitly specified as there are no objects to use with `human_attribute_name`. In order to avoid this
|
114
|
+
edge case, you can pass in the class of the objects normally present in the collection when creating the table:
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
<%= CarTable.new(@cars, self, class: Car).render %>
|
118
|
+
```
|
110
119
|
|
111
120
|
### Links and view helpers
|
112
121
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/dining-table.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: dining-table 1.
|
5
|
+
# stub: dining-table 1.1.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "dining-table".freeze
|
9
|
-
s.version = "1.
|
9
|
+
s.version = "1.1.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Micha\u{eb}l Van Damme".freeze]
|
14
|
-
s.date = "2018-
|
14
|
+
s.date = "2018-11-28"
|
15
15
|
s.description = "Easily output tabular data, be it in HTML, CSV or XLSX. Create clean table classes instead of messing with views to create nice tables.".freeze
|
16
16
|
s.email = "michael.vandamme@vub.ac.be".freeze
|
17
17
|
s.extra_rdoc_files = [
|
@@ -26,6 +26,7 @@ module DiningTable
|
|
26
26
|
label = determine_label(:header)
|
27
27
|
return label if label
|
28
28
|
object_class = table.collection.first.class if table.collection.first
|
29
|
+
object_class ||= table.object_class if !object_class
|
29
30
|
object_class.human_attribute_name( name ) if object_class && object_class.respond_to?( :human_attribute_name )
|
30
31
|
end
|
31
32
|
end
|
data/lib/dining-table/table.rb
CHANGED
data/spec/html_table_spec.rb
CHANGED
@@ -36,7 +36,19 @@ describe 'HTMLTableSpec' do
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
|
+
it "correctly renders a table's header when the table body is empty and a class is provided" do
|
41
|
+
html = CarTable.new([], nil, :class => CarWithHumanAttributeName).render
|
42
|
+
doc = document( html )
|
43
|
+
[ 'Brand', 'Number of doors', 'Stock' ].each_with_index do |header, col_index|
|
44
|
+
xpath = "/table/thead/tr[1]/th[#{ col_index + 1 }]"
|
45
|
+
check_not_empty(doc.elements, xpath)
|
46
|
+
doc.elements.each(xpath) do |element|
|
47
|
+
element.text.must_equal header
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
40
52
|
it "correctly renders a table's header when explicit headers are defined" do
|
41
53
|
@cars = CarWithHumanAttributeName.collection
|
42
54
|
html = CarTableWithHeader.new(@cars, @view_context).render
|
@@ -55,6 +67,23 @@ describe 'HTMLTableSpec' do
|
|
55
67
|
end
|
56
68
|
end
|
57
69
|
|
70
|
+
it "correctly renders a table's header when explicit headers are defined and the table body is empty" do
|
71
|
+
html = CarTableWithHeader.new([], @view_context).render
|
72
|
+
doc = document( html )
|
73
|
+
[ 'The brand', 'The number of doors' ].each_with_index do |header, col_index|
|
74
|
+
xpath = "/table/thead/tr[1]/th[#{ col_index + 1 }]"
|
75
|
+
check_not_empty(doc.elements, xpath)
|
76
|
+
doc.elements.each(xpath) do |element|
|
77
|
+
element.text.must_equal header
|
78
|
+
end
|
79
|
+
end
|
80
|
+
# last header has link
|
81
|
+
doc.elements.each("/table/thead/tr[1]/th[3]/a") do |element|
|
82
|
+
element.text.must_equal 'Stock'
|
83
|
+
element.attributes.get_attribute('href').value.must_equal "http://www.google.com"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
58
87
|
it "correctly renders a table's footer when footers are defined" do
|
59
88
|
@cars = CarWithHumanAttributeName.collection
|
60
89
|
html = CarTableWithFooter.new(@cars, @view_context).render
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dining-table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michaël Van Damme
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|