You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api/frontend.md
+2-4Lines changed: 2 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -90,8 +90,6 @@ You need this section only if you are going to override a `pagy_nav*` helper or
90
90
91
91
**Important**: This method is not intended to be overridden, however you could just replace it in your overridden `pagy_nav*` helpers or templates with some generic helper like the rails `link_to`. If you intend to do so, be sure to have a very good reason, since using `pagy_link_proc` is a lot faster than the rails `link_to` (benchmarked at ~22x faster using ~18x less memory on a 20 links nav).
92
92
93
-
**Warning**: This is a peculiar way to create page links and it works only for that purpose. It is not intended to be used for generic links.
94
-
95
93
This method returns a specialized proc that you call to produce the page links. The reason it is a two steps process instead of a single method call is performance. Indeed the method calls the potentially expensive `pagy_url_for` only once and generates the proc, then calling the proc will just interpolates the strings passed to it.
96
94
97
95
Here is how you should use it: in your helper or template call the method to get the proc (just once):
# the first :locale will be used also as the default_locale
191
+
# the first :locale will be used also as the default locale
194
192
Pagy::I18n.load({locale: 'de'},
195
193
{locale: 'en'},
196
194
{locale: 'es'})
@@ -222,7 +220,7 @@ That instance variable will be used by the [pagy_t](#pagy_tpath-vars) method inc
222
220
223
221
When Pagy uses its own i18n implementation, it has only access to the strings in its own files and not in other `I18n` files used by the rest of the app.
224
222
225
-
That means that if you use the `pagy_info` helper with the specific model names instead of the generic "items" string, you may need to add entries for the models in the pagy dictionary files. For example:
223
+
That means that if you use the `pagy_info` or `pagy_items_selector` helpers with the specific model names instead of the generic "items" string, you may need to add entries for the models in the pagy dictionary files. For example:
These are the modes accepted by the `:overflow` variable:
52
52
53
-
### :last_page
54
-
55
-
**Notice**: Not available for `Pagy::Countless` instances.
56
-
57
-
It is useful in apps with an UI, in order to avoid to redirect to the last page.
58
-
59
-
Regardless the overflowing page requested, Pagy will set the page to the last page and paginate exactly as if the last page has been requested. For example:
60
-
61
-
```ruby
62
-
# no exception passing an overflowing page (Default mode :last_page)
63
-
pagy =Pagy.new(count:100, page:100)
64
-
65
-
pagy.overflow? #=> true
66
-
pagy.vars[:page] #=> 100 (requested page)
67
-
pagy.page #=> 5 (current/last page)
68
-
pagy.last == pagy.page #=> true
69
-
```
70
-
71
53
### :empty_page
72
54
73
55
This is the default mode; it will paginate the actual requested page, which - being overflowing - is empty. It is useful with APIs, where the client expects an empty set of results in order to stop requesting further pages.
**Notice**: Not available for `Pagy::Countless` instances since for countless instances the last page is not known.
100
+
101
+
It is useful in apps with an UI, in order to avoid to redirect to the last page.
102
+
103
+
Regardless the overflowing page requested, Pagy will set the page to the last page and paginate exactly as if the last page has been requested. For example:
This mode raises the `Pagy::OverflowError` as usual, so you can rescue from and do what is needed. It is useful when you need to use your own custom mode even in presence of this extra (which would not raise any error).
116
+
This mode raises the `Pagy::OverflowError` as usual, so you can rescue from and implement your own custom mode even in presence of this extra.
Copy file name to clipboardExpand all lines: docs/extras/support.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ require 'pagy/extras/support'
17
17
18
18
## Support for alternative pagination types and features
19
19
20
-
Besides the classic navbar pagination, the `compact` and the `responsive` UI components, Pagy offers a few helpers to support a few alternative types of pagination and related features.
20
+
Besides the classic `pagy*_nav` pagination, the `pagy*_nav_js` and the `pagy*_combo_nav_js` UI components, Pagy offers a few helpers to support a few alternative types of pagination and related features.
Copy file name to clipboardExpand all lines: docs/how-to.md
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,7 +80,7 @@ Pagy works out of the box assuming that:
80
80
Pagy can also work in any other scenario assuming that:
81
81
82
82
- If your framework doesn't have a `params` method you may need to define the `params` method or override the `pagy_get_vars` (which uses the `params` method) in your controller
83
-
- If the collection you are paginating doesn't respond to `offset` and `limit` you may need to override the `pagy_get_items` method in your controller (to get the items out of your specific collection) or use a specific extra if available (e.g. `array`, `searchkick`, ...)
83
+
- If the collection you are paginating doesn't respond to `offset` and `limit` you may need to override the `pagy_get_items` method in your controller (to get the items out of your specific collection) or use a specific extra if available (e.g. `array`, `searchkick`, `elasticsearch_rais`)
84
84
- If your framework doesn't have a `request` method you may need to override the `pagy_url_for` (which uses `Rack` and `request`) in your view
85
85
86
86
**Notice**: the total overriding you may need is usually just a handful of lines at worse, and it doesn't need monkey patching or writing any sub-class or module.
@@ -165,7 +165,7 @@ You can also override the `pagy_get_vars` if you need some special way to get th
165
165
If you need to customize some HTML attribute of the page links, you may not need to override the `pagy_nav*` helper. It might be enough to pass some extra attribute string with the `:link_extra` variable. For example:
**IMPORTANT**: For performance reasons the `:anchor` string must include the `#`.
198
+
**IMPORTANT**: For performance reasons the `:anchor` string must include the `"#"`.
199
199
200
200
## Customizing the URL
201
201
@@ -353,14 +353,14 @@ These helpers take the Pagy object and return the HTML string with the paginatio
353
353
354
354
**Notice**: the [extras](extras.md) add a few other helpers that you can use the same way, in order to get added features (e.g. bootstrap compatibility, responsiveness, compact layouts, etc.)
Helpers are the preferred choice (over templates) for their performance. If you need to override a `pagy_nav*` helper you can copy and paste it in your helper and edit it there. It is a simple concatenation of strings with a very simple logic.
366
366
@@ -496,7 +496,7 @@ Here are a few options for manually handling the error in apps:
Copy file name to clipboardExpand all lines: docs/migration-guide.md
+4-6Lines changed: 4 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,7 +60,7 @@ Pagy::VARS[:items] = 10
60
60
Pagy::VARS[:size] = [5,4,4,5]
61
61
```
62
62
63
-
Remove all the old settings and uncomment and edit the new settings in the `pagy.rb` initializer _(see [Configuration](how-to.md#global-configuration))_.
63
+
Remove all the legacy settings of the old gem(s) and uncomment and edit the new settings in the `pagy.rb` initializer _(see [Configuration](how-to.md#global-configuration))_.
64
64
65
65
#### Cleanup the Models
66
66
@@ -70,7 +70,7 @@ The other gems are careless about adding methods, scopes, and even configuration
70
70
71
71
For example, you may want to search for keywords like `per_page`, `per` and such, which are actually configuration settings. They should either go into the `pagy.rb` initializer if they are global to the app, or into the specific `pagy` call in the controller if they are specific to an action.
72
72
73
-
If the app used the `page` scope in some of its methods or scopes, that should be removed (including removing the argument used to pass the page number to the scope), leaving the rest of the scope in place. Search where the app uses the already paginated scope in the controllers, and use the scope in a regular `pagy` statement. For example:
73
+
If the app used the `page` scope in some of its methods or scopes in some model, that should be removed (including removing the argument used to pass the page number to the method/scope), leaving the rest of the scope in place. Search where the app uses the already paginated scope in the controllers, and use the scope in a regular `pagy` statement. For example:
@@ -125,10 +125,8 @@ Please take a look at the topics in the [how-to](how-to.md) documentation: that
125
125
126
126
### CSSs
127
127
128
-
The css styling that you may have applied to the pagination elements may need some minor change. However if the app uses the pagination from bootstrap (or some other framework), the same CSSs should work seamlessly with the pagy nave helpers or with any of the bootstrap templates.
128
+
The css styling that you may have applied to the pagination elements may need some minor change. However if the app uses the pagination from bootstrap (or some other framework), the same CSSs should work seamlessly with the pagy nav helpers or with any of the bootstrap templates.
129
129
130
130
### I18n
131
131
132
-
If the app uses `I18n` you should follow the [I18n doc](api/frontend.md#i18n)
133
-
134
-
See also [I18n](api/frontend.md#i18n).
132
+
If the app uses `I18n` you should follow the [I18n doc](api/frontend.md#i18n).
0 commit comments