activeadmin_table_footer 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd4e5d13097968b6dd656ac4385181e8f2016951126737dff695a72453c5a9c8
4
- data.tar.gz: 19644d91c95753b13c2e7248ad1ac29802dc4dcb180316c3c657a82029c7044b
3
+ metadata.gz: a9874aaf42089efb8297cda5f60411bad438d691a12098a19439f38d5986d308
4
+ data.tar.gz: fff210775c3c1e30d1ee09ae20d596ff7a684f0091f47209b9fbd95d9f3a0053
5
5
  SHA512:
6
- metadata.gz: 95c22fca6a7286f3f1bb611658442f6938a07846298d80c713ce1d3de97e5f41405ea2cdc7163f3e53b990dd26ec12c1cb0d8191022378dfe8df45a50aaea067
7
- data.tar.gz: 24a2a4bab3736f134cb7bd5b7062b9a4b3c9dbb409da369adcf11eb83c6b33da3a6668e187545bd61e35190843dd5e909865ce4178fa0fe0a5869e629fc9302c
6
+ metadata.gz: ef0407e70f5a3129e88db017a39bc252745fcaba6cc015783b445528b9f572bc694d957b28aef299f15214d09e0e84e0e76caee32c6f2d8b175dc28262637356
7
+ data.tar.gz: 89bf638f6ab6ff73023dd42de1ce8f62afc8305a11339e15347d00f626f0ccfea2896c5a562aa2eb243993c22780044d89963ab7907c870bb34615dabdf0b520
@@ -7,17 +7,20 @@ module ActiveadminTableFooter
7
7
  module IndexAsTableExtension
8
8
  def build(page_presenter, collection)
9
9
  footer_proc = page_presenter[:footer_data]
10
+ return super unless footer_proc && page_presenter.block
10
11
 
11
- if footer_proc && page_presenter.block
12
- original_block = page_presenter.block
13
- wrapped = lambda do |table|
14
- table.instance_variable_set(:@footer_data_proc, footer_proc)
15
- instance_exec(table, &original_block)
16
- end
17
- page_presenter.instance_variable_set(:@block, wrapped)
12
+ original_block = page_presenter.block
13
+ wrapped = lambda do |table|
14
+ table.instance_variable_set(:@footer_data_proc, footer_proc)
15
+ instance_exec(table, &original_block)
18
16
  end
19
17
 
20
- super
18
+ # Render against a copy. ActiveAdmin builds one PagePresenter per
19
+ # `index do ... end` when it loads the resource and hands that same
20
+ # object to every render, so writing the wrapper back into the presenter
21
+ # would wrap the previous wrapper once per request — growing retained
22
+ # closures and block call depth until a render raises SystemStackError.
23
+ super(ActiveAdmin::PagePresenter.new(page_presenter.options, &wrapped), collection)
21
24
  end
22
25
  end
23
26
  end
@@ -8,10 +8,12 @@ module ActiveadminTableFooter
8
8
  super(obj, *attrs, options)
9
9
  end
10
10
 
11
+ # Any falsy callback means "no footer" — `&.` would only skip nil and raise
12
+ # on `footer_data: false`, which is what `footer_data: flag && ->(c) { ... }`
13
+ # passes when the flag is off.
11
14
  def footer_data
12
15
  return @footer_data if defined?(@footer_data)
13
- return (@footer_data = nil) unless @footer_data_proc
14
- @footer_data = @footer_data_proc.call(unscoped_collection_for_footer)
16
+ @footer_data = (@footer_data_proc.call(unscoped_collection_for_footer) if @footer_data_proc)
15
17
  end
16
18
 
17
19
  # The collection AA passes us is the paginated + ordered slice. Aggregates
@@ -49,14 +51,15 @@ module ActiveadminTableFooter
49
51
  def build_footer_cell_for(col)
50
52
  within @aatf_footer_row do
51
53
  column_key = column_key_for(col)
52
- # Always include `col col-<key>` so capybara_active_admin matchers
53
- # (`have_table_cell(column: ...)`) work in both AA 3 and AA 4 — the
54
- # selector convention is `td.col.col-<key>`.
55
- compat_classes = column_key ? "col col-#{column_key}" : "col"
56
- classes = [col.html_class, compat_classes, ActiveadminTableFooter.footer_th_class]
57
- .reject { |c| c.nil? || c.to_s.empty? }
58
- .join(" ")
59
- attrs = { class: classes.empty? ? nil : classes }
54
+ # `col` + `col-<key>` keeps capybara_active_admin's
55
+ # `have_table_cell(column: ...)` matcher working on AA 3 and AA 4.
56
+ classes = [
57
+ col.html_class,
58
+ "col",
59
+ ("col-#{column_key}" if column_key),
60
+ ActiveadminTableFooter.footer_th_class
61
+ ].compact_blank.join(" ").presence
62
+ attrs = { class: classes }
60
63
  attrs[:"data-column"] = column_key if column_key
61
64
  td(**attrs) do
62
65
  render_footer_value(col) if column_has_footer?(col)
@@ -66,12 +69,8 @@ module ActiveadminTableFooter
66
69
 
67
70
  def column_key_for(col)
68
71
  # AA 4 exposes Column#title_id; AA 3 does not — derive from title.
69
- if col.respond_to?(:title_id) && col.title_id.respond_to?(:presence)
70
- return col.title_id.presence
71
- end
72
- title = col.title.to_s
73
- return nil if title.empty?
74
- title.parameterize(separator: "_")
72
+ return col.title_id.presence if col.respond_to?(:title_id)
73
+ col.title.to_s.presence&.parameterize(separator: "_")
75
74
  end
76
75
 
77
76
  def ensure_tfoot!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveadminTableFooter
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin_table_footer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Fedoronchuk