katalyst-tables 3.10.0 → 3.11.1

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: 1f28bfdf9aae3a6cf0fc5822baa12cfe8da12dbd23b4a3b28c2bd6b816fad9f2
4
- data.tar.gz: 31828abc1872970d1d9f7280ff166074e5cd8444ccdcc599a9bcf03095296a0b
3
+ metadata.gz: 1e8456c713efa8b079198dff2fd156ba028258ff09eb056b6a9a95cc5eb1aeaf
4
+ data.tar.gz: 4f6045cabeecbb034134151167dae9e9ce1c0f8744e32576829665fde2ec9117
5
5
  SHA512:
6
- metadata.gz: ac366753b188bb5a4d90da55fda2b6e285ca5640681a5aac053decad8ca499cded748569875de0647439cc08691830fed2517b01e05bc0308d8aa6b13a23b38d
7
- data.tar.gz: a15ba7a25da90dda2bb5a235977d67c1ee8807058b83799ef6e56f15c16d7f573d0e44d11a511736a9669ac5184563c4e51579a4e930061f5917c29f8b5b398f
6
+ metadata.gz: b22f53a017c4e9120fab8d73fedc699d929c5ce855e659ce67cc20a592b27dd0400111ace41ddf0d0b5cc9646a5836263b82c564b3ed795fc2fff9b8137b7f61
7
+ data.tar.gz: 8bee047ee8e2ca64e849f8735a87f1f917ef4a83d757b9372d9be3e1f176a17de390ac0f57cab1140d967cc4dbc1c94496a9c5063bf68dc69cbbe5ddc6fd962e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [3.11.0]
2
+
3
+ * Support for Pagy 43
4
+
1
5
  ## [3.10.0]
2
6
 
3
7
  * Support for Rails 8.1
@@ -8,7 +8,15 @@ module Katalyst
8
8
  "Pagy::Frontend".safe_constantize&.tap { |pagy| include(pagy) }
9
9
 
10
10
  def self.pagy_legacy?
11
- Pagy::VERSION.scan(/\d+/).first.to_i <= 8
11
+ pagy_major < 43
12
+ end
13
+
14
+ def self.pagy_pre_8?
15
+ pagy_major < 8
16
+ end
17
+
18
+ def self.pagy_major
19
+ @pagy_major ||= Pagy::VERSION.scan(/\d+/).first.to_i
12
20
  end
13
21
 
14
22
  delegate :pagy_legacy?, to: :class
@@ -25,7 +33,7 @@ module Katalyst
25
33
  end
26
34
 
27
35
  def call
28
- pagy_nav(@pagy, **pagy_options).html_safe # rubocop:disable Rails/OutputSafety
36
+ render_nav.html_safe # rubocop:disable Rails/OutputSafety
29
37
  end
30
38
 
31
39
  def pagy_options
@@ -38,6 +46,12 @@ module Katalyst
38
46
 
39
47
  private
40
48
 
49
+ def render_nav
50
+ return pagy_nav(@pagy, **pagy_options) if pagy_legacy?
51
+
52
+ @pagy.series_nav(**pagy_options)
53
+ end
54
+
41
55
  def default_pagy_options
42
56
  pagy_legacy? ? {} : { anchor_string: 'data-turbo-action="replace"' }
43
57
  end
@@ -3,18 +3,25 @@
3
3
  module Katalyst
4
4
  module Tables
5
5
  module Collection
6
+ class Config
7
+ attr_accessor :paginate, :sorting
8
+ end
9
+
6
10
  module Core # :nodoc:
7
11
  extend ActiveSupport::Concern
8
12
 
9
13
  include ActiveModel::Model
10
14
  include ActiveModel::Attributes
11
15
  include ActiveModel::Dirty
12
- include ActiveSupport::Configurable
13
16
 
14
17
  include HasParams
15
18
  include Reducers
16
19
 
17
20
  class_methods do
21
+ def config
22
+ @config ||= Config.new
23
+ end
24
+
18
25
  def permitted_params
19
26
  _default_attributes.to_h.each_with_object([]) do |(k, v), h|
20
27
  h << case v
@@ -20,11 +20,9 @@ module Katalyst
20
20
  attr_accessor :pagination
21
21
 
22
22
  attribute :page, :integer, default: 1, filter: false
23
-
24
- config_accessor :paginate
25
23
  end
26
24
 
27
- def initialize(paginate: config.paginate, **)
25
+ def initialize(paginate: self.class.config.paginate, **)
28
26
  super(**)
29
27
 
30
28
  @paginate = paginate.freeze
@@ -38,7 +36,7 @@ module Katalyst
38
36
  opts = @paginate.is_a?(Hash) ? @paginate : {}
39
37
  opts = opts.dup
40
38
 
41
- if PagyNavComponent.pagy_legacy?
39
+ if PagyNavComponent.pagy_pre_8?
42
40
  opts[:anchor_string] ||= "data-turbo-action=\"replace\""
43
41
  end
44
42
 
@@ -48,7 +46,11 @@ module Katalyst
48
46
  class Paginate # :nodoc:
49
47
  # Pagy is not a required gem unless you're using pagination
50
48
  # Expect to see NoMethodError failures if pagy is not available
51
- "Pagy::Backend".safe_constantize&.tap { |pagy| include(pagy) }
49
+ if (pagy_method = "Pagy::Method".safe_constantize)
50
+ include(pagy_method)
51
+ else
52
+ "Pagy::Backend".safe_constantize&.tap { |pagy| include(pagy) }
53
+ end
52
54
 
53
55
  def initialize(app)
54
56
  @app = app
@@ -64,7 +66,12 @@ module Katalyst
64
66
 
65
67
  # pagy shim
66
68
  def params
67
- @collection.attributes.with_indifferent_access
69
+ @collection.to_params
70
+ end
71
+
72
+ # Pagy 43 expects a request object; provide the minimal hash interface it supports.
73
+ def request
74
+ { base_url: nil, path: nil, params:, cookie: nil }
68
75
  end
69
76
  end
70
77
  end
@@ -55,7 +55,7 @@ module Katalyst
55
55
  attr_reader :default_sort
56
56
  end
57
57
 
58
- def initialize(sorting: config.sorting, **)
58
+ def initialize(sorting: self.class.config.sorting, **)
59
59
  @default_sort = sorting.to_param if sorting.present?
60
60
 
61
61
  super(sort: @default_sort, **) # set default sort based on config
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: katalyst-tables
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.10.0
4
+ version: 3.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katalyst Interactive