Skip to content

Commit c2db44e

Browse files
committed
WIP: Add a few notes about the new changelog
1 parent d70f72b commit c2db44e

File tree

19 files changed

+298
-142
lines changed

19 files changed

+298
-142
lines changed

CHANGELOG-10.md

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
---
2+
icon: versions-24
3+
---
4+
5+
# CHANGELOG
6+
7+
## Release Policy
8+
9+
Pagy follows the [Semantic Versioning 2.0.0](https://semver.org/), and introduces BREAKING CHANGES only for MAYOR versions.
10+
11+
We release any new version (MAJOR, MINOR, PATCH) as soon as it is ready for release, regardless of any time constraint, frequency
12+
or duration.
13+
14+
We rarely deprecate elements (releasing a new MAYOR version is just simpler and more efficient). However, when we do, you can
15+
expect the old/deprecated functionality to be supported ONLY during the current MAYOR version.
16+
17+
## Recommended Version Constraint
18+
19+
Given a version number `MAJOR.MINOR.PATCH` (e.g. `10.0.0`):
20+
21+
The `gem 'pagy', '~> 10.0'` Gemfile entry (without the PATCH number) ensures that the `bundle update` command will update pagy to
22+
the most recent version WITHOUT BREAKING CHANGES.
23+
24+
Increment the MAYOR version in your Gemfile ONLY when you are ready to handle the BREAKING CHANGES.
25+
26+
## Breaking Changes
27+
28+
If you upgrade from version `< 10.0.0` see the following:
29+
30+
- [Breaking changes in version 10.0.0](#version-1000)
31+
- [Breaking changes in version 9.0.0](CHANGELOG_LEGACY.md#version-900)
32+
- [Breaking changes in version 8.0.0](CHANGELOG_LEGACY.md#version-800)
33+
- [Breaking changes in version 7.0.0](CHANGELOG_LEGACY.md#version-700)
34+
- [Breaking changes in version 6.0.0](CHANGELOG_LEGACY.md#version-600)
35+
- [Breaking changes in version 5.0.0](CHANGELOG_LEGACY.md#version-500)
36+
- [Breaking changes in version 4.0.0](CHANGELOG_LEGACY.md#version-400)
37+
- [Breaking changes in version 3.0.0](CHANGELOG_LEGACY.md#version-300)
38+
- [Breaking changes in version 2.0.0](CHANGELOG_LEGACY.md#version-200)
39+
- [Breaking changes in version 1.0.0](CHANGELOG_LEGACY.md#version-100)
40+
41+
## Deprecations
42+
43+
None
44+
45+
<hr>
46+
47+
## Version 10.0.0
48+
49+
### Overview
50+
51+
This is a mayor, MAYOR version, with important additions and improvements, a lot easier to use and customize, it has fewer methods
52+
and variables, cleaner code with a brand-new documentation and the new `Pagy AI`, ready to answer your questions.
53+
54+
### Keynav Pagination Addition
55+
56+
The pagy exclusive technique to use `keyset pagination with numeric pages, supporting `pagy_*navs` and other Frontend
57+
helpers.<br/>The best technique for performance AND functionality!
58+
59+
### Improvements
60+
61+
- Automatic loading of just the code that you actually use
62+
: Every class, module and helper is automatically loaded only if you actually use it, without any explicit `require`.
63+
_(the legacy version was requiring more code)_
64+
65+
- Better file and namespace system organization
66+
: The class hierarchy, the mixin files, and the test file structure have been deeply reorganized.
67+
: The code is cleaner, more concise and more readable, adding fewer modules in the `ancestors` array of yur app.
68+
69+
- The extras are almost all gone
70+
: They have been converted to autoloaded mixins, or integrated in the core code at zero-cost. You can use the methods that you
71+
need, and they will just work without explicit requiring.
72+
: The only extras that are left _(for different compelling reasons)_ are: `gearbox`, `i18n` and `size`. They must be required in
73+
the initializer as usual.
74+
75+
- The Pagy::Countless remembers the last page
76+
: When you jump back in the page nav, it remembers the current page count, so you can jump forward.
77+
78+
- Cleaner URLs
79+
: No more empty params or extra '?' in the url string
80+
: URL templates are safer for string manipulation.
81+
: The `pagy_page_url` (legacy `pagy_url_for`) can be used also without a request (incorporating the legacy `standalone` extra)
82+
83+
- Javascript refactoring
84+
: Updated the support for the pagy helpers and keynav pagination.
85+
: Added the plain `pagy.js` and relative source map.
86+
87+
### Breaking Changes
88+
89+
#### Core Changes
90+
91+
- The `Pagy::DEFAULT` is now frozen.
92+
: Remove all the `Pagy::DEFAULT` variables from your code and pass their variables to the constructor. As an alternative to
93+
avoid repetitions, define your own `PAGY_DEFAULT = {...}` hash and pass it to the different constructors:
94+
`pagy_offset(scope, **PAGY_DEFAULT, ...)`
95+
96+
- Direct instantiation of the pagy constructor classes is not recommended.
97+
: Use the provided constructor helpers for easier usage, maintenance and forward compatibility.
98+
99+
- Replace the existing (if any) `Pagy.root` with `Pagy::ROOT`
100+
- When the `:params` variable is set to a lambda, it should modify the passed `query_params` directly. The returned value is now
101+
ignored for a sligtly better performance.
102+
103+
#### Simple renaming (without logic changes)
104+
105+
| Type | Search | Replace | Notes |
106+
|-------------|----------------|-----------------|----------------------------------------------------------|
107+
| Constructor | `pagy(` | `pagy_offset(` | For consistency with the other old and new constructors |
108+
| Method | `pagy_url_for` | `pagy_page_url` | The legacy naming was causing rails-related expectations |
109+
110+
#### Extras Replacement
111+
112+
##### `arel`, `array`, `boostrap`, `bulma`, `calendar`, `countless`, `headers`, `keyset`, `pagy`
113+
114+
- Just remove the `require 'pagy/extras/<extra-name>'` from the initializer, and continue to use their features without changes.
115+
116+
##### `elasticsearch_rails`, `meilisearch`, `searchkick`
117+
118+
- Remove the `require 'pagy/extras/<extra-name>'` from the initializer
119+
- Replace your existing (if any) `Pagy.new_from_<extra-name>` with `pagy_<extra-name>`. _(Active and passive modes are now handled
120+
by the same helper.)_
121+
- Replace the existing (if any) `extend Pagy::Search` statement in your models with `extend Pagy::Offset::Search`.
122+
- The `pagy_search` name customization has been discontinued. Remove the existing (if any) `:<extra-name>_pagy_search`
123+
variable from your code, and use the standard `pagy_search` method.
124+
- Rename the existing (if any) `:<extra-name>_search` variable as `:search_method` and pass it to the constructor.
125+
126+
##### `jsonapi`
127+
128+
- Remove the `require 'pagy/extras/jsonapi'` from the initializer.
129+
- Rename `pagy_jsonapi_links` as `pagy_links`. Notice that the `nil` links are now removed as the `JSON:API`
130+
requires.
131+
- You should pass the `:jsonapi` variable to the constructor when you want to trigger the feature.
132+
133+
##### `limit`
134+
135+
- Remove the `require 'pagy/extras/limit'` from the initializer.
136+
- You should pass the `:maxable_limit` variable - set to the max limit allowed - to the constructor when you want to trigger the
137+
feature.
138+
139+
##### `metadata`
140+
141+
- Remove the `require 'pagy/extras/metadata'` from the initializer.
142+
- Rename the existing (if any) `:scaffold_url` to `url_template`
143+
144+
##### `overflow`
145+
146+
- Remove the `require 'pagy/extras/overflow'` from the initializer.
147+
- You should pass the `:overflow: ...` variable to the constructor when you want to trigger the feature.
148+
149+
#### `standlone`
150+
151+
- Remove the `require 'pagy/extras/standalone'` from the initializer.
152+
- Replace the `:url` variable with `:request`, and its content with `{ url_prefix: 'the-previous-value-of-url' }`. You can also
153+
optionally add your `query_params` hash. For example `{ query_params: { param1: 'abc', param2: 'def' }` for complete control
154+
over the generated url.
155+
156+
##### `trim` (discontinued)
157+
158+
- It was mostly useless and half backed, causing a lot of complications in the ruby and javascript code.
159+
- Use a proper way to address your requirement, like using URL rewriting at the HTTP server level.
160+
161+
##### `gearbox`
162+
163+
- Remove the `:gearbox_extra` variable from your code
164+
- You should pass the `gearbox_limit: [...]` variable to the constructor when you want to trigger the feature.
165+
166+
##### `i18n`, `size`
167+
168+
- No change required.
169+
170+
#### Possibly Breaking Overridings
171+
172+
- The internal Pagy protected methods have been renamed and refactored. If you use custom Pagy classes, you may need to search
173+
into the code.
174+
175+
[LEGACY CHANGELOG >>>](CHANGELOG_LEGACY.md)

docs/api/keyset_for_ui.md renamed to docs/api/keynav.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ You should also familiarize with the [Pagy::Keyset](keyset.md) class.
3131

3232
## Glossary
3333

34-
This section integrates the [Keyset Glossary](keyset_for_ui.md#glossary)
34+
This section integrates the [Keyset Glossary](keynav#glossary)
3535

36-
| Term | Description |
37-
|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
38-
| `keyset augmented pagination` | The pagy exclusive technique to use `keyset pagination` with numeric pages, supporting `pagy_*navs` and other Frontend helpers.<br/>The best technique for performance AND functionality! |
39-
| `page` | The array of variables from the client prepared by the `keyset_for_ui` extra, to paginate the requested page. |
40-
| `cutoffs` | The array of `cutoff`s of the known pagination state, used to keep track of the visited pages during the navigation. They are cached in the `sessionStorge` of the client. |
36+
| Term | Description |
37+
|---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
38+
| `keynav pagination` | The pagy exclusive technique to use `keyset pagination` with numeric pages, supporting `pagy_*navs` and other Frontend helpers.<br/>The best technique for performance AND functionality! |
39+
| `page` | The array of variables from the client prepared by the `keyset_for_ui` extra, to paginate the requested page. |
40+
| `cutoffs` | The array of `cutoff`s of the known pagination state, used to keep track of the visited pages during the navigation. They are cached in the `sessionStorge` of the client. |
4141

4242
## How Pagy Keyset For UI works
4343

docs/extras/keyset_for_ui.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ and other Frontend helpers.
1717

1818
## Overview
1919

20-
This is a wrapper around the [Pagy::Keyset::Keynav API](/docs/api/keyset_for_ui.md). Please refer to the following resources:
20+
This is a wrapper around the [Pagy::Keyset::Keynav API](/docs/api/keynav). Please refer to the following resources:
2121

22-
[!ref Keyset For UI: Documentation](/docs/api/keyset_for_ui.md)
22+
[!ref Keyset For UI: Documentation](/docs/api/keynav)
2323

2424
[!ref Keyset Pagination: Concepts and Overview](/docs/api/keyset.md)
2525

gem/apps/demo.ru

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,18 @@ STYLES = { pagy: { extra: 'pagy', prefix: '', css_anchor: 'pagy-scss' },
4646
# Sinatra setup
4747
require 'sinatra/base'
4848

49-
# Pagy initializer
50-
Pagy::DEFAULT[:limit_requestable] = true
51-
5249
# Sinatra application
5350
class PagyDemo < Sinatra::Base
5451
include Pagy::Backend
52+
PAGY_DEFAULT = { maxable_limit: 100 }.freeze
5553

5654
get '/' do
5755
redirect '/pagy'
5856
end
5957

6058
get '/template' do
6159
collection = MockCollection.new
62-
@pagy, @records = pagy_offset(collection)
60+
@pagy, @records = pagy_offset(collection, **PAGY_DEFAULT)
6361

6462
erb :template, locals: { pagy: @pagy, style: 'pagy' }
6563
end
@@ -85,7 +83,7 @@ class PagyDemo < Sinatra::Base
8583

8684
get("/#{style}") do
8785
collection = MockCollection.new
88-
@pagy, @records = pagy_offset(collection)
86+
@pagy, @records = pagy_offset(collection, **PAGY_DEFAULT)
8987

9088
erb :helpers, locals: { style:, prefix: }
9189
end

gem/apps/keynav.ru

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,12 @@ gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
3030
gem 'sqlite3'
3131
end
3232

33-
# Pagy initializer
34-
Pagy::DEFAULT[:limit] = 4
35-
Pagy::DEFAULT[:limit_requestable] = true
36-
3733
# Sinatra setup
3834
require 'sinatra/base'
3935
# Sinatra application
4036
class PagyKeynav < Sinatra::Base
4137
include Pagy::Backend
38+
PAGY_DEFAULT = { limit: 4, maxable_limit: 100 }.freeze
4239

4340
get('/javascripts/:file') do
4441
format = params[:file].split('.').last
@@ -54,9 +51,9 @@ class PagyKeynav < Sinatra::Base
5451
get '/' do
5552
Time.zone = 'UTC'
5653

57-
@order = { animal: :asc, name: :asc, birthdate: :desc, id: :asc }
58-
@pagy, @pets = pagy_keynav_js(Pet.order(@order))
59-
@ids = @pets.pluck(:id)
54+
@order = { animal: :asc, name: :asc, birthdate: :desc, id: :asc }
55+
@pagy, @pets = pagy_keynav_js(Pet.order(@order), **PAGY_DEFAULT)
56+
@ids = @pets.pluck(:id)
6057
erb :main
6158
end
6259

@@ -164,10 +161,10 @@ require 'active_record'
164161
# ActiveSupport::JSON::Encoding.time_precision = 6
165162

166163
# Log
167-
output = ENV['APP_ENV'].equal?('showcase') ? IO::NULL : $stdout
164+
output = ENV['APP_ENV'].equal?('showcase') ? IO::NULL : $stdout
168165
ActiveRecord::Base.logger = Logger.new(output)
169166
# SQLite DB files
170-
dir = ENV['APP_ENV'].equal?('development') ? '.' : Dir.pwd # app dir in dev or pwd otherwise
167+
dir = ENV['APP_ENV'].equal?('development') ? '.' : Dir.pwd # app dir in dev or pwd otherwise
171168
abort "ERROR: Cannot create DB files: the directory #{dir.inspect} is not writable." \
172169
unless File.writable?(dir)
173170
# Connection

gem/apps/keyset.ru

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,13 @@ gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
3030
gem 'sqlite3'
3131
end
3232

33-
# Pagy initializer
34-
Pagy::DEFAULT[:limit] = 10
35-
Pagy::DEFAULT[:limit_requestable] = true
36-
3733
# Sinatra setup
3834
require 'sinatra/base'
3935
# Sinatra application
4036
class PagyKeyset < Sinatra::Base
4137
include Pagy::Backend
38+
PAGY_DEFAULT = { limit: 10, maxable_limit: 100 }.freeze
39+
4240
# Root route/action
4341
get '/' do
4442
Time.zone = 'UTC'

gem/apps/keyset_sequel.ru

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
3030
gem 'sqlite3'
3131
end
3232

33-
# Pagy initializer
34-
Pagy::DEFAULT[:limit] = 10
35-
Pagy::DEFAULT[:limit_requestable] = true
36-
3733
# Sinatra setup
3834
require 'sinatra/base'
3935
require 'logger'
4036
# Sinatra application
4137
class PagyKeysetSequel < Sinatra::Base
4238
include Pagy::Backend
39+
PAGY_DEFAULT = { limit: 10, maxable_limit: 100 }.freeze
40+
4341
# Root route/action
4442
get '/' do
4543
@order = { animal: :asc, name: :asc, birthdate: :desc, id: :asc }

gem/apps/rails.ru

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,12 @@ class PagyRails < Rails::Application # :nodoc:
5252
end
5353

5454
# AR config
55-
dir = Rails.env.development? ? '.' : Dir.pwd # app dir in dev or pwd otherwise
55+
dir = Rails.env.development? ? '.' : Dir.pwd # app dir in dev or pwd otherwise
5656
unless File.writable?(dir)
5757
warn "ERROR: directory #{dir.inspect} is not writable (the pagy-rails-app needs to create DB files)"
5858
exit 1
5959
end
6060

61-
# Pagy initializer
62-
Pagy::DEFAULT[:limit] = 10
63-
Pagy::DEFAULT[:limit_requestable] = true
64-
Pagy::Offset::DEFAULT[:overflow] = :empty_page
65-
6661
# Activerecord initializer
6762
ActiveRecord::Base.logger = Logger.new(OUTPUT)
6863
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: "#{dir}/tmp/pagy-rails.sqlite3")
@@ -80,11 +75,15 @@ end
8075
# Models
8176
class Post < ActiveRecord::Base # :nodoc:
8277
has_many :comments
83-
end # :nodoc:
78+
end
79+
80+
# :nodoc:
8481

8582
class Comment < ActiveRecord::Base # :nodoc:
8683
belongs_to :post
87-
end # :nodoc:
84+
end
85+
86+
# :nodoc:
8887

8988
# Unused model, useful to test overriding conflicts
9089
module Calendar
@@ -107,10 +106,13 @@ end
107106
class CommentsController < ActionController::Base # :nodoc:
108107
include Rails.application.routes.url_helpers
109108
include Pagy::Backend
109+
PAGY_DEFAULT = { limit: 10,
110+
maxable_limit: 100,
111+
overflow: :empty_page }.freeze
110112

111113
def index
112-
@pagy, @comments = pagy_offset(Comment.all)
113-
pagy_headers_merge(@pagy)
114+
@pagy, @comments = pagy_offset(Comment.all, **PAGY_DEFAULT)
115+
# pagy_headers_merge(@pagy)
114116
render inline: TEMPLATE
115117
end
116118
end

gem/apps/repro.ru

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,15 @@ gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
2929
gem 'sinatra'
3030
end
3131

32-
# Edit this section adding/removing the extras and Pagy::DEFAULT as needed
32+
# Edit this section adding the extras as needed
3333
# pagy initializer
34-
# Pagy::Offset::DEFAULT[:overflow] = :empty_page
35-
# Pagy::DEFAULT[:limit_requestable] = true
3634

3735
# Sinatra setup
3836
require 'sinatra/base'
3937
# Sinatra application
4038
class PagyRepro < Sinatra::Base
41-
PAGY_DEFAULT = { overflow: :empty_page, limit_requestable: true }.freeze
42-
4339
include Pagy::Backend
40+
PAGY_DEFAULT = { maxable_limit: 100, overflow: :empty_page }.freeze
4441

4542
get('/javascripts/:file') do
4643
format = params[:file].split('.').last

0 commit comments

Comments
 (0)