greentable 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- greentable (0.9.3)
4
+ greentable (0.9.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -209,7 +209,7 @@ will produce
209
209
 
210
210
  ## Greentable Footer
211
211
 
212
- Sometime, you'll need to display a total (or whathaveyou) at the end:
212
+ Sometimes, you'll need to display a total (or whathaveyou) at the end:
213
213
 
214
214
  ```haml
215
215
  =greentable(products) do |gt, product|
@@ -254,6 +254,63 @@ will produce
254
254
  </table>
255
255
  ```
256
256
 
257
+ Subtotal, shipping, tax, total? No problem:
258
+
259
+ ```haml
260
+ =greentable(order.order_line_items) do |gt, order_line_item|
261
+ -gt.footer([:subtotal, :shipping, :tax, :total], class: 'klass') do |footer, attr|
262
+ -footer.col do
263
+ =attr
264
+ -footer.col do
265
+ =order.send(attr)
266
+
267
+ -gt.col('name') do
268
+ =order_line_item.name
269
+ -gt.col('price') do
270
+ =order_line_item.price
271
+ ```
272
+
273
+ will produce
274
+
275
+ ```html
276
+ <table>
277
+ <thead>
278
+ <tr>
279
+ <th>name</th>
280
+ <th>price</th>
281
+ </tr>
282
+ </thead>
283
+ <tbody>
284
+ <tr>
285
+ <td>ProductA</td>
286
+ <td>$2.11</td>
287
+ </tr>
288
+ <tr>
289
+ <td>ProductB</td>
290
+ <td>$1.03</td>
291
+ </tr>
292
+ </tbody>
293
+ <tfoot>
294
+ <tr>
295
+ <td class='klass'>subtotal</td>
296
+ <td class='klass'>xyz</td>
297
+ </tr>
298
+ <tr>
299
+ <td class='klass'>shipping</td>
300
+ <td class='klass'>xyz</td>
301
+ </tr>
302
+ <tr>
303
+ <td class='klass'>tax</td>
304
+ <td class='klass'>xyz</td>
305
+ </tr>
306
+ <tr>
307
+ <td class='klass'>total</td>
308
+ <td class='klass'>xyz</td>
309
+ </tr>
310
+ </tfoot>
311
+ </table>
312
+ ```
313
+
257
314
  ## Global Defaults
258
315
  You can configure global defaults for all your greentables.
259
316
 
@@ -45,13 +45,23 @@ module Greentable
45
45
  return nil
46
46
  end
47
47
 
48
- def footer(opts = {}, &block)
48
+ def footer(*args, &block)
49
49
  return unless @tfoot.empty?
50
+ if args.size == 1
51
+ rows = [nil]
52
+ opts = args[0]
53
+ elsif args.size == 2
54
+ rows = args[0]
55
+ opts = args[1]
56
+ else
57
+ raise 'greentable footer: number of arguments must be either 1 or two'
58
+ end
59
+
50
60
  @tfoot << '<tfoot>'
51
61
  tr_opts = deep_merge(@defaults_tr, opts.delete(:tr))
52
62
  td_opts = deep_merge(opts, opts.delete(:td))
53
63
  td_opts = deep_merge(@defaults_td, td_opts)
54
- TableGroup.new(@parent, [nil], {td: td_opts, tr: tr_opts}).process(&block).send(:to_s_tbody_content, @tfoot)
64
+ TableGroup.new(@parent, rows, {td: td_opts, tr: tr_opts}).process(&block).send(:to_s_tbody_content, @tfoot)
55
65
  @tfoot << '</tfoot>'
56
66
  end
57
67
 
@@ -1,3 +1,3 @@
1
1
  module Greentable
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.4"
3
3
  end
@@ -146,6 +146,42 @@ class GreentableTableTest < ActiveSupport::TestCase
146
146
  assert_equal "<table><thead><tr><th>col0</th></tr></thead><tbody><tr><td>0</td></tr></tbody><tfoot><tr class=\"tr_class\"><td style=\"a b\">peace</td><td style=\"a c\">out</td></tr></tfoot></table>", gt.to_s
147
147
  end
148
148
 
149
+ test "footer - with empty table" do
150
+ gt = Greentable::Table.new(self, [], {})
151
+ gt.process do |gt, x|
152
+ gt.footer do |footer|
153
+ footer.col do
154
+ 'peace'
155
+ end
156
+ footer.col do
157
+ 'out'
158
+ end
159
+ end
160
+ gt.col('col0') do
161
+ x
162
+ end
163
+ end
164
+ assert_equal "", gt.to_s
165
+ end
166
+
167
+ test "footer - with multiple rows" do
168
+ gt = Greentable::Table.new(self, [0], {})
169
+ gt.process do |gt, x|
170
+ gt.footer(['f1', 'f2'], :class => 'klass') do |footer, row|
171
+ footer.col do
172
+ 'Total'
173
+ end
174
+ footer.col do
175
+ row
176
+ end
177
+ end
178
+ gt.col('col0') do
179
+ x
180
+ end
181
+ end
182
+ assert_equal "<table><thead><tr><th>col0</th></tr></thead><tbody><tr><td>0</td></tr></tbody><tfoot><tr><td class=\"klass\">Total</td><td class=\"klass\">f1</td></tr><tr><td class=\"klass\">Total</td><td class=\"klass\">f2</td></tr></tfoot></table>", gt.to_s
183
+ end
184
+
149
185
  test "row_counter" do
150
186
  gt = Greentable::Table.new(self, [0, 1, 2], {})
151
187
  gt.process do |gt, x|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: greentable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-01 00:00:00.000000000 Z
12
+ date: 2014-04-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -247,7 +247,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
247
247
  version: '0'
248
248
  segments:
249
249
  - 0
250
- hash: -3412082307347015687
250
+ hash: -125976970667350695
251
251
  required_rubygems_version: !ruby/object:Gem::Requirement
252
252
  none: false
253
253
  requirements:
@@ -256,7 +256,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
256
256
  version: '0'
257
257
  segments:
258
258
  - 0
259
- hash: -3412082307347015687
259
+ hash: -125976970667350695
260
260
  requirements: []
261
261
  rubyforge_project:
262
262
  rubygems_version: 1.8.25