data-table 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a93c19ba22c5c189c7eb7c2523776ce2b97f3c62
4
- data.tar.gz: d31df8fbf78d197cd174a48ff1aff84ed1f3d465
3
+ metadata.gz: '0460569bde89f23e217c746e8a389733bf116696'
4
+ data.tar.gz: 29c4b0d8de0f82967dff15baa783011a94e74a68
5
5
  SHA512:
6
- metadata.gz: e58f9dd66a62c8b84d5ca9155775d887499b60526846652def4dbd277da321b5fecb19602c4a2382f296192823b7049623a32712703d8e08a0ab3d0fdaa7083a
7
- data.tar.gz: ce764c8ec13fcd513a7e7c21148da825128b7f4802f8873749acb5216c6c0362d8d73d8fd3f9bf9cef84519b6018722d6cf767ce2a01e99d71f58e07e0428be3
6
+ metadata.gz: d3330d311d3a62f0c42a431bdc19c307a283e3cdf4504c30371e311ad3b5330ad1c7d5ac96218dadfa25f6b3fc60efdbabc26137e1b470a8aa10cbc9b6e070fe
7
+ data.tar.gz: a817743f3b98df6fbed75e32172d969da426b33941bf6d4ab06909afa296d8d12cb337541b111c6dfd944074eb8983b9314330e2abbc9a77f34fc5cef034c0f6
data/data-table.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.licenses = ['Nonstandard']
8
8
  s.authors = ['Steve Erickson', 'Jeff Fraser']
9
9
  s.email = ['sixfeetover@gmail.com']
10
- s.homepage = 'https://github.com/sixfeetover/data-table'
10
+ s.homepage = 'https://github.com/veracross/data-table'
11
11
  s.summary = %(Turn arrays of hashes or models in to an HTML table.)
12
12
  s.description = %(data-table is a simple gem that provides a DSL for
13
13
  turning an array of hashes or ActiveRecord objects into an
@@ -268,6 +268,8 @@ module DataTable
268
268
  def render_parent_subtotals(group_array)
269
269
  html = ''
270
270
  @parent_subtotals[group_array].each_with_index do |group, index|
271
+ next if group.nil?
272
+
271
273
  html << "<tr class='parent_subtotal "
272
274
  html << "index_#{index} #{group_array.join('_').gsub(/\s/, '_').downcase}'>"
273
275
  @columns.each do |col|
@@ -1,3 +1,3 @@
1
1
  module DataTable
2
- VERSION = '2.0.1'.freeze
2
+ VERSION = '2.0.2'.freeze
3
3
  end
data/spec/table_spec.rb CHANGED
@@ -139,4 +139,136 @@ describe DataTable::Table do
139
139
  eq(%{<table id='' class='data_table ' cellspacing='0' cellpadding='0'><caption></caption><thead><tr></tr></thead><tr><td class='empty_data_table' colspan='0'>#{text}</td></tr></table>})
140
140
  end
141
141
  end
142
+
143
+ context 'with a more complicated setup' do
144
+ it 'renders okay' do
145
+ raw_results = [
146
+ { 'class' => 'Basketball', 'grade_level' => '9', 'points' => 50 },
147
+ { 'class' => 'Basketball', 'grade_level' => '9', 'points' => 51 },
148
+ { 'class' => 'Basketball', 'grade_level' => '10', 'points' => 52 },
149
+ { 'class' => 'Basketball', 'grade_level' => '10', 'points' => 53 },
150
+ { 'class' => 'Basketball', 'grade_level' => '10', 'points' => 54 },
151
+ { 'class' => 'Basketball', 'grade_level' => '12', 'points' => 55 }
152
+ ]
153
+
154
+ fields = [{
155
+ field_name: 'class',
156
+ display_description: 'Class',
157
+ column_width: 1.23,
158
+ data_type: 2
159
+ }, {
160
+ field_name: 'grade_level',
161
+ display_description: 'Grade Level',
162
+ column_width: 2.34,
163
+ data_type: 2
164
+ }, {
165
+ field_name: 'points',
166
+ display_description: 'Points',
167
+ column_width: 3.45,
168
+ data_type: 4
169
+ }]
170
+
171
+ column_groups = {}
172
+
173
+ subtotal_headers = [
174
+ { field_name: 'class' },
175
+ { field_name: 'grade_level' }
176
+ ]
177
+
178
+ subtotal_aggregates = {
179
+ sum: [],
180
+ avg: [{
181
+ field_name: 'points',
182
+ data_type: 4
183
+ }],
184
+ min: [],
185
+ max: []
186
+ }
187
+
188
+ total_aggregates = {
189
+ sum: [],
190
+ avg: [],
191
+ min: [],
192
+ max: []
193
+ }
194
+
195
+ has_aggregates = true
196
+
197
+ raw_results.each_with_index do |record, index|
198
+ record[:___data_table_index___] = index
199
+ end
200
+
201
+ html = DataTable.render(raw_results) do |t|
202
+ if has_aggregates
203
+ t.column :__subtotal_header__, '&nbsp;', width: '30px' do |_v|
204
+ '&nbsp;'
205
+ end
206
+ end
207
+
208
+ # COLUMN GROUPS
209
+ if column_groups.any?
210
+ t.custom_header do
211
+ th '', colspan: 1, css: 'column-group', style: 'width: 30px;' unless subtotal_headers.empty?
212
+
213
+ column_groups.each do |_column_group_index, column_group|
214
+ th column_group[:description], colspan: column_group[:column_count], css: 'column-group', style: "width: #{column_group_width}in;"
215
+ end
216
+
217
+ # spacer column
218
+ th '', colspan: 1, css: 'column-group'
219
+ end
220
+ end
221
+
222
+ # COLUMNS
223
+ fields.each do |field|
224
+ t.column field[:field_name], field[:display_description], css_class: "data-type-#{field[:data_type]}", width: field[:column_width] do |_v, record|
225
+ record[field[:field_name]]
226
+ end
227
+ end
228
+
229
+ # SUBTOTAL HEADERS
230
+ subtotal_headers.each_with_index do |subtotal_header, index|
231
+ t.group_by subtotal_header[:field_name], level: index
232
+ end
233
+
234
+ # SUBTOTAL AGGREGATES
235
+ unless subtotal_headers.empty?
236
+ subtotal_aggregates.each_with_index do |(aggregate_function, columns), index|
237
+ next if columns.empty?
238
+
239
+ t.subtotal :__subtotal_header__, nil, index do |_records, _column, path|
240
+ "#{path}: #{aggregate_function.to_s.upcase}"
241
+ end
242
+
243
+ columns.each do |column|
244
+ t.subtotal column[:field_name], aggregate_function, index do |value|
245
+ value
246
+ end
247
+ end
248
+ end
249
+ end
250
+
251
+ # TOTAL AGGREGATES
252
+ total_aggregates.each_with_index do |(aggregate_function, columns), index|
253
+ next if columns.empty?
254
+
255
+ t.total :__subtotal_header__, nil, index do |_records|
256
+ aggregate_function.to_s.upcase
257
+ end
258
+
259
+ columns.each do |column|
260
+ t.total column[:field_name], aggregate_function, index do |value|
261
+ value
262
+ end
263
+ end
264
+ end
265
+
266
+ # spacer column
267
+ t.column :_empty_space, ''
268
+ end
269
+
270
+ expected_html = %(<table id='' class='data_table ' cellspacing='0' cellpadding='0'><caption></caption><thead><tr><th class='__subtotal_header__ ' style='width: 30px'>&nbsp;</th><th class='points data-type-4' style='width: 3.45'>Points</th><th class='_empty_space ' ></th></tr></thead><tbody class='basketball'><tr class='group_header level_0'><th colspan='3'>Basketball</th></tr><tr class='group_header level_1'><th colspan='3'>9</th></tr><tr class='row_0 ' ><td class='__subtotal_header__ nilclass' >&nbsp;</td><td class='points numeric data-type-4' >50</td><td class='_empty_space nilclass' ></td></tr><tr class='row_1 alt ' ><td class='__subtotal_header__ nilclass' >&nbsp;</td><td class='points numeric data-type-4' >51</td><td class='_empty_space nilclass' ></td></tr><tr class='subtotal index_1 first'><td class='__subtotal_header__ nilclass' >9: AVG</td><td class='points numeric data-type-4' >50.5</td><td class='_empty_space nilclass' ></td></tr><tr class='group_header level_1'><th colspan='3'>10</th></tr><tr class='row_0 ' ><td class='__subtotal_header__ nilclass' >&nbsp;</td><td class='points numeric data-type-4' >52</td><td class='_empty_space nilclass' ></td></tr><tr class='row_1 alt ' ><td class='__subtotal_header__ nilclass' >&nbsp;</td><td class='points numeric data-type-4' >53</td><td class='_empty_space nilclass' ></td></tr><tr class='row_2 ' ><td class='__subtotal_header__ nilclass' >&nbsp;</td><td class='points numeric data-type-4' >54</td><td class='_empty_space nilclass' ></td></tr><tr class='subtotal index_1 first'><td class='__subtotal_header__ nilclass' >10: AVG</td><td class='points numeric data-type-4' >53.0</td><td class='_empty_space nilclass' ></td></tr><tr class='group_header level_1'><th colspan='3'>12</th></tr><tr class='row_0 ' ><td class='__subtotal_header__ nilclass' >&nbsp;</td><td class='points numeric data-type-4' >55</td><td class='_empty_space nilclass' ></td></tr><tr class='subtotal index_1 first'><td class='__subtotal_header__ nilclass' >12: AVG</td><td class='points numeric data-type-4' >55.0</td><td class='_empty_space nilclass' ></td></tr><tr class='parent_subtotal index_1 basketball'><td class='__subtotal_header__ nilclass' >Basketball: AVG</td><td class='points numeric data-type-4' >52.5</td><td class='_empty_space nilclass' ></td></tr></tbody></table>)
271
+ expect(html).to eq(expected_html)
272
+ end
273
+ end
142
274
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data-table
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Erickson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-11-12 00:00:00.000000000 Z
12
+ date: 2019-02-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -98,7 +98,7 @@ files:
98
98
  - spec/enum_spec.rb
99
99
  - spec/spec_helper.rb
100
100
  - spec/table_spec.rb
101
- homepage: https://github.com/sixfeetover/data-table
101
+ homepage: https://github.com/veracross/data-table
102
102
  licenses:
103
103
  - Nonstandard
104
104
  metadata: {}
@@ -122,9 +122,4 @@ rubygems_version: 2.6.14
122
122
  signing_key:
123
123
  specification_version: 4
124
124
  summary: Turn arrays of hashes or models in to an HTML table.
125
- test_files:
126
- - spec/column_spec.rb
127
- - spec/data_table_spec.rb
128
- - spec/enum_spec.rb
129
- - spec/spec_helper.rb
130
- - spec/table_spec.rb
125
+ test_files: []