pagy 43.2.1 → 43.2.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.
data/lib/pagy.rb CHANGED
@@ -8,7 +8,7 @@ require_relative 'pagy/toolbox/helpers/loader'
8
8
 
9
9
  # Top superclass: it defines only what's common to all the subclasses
10
10
  class Pagy
11
- VERSION = '43.2.1'
11
+ VERSION = '43.2.2'
12
12
  ROOT = Pathname.new(__dir__).parent.freeze
13
13
  DEFAULT = { limit: 20, limit_key: 'limit', page_key: 'page' }.freeze
14
14
  PAGE_TOKEN = EscapedValue.new('P ')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagy
3
3
  version: !ruby/object:Gem::Version
4
- version: 43.2.1
4
+ version: 43.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Domizio Demichelis
@@ -48,13 +48,13 @@ files:
48
48
  - LICENSE.txt
49
49
  - apps/calendar.ru
50
50
  - apps/demo.ru
51
+ - apps/enable_rails_page_segment.rb
51
52
  - apps/index.rb
52
53
  - apps/keynav+root_key.ru
53
54
  - apps/keynav.ru
54
55
  - apps/keyset.ru
55
56
  - apps/keyset_sequel.ru
56
57
  - apps/rails.ru
57
- - apps/rails_page_segment.rb
58
58
  - apps/repro.ru
59
59
  - bin/pagy
60
60
  - config/pagy.rb
@@ -65,7 +65,6 @@ files:
65
65
  - javascripts/pagy.min.js
66
66
  - javascripts/pagy.mjs
67
67
  - javascripts/wand.js
68
- - lib/optimist.rb
69
68
  - lib/pagy.rb
70
69
  - lib/pagy/classes/calendar/calendar.rb
71
70
  - lib/pagy/classes/calendar/day.rb
@@ -84,6 +83,7 @@ files:
84
83
  - lib/pagy/classes/offset/offset.rb
85
84
  - lib/pagy/classes/offset/search.rb
86
85
  - lib/pagy/classes/request.rb
86
+ - lib/pagy/cli.rb
87
87
  - lib/pagy/console.rb
88
88
  - lib/pagy/modules/abilities/configurable.rb
89
89
  - lib/pagy/modules/abilities/countable.rb
@@ -1,71 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # ################# IMPORTANT WARNING #################
4
- # Use this override ONLY if you strictly need to support the page param as a dynamic segment.
5
- # (e.g. get '/comments(/:page)', to: 'comments#index').
6
- #
7
- # This setup forces Pagy to use the Rails `url_for` method, which is significantly
8
- # slower (~20x) than Pagy's native URL generation.
9
- # #####################################################
10
-
11
- # 1. CONSTANT REDEFINITION
12
- # We must replace Pagy's internal tokens.
13
- # Why: Pagy marks its default tokens as "Escaped" to allow spaces into the URL template for safe interpolation.
14
- # Since we are handing control back to Rails' standard QueryUtils, we need simple, URL-safe placeholders
15
- # that Rails won't need to escape, to avoid mismatches between non-escaped and escaped tokens.
16
- Pagy.send(:remove_const, :PAGE_TOKEN)
17
- Pagy.send(:remove_const, :LIMIT_TOKEN)
18
-
19
- Pagy::PAGE_TOKEN = '___PAGY_PAGE___'
20
- Pagy::LIMIT_TOKEN = '___PAGY_LIMIT___'
21
-
22
- require 'pagy/toolbox/paginators/method'
23
- require 'pagy/modules/abilities/linkable'
24
-
25
- class Pagy
26
- # 2. REQUEST PARAMETERS
27
- # Why: Pagy defaults to Rack::Request to be framework agnostic.
28
- # To support dynamic segments (which are routing concepts, not query params),
29
- # we must switch to the Rails `request.params` method which includes path parameters.
30
- module RequestOverride
31
- def get_params(request)
32
- request.params
33
- end
34
- end
35
- Request.prepend RequestOverride
36
-
37
- # 3. CONTEXT INJECTION
38
- # Why: The Pagy object needs access to the Controller instance to call `url_for`.
39
- # We intercept the `pagy` method in the controller to inject `self` (the controller)
40
- # into the Pagy instance as `@context`.
41
- module MethodOverride
42
- def pagy(...)
43
- super.tap do |result|
44
- # result is [pagy_object, records]
45
- # We inject the controller (self) directly into the pagy object
46
- result[0].instance_variable_set(:@context, self)
47
- end
48
- end
49
- end
50
- Method.prepend MethodOverride
51
-
52
- # 4. URL GENERATION
53
- # Why: We override Pagy's optimized string interpolation with Rails' `url_for`.
54
- # We combine the current Rails parameters with Pagy's options and generate the URL.
55
- module LinkableOverride
56
- def compose_url(absolute, _path, params, fragment)
57
- params[:anchor] = fragment if fragment
58
- params[:only_path] = !absolute
59
-
60
- # Call the Rails url_for method from the controller context
61
- @context.url_for(params)
62
- end
63
- end
64
- Linkable.prepend LinkableOverride
65
- end
66
-
67
- # USAGE with rails.ru
68
-
69
- # Search and uncomment the following lines in the rails.ru app:
70
- # require_relative 'rails_page_segment' # Uncomment to test the rails_page_segment.rb override
71
- # get '/comments(/:page)', to: 'comments#index' # Uncomment to test the rails_page_segment.rb override