activeadmin_table_footer 1.0.0 → 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: 3fa5ab83f8cc3ef9268b501ee4fd09d7fb3d1b6cab32b83dccc80a888bdec44e
4
- data.tar.gz: 506c5310ec7706b0314641334ab4558b92a2cdcd37e9d861fb6b6ee17adf1c73
3
+ metadata.gz: a9874aaf42089efb8297cda5f60411bad438d691a12098a19439f38d5986d308
4
+ data.tar.gz: fff210775c3c1e30d1ee09ae20d596ff7a684f0091f47209b9fbd95d9f3a0053
5
5
  SHA512:
6
- metadata.gz: c415a857de380ae03c0f90f3d0d47ecfb2b55fa7e8569f009bc6f4b550127ac11b3a39911e8f785738d03227abaeed6d614be605acd28b04d4cc2d0bc926c946
7
- data.tar.gz: 9498192db2a62f42d2f52f9e68a6e2aa038d4c2c9e5448e450128c4c4cb43cfecaa5ed4dab29c9dabf039c375ab9bb46ef58c295adb7bd5c7a9104dafb075653
6
+ metadata.gz: ef0407e70f5a3129e88db017a39bc252745fcaba6cc015783b445528b9f572bc694d957b28aef299f15214d09e0e84e0e76caee32c6f2d8b175dc28262637356
7
+ data.tar.gz: 89bf638f6ab6ff73023dd42de1ce8f62afc8305a11339e15347d00f626f0ccfea2896c5a562aa2eb243993c22780044d89963ab7907c870bb34615dabdf0b520
@@ -3,13 +3,11 @@
3
3
  require "rails/engine"
4
4
 
5
5
  module ActiveadminTableFooter
6
+ # Empty engine — kept so Rails recognizes this gem as an engine on
7
+ # boot. Patches are applied eagerly from
8
+ # `lib/activeadmin_table_footer.rb` so they are in place before AA
9
+ # resources are loaded (even when consuming engines `require` admin
10
+ # files from an initializer).
6
11
  class Engine < ::Rails::Engine
7
- config.to_prepare do
8
- require "activeadmin_table_footer/table_for_extension"
9
- require "activeadmin_table_footer/index_as_table_extension"
10
-
11
- ActiveAdmin::Views::TableFor.prepend(ActiveadminTableFooter::TableForExtension)
12
- ActiveAdmin::Views::IndexAsTable.prepend(ActiveadminTableFooter::IndexAsTableExtension)
13
- end
14
12
  end
15
13
  end
@@ -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.0"
4
+ VERSION = "1.0.2"
5
5
  end
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Load ActiveAdmin first so `ActiveAdmin::Views::TableFor` and
4
+ # `IndexAsTable` exist by the time we prepend onto them. AA doesn't
5
+ # publish a load hook for itself (only `:active_admin_controller`), and
6
+ # `config.to_prepare` would fire too late for engines that require AA
7
+ # resources from an initializer. Sibling plugins (active_admin_sidebar,
8
+ # etc.) use the same pattern.
9
+ require "activeadmin"
3
10
  require "activeadmin_table_footer/version"
4
11
  require "activeadmin_table_footer/styles"
5
12
 
@@ -22,3 +29,8 @@ module ActiveadminTableFooter
22
29
  end
23
30
 
24
31
  require "activeadmin_table_footer/engine" if defined?(Rails)
32
+ require "activeadmin_table_footer/table_for_extension"
33
+ require "activeadmin_table_footer/index_as_table_extension"
34
+
35
+ ActiveAdmin::Views::TableFor.prepend(ActiveadminTableFooter::TableForExtension)
36
+ ActiveAdmin::Views::IndexAsTable.prepend(ActiveadminTableFooter::IndexAsTableExtension)
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.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Fedoronchuk
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  requirements: []
103
- rubygems_version: 3.7.1
103
+ rubygems_version: 3.6.9
104
104
  specification_version: 4
105
105
  summary: Table footer DSL for ActiveAdmin index tables
106
106
  test_files: []