Skip to content

Commit d4be9dd

Browse files
committed
replaced responsive with nav_js; reordered methods and test normalization
1 parent ec7d754 commit d4be9dd

30 files changed

Lines changed: 558 additions & 831 deletions

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ gem 'rubocop', '~> 0.63.1' unless ENV['SKIP_RUBOCOP']
2222

2323
# docs server
2424
gem "github-pages", '193', group: :jekyll_plugins
25+
26+
gem 'oj'

Gemfile.lock

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ GEM
209209
mini_portile2 (~> 2.4.0)
210210
octokit (4.13.0)
211211
sawyer (~> 0.8.0, >= 0.5.3)
212+
oj (3.7.11)
212213
parallel (1.13.0)
213214
parser (2.6.0.0)
214215
ast (~> 2.4.0)
@@ -263,10 +264,11 @@ DEPENDENCIES
263264
github-pages (= 193)
264265
i18n
265266
minitest
267+
oj
266268
rack
267269
rake
268270
rubocop (~> 0.63.1)
269271
single_cov (~> 1.3)
270272

271273
BUNDLED WITH
272-
1.17.2
274+
2.0.1

docs/api/countless.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ The available values for the `:overflow` variable are `:empty_page` and `:except
4141

4242
### Features without support
4343

44-
The `pagy_info` and all the `*_compact_nav` helpers that use the total `count` are not supported.
44+
The `pagy_info` and all the `*_compact_nav_js` helpers that use the total `count` are not supported.
4545

4646
## How countless pagination works
4747

docs/extras.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ Extras don't define any new module or class, they just re-open the `Pagy` class
3939

4040
## Methods
4141

42-
All the added methods are documented in the respective extras.
42+
A few extras require the [pagy/extras/shared](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/shared.rb) file. It defines only 3 methods used internally, so you don't actually need to use them directly.
43+
44+
**Notice**: All the other added methods are documented in the respective extras doc.
4345

4446
## Javascript
4547

4648
A few helpers use javascript:
4749

48-
- `pagy_*_compact_nav`
49-
- `pagy_*_responsive_nav`
50+
- `pagy_*_compact_nav_js`
51+
- `pagy_*_nav_js`
5052
- `pagy_items_selector`
5153

5254
If you use any of them you should load the [pagy.js](https://github.com/ddnexus/pagy/blob/master/lib/javascripts/pagy.js) file, and run `Pagy.init()` on window load and eventually on [AJAX-load](#using-ajax-with-javascript-enabled-helpers).
@@ -126,34 +128,34 @@ $( window ).load(function() {
126128

127129
### Using AJAX with javascript-enabled helpers
128130

129-
If you AJAX-render any of the javascript helpers mentioned above, you should also execute `Pagy.init(container_element);` in the javascript template. Here is an example for a `pagy_bootstrap_responsive_nav` AJAX-render:
131+
If you AJAX-render any of the javascript helpers mentioned above, you should also execute `Pagy.init(container_element);` in the javascript template. Here is an example for a `pagy_bootstrap_nav_js` AJAX-render:
130132

131-
`pagy_remote_responsive` controller action (notice the `link_extra` to enable AJAX):
133+
`pagy_remote_nav_js` controller action (notice the `link_extra` to enable AJAX):
132134

133135
```ruby
134-
def pagy_remote_responsive
136+
def pagy_remote_nav_js
135137
@pagy, @records = pagy(Product.all, link_extra: 'data-remote="true"')
136138
end
137139
```
138140

139-
`pagy_remote_responsive.html.erb` template for non-AJAX render (first page-load):
141+
`pagy_remote_nav_js.html.erb` template for non-AJAX render (first page-load):
140142

141143
```erb
142144
<div id="container">
143-
<%= render partial: 'responsive_nav' %>
145+
<%= render partial: 'nav_js' %>
144146
</div>
145147
```
146148

147-
`_responsive_nav.html.erb` partial shared for AJAX and non-AJAX rendering:
149+
`_nav_js.html.erb` partial shared for AJAX and non-AJAX rendering:
148150

149151
```erb
150-
<%== pagy_bootstrap_responsive_nav(@pagy) %>
152+
<%== pagy_bootstrap_nav_js(@pagy) %>
151153
```
152154

153-
`pagy_remote_responsive.js.erb` javascript template used for AJAX:
155+
`pagy_remote_nav_js.js.erb` javascript template used for AJAX:
154156

155-
```js-erb
156-
$('#container').html("<%= j(render 'responsive_nav')%>");
157+
```erb
158+
$('#container').html("<%= j(render 'nav_js')%>");
157159
Pagy.init(document.getElementById('container'));
158160
```
159161

docs/extras/bootstrap.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ with a fast helper:
2020

2121
```erb
2222
<%== pagy_bootstrap_nav(@pagy) %>
23-
<%== pagy_bootstrap_responsive_nav(@pagy) %>
24-
<%== pagy_bootstrap_compact_nav(@pagy) %>
23+
<%== pagy_bootstrap_nav_js(@pagy) %>
24+
<%== pagy_bootstrap_compact_nav_js(@pagy) %>
2525
```
2626

2727
or with a template:
@@ -30,7 +30,7 @@ or with a template:
3030
<%== render 'pagy/bootstrap_nav', locals: {pagy: @pagy} %>
3131
```
3232

33-
Configure [javascript](../extras.md#javascript) if you use `pagy_bootstrap_responsive_nav` or `pagy_bootstrap_compact_nav`.
33+
Configure [javascript](../extras.md#javascript) if you use `pagy_bootstrap_nav_js` or `pagy_bootstrap_compact_nav_js`.
3434

3535
## Files
3636

@@ -49,19 +49,19 @@ This method is the same as the `pagy_nav`/`pagy_plain_nav`, but customized for B
4949

5050
The `bootstrap_nav.*` templates produce the same output, and can be used as an easier (but slower) starting point to override it.
5151

52-
### pagy_bootstrap_compact_nav(pagy, ...)
52+
### pagy_bootstrap_compact_nav_js(pagy, ...)
5353

54-
This method is the same as the `pagy_plain_compact_nav`, but customized for the Bootstrap framework.
54+
This method is the same as the `pagy_plain_compact_nav_js`, but customized for the Bootstrap framework.
5555

5656
Here is an example:
5757

5858
![pagy-compact](../assets/images/pagy-compact-g.png)
5959

6060
See more details in the [compact navs](plain.md#compact-navs) documentation.
6161

62-
### pagy_bootstrap_responsive_nav(pagy, ...)
62+
### pagy_bootstrap_nav_js(pagy, ...)
6363

64-
This method is the same as the `pagy_plain_responsive_nav`, but customized for the Bootstrap framework.
64+
This method is the same as the `pagy_plain_nav_js`, but customized for the Bootstrap framework.
6565

6666
See more details in the [responsive navs](plain.md#responsive-navs) documentation.
6767

docs/extras/bulma.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ with a fast helper:
2020

2121
```erb
2222
<%== pagy_bulma_nav(@pagy) %>
23-
<%== pagy_bulma_responsive_nav(@pagy) %>
24-
<%== pagy_bulma_compact_nav(@pagy) %>
23+
<%== pagy_bulma_nav_js(@pagy) %>
24+
<%== pagy_bulma_compact_nav_js(@pagy) %>
2525
```
2626

2727
or with a template:
@@ -30,7 +30,7 @@ or with a template:
3030
<%== render 'pagy/bulma_nav', locals: {pagy: @pagy} %>
3131
```
3232

33-
Configure [javascript](../extras.md#javascript) if you use `pagy_bulma_responsive_nav` or `pagy_bulma_compact_nav`.
33+
Configure [javascript](../extras.md#javascript) if you use `pagy_bulma_nav_js` or `pagy_bulma_compact_nav_js`.
3434

3535
## Files
3636

@@ -49,19 +49,19 @@ This method is the same as the `pagy_nav`/`pagy_plain_nav`, but customized for B
4949

5050
The `bulma_nav.*` templates produce the same output, and can be used as an easier (but slower) starting point to override it.
5151

52-
### pagy_bulma_compact_nav(pagy, ...)
52+
### pagy_bulma_compact_nav_js(pagy, ...)
5353

54-
This method is the same as the `pagy_plain_compact_nav`, but customized for the Bulma CSS framework.
54+
This method is the same as the `pagy_plain_compact_nav_js`, but customized for the Bulma CSS framework.
5555

5656
Here is an example:
5757

5858
![pagy-compact-bulma](../assets/images/pagy-compact-bulma-g.png)
5959

6060
See more details in the [compact navs](plain.md#compact-navs) documentation.
6161

62-
### pagy_bulma_responsive_nav(pagy, ...)
62+
### pagy_bulma_nav_js(pagy, ...)
6363

64-
This method is the same as the `pagy_plain_responsive_nav`, but customized for the Bulma CSS framework.
64+
This method is the same as the `pagy_plain_nav_js`, but customized for the Bulma CSS framework.
6565

6666
See more details in the [responsive navs](plain.md#responsive-navs) documentation.
6767

docs/extras/foundation.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ or with a template:
2828
<%== render 'pagy/foundation_nav', locals: {pagy: @pagy} %>
2929
```
3030

31-
Configure [javascript](../extras.md#javascript) if you use `pagy_foundation_responsive_nav` or `pagy_foundation_compact_nav`.
31+
Configure [javascript](../extras.md#javascript) if you use `pagy_foundation_nav_js` or `pagy_foundation_compact_nav_js`.
3232

3333
## Files
3434

@@ -47,15 +47,15 @@ This method is the same as the `pagy_nav`/`pagy_plain_nav`, but customized for F
4747

4848
The `foundation_nav.*` templates produce the same output, and can be used as an easier (but slower) starting point to override it.
4949

50-
### pagy_foundation_compact_nav(pagy, ...)
50+
### pagy_foundation_compact_nav_js(pagy, ...)
5151

52-
This method is the same as the `pagy_plain_compact_nav`, but customized for the Foundation framework.
52+
This method is the same as the `pagy_plain_compact_nav_js`, but customized for the Foundation framework.
5353

5454
See more details in the [compact navs](plain.md#compact-navs) documentation.
5555

56-
### pagy_foundation_responsive_nav(pagy, ...)
56+
### pagy_foundation_nav_js(pagy, ...)
5757

58-
This method is the same as the `pagy_plain_responsive_nav`, but customized for the Foundation framework.
58+
This method is the same as the `pagy_plain_nav_js`, but customized for the Foundation framework.
5959

6060
See more details in the [responsive navs](plain.md#responsive-navs) documentation.
6161

docs/extras/materialize.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ with a fast helper:
2020

2121
```erb
2222
<%== pagy_materialize_nav(@pagy) %>
23-
<%== pagy_materialize_responsive_nav(@pagy) %>
24-
<%== pagy_materialize_compact_nav(@pagy) %>
23+
<%== pagy_materialize_nav_js(@pagy) %>
24+
<%== pagy_materialize_compact_nav_js(@pagy) %>
2525
```
2626

27-
Configure [javascript](../extras.md#javascript) if you use `pagy_materialize_responsive_nav` or `pagy_materialize_compact_nav`.
27+
Configure [javascript](../extras.md#javascript) if you use `pagy_materialize_nav_js` or `pagy_materialize_compact_nav_js`.
2828

2929
## Files
3030

@@ -38,19 +38,19 @@ This extra adds 3 nav helpers to the `Pagy::Frontend` module. You can customize
3838

3939
This method is the same as the `pagy_nav`/`pagy_plain_nav`, but customized for Materialize.
4040

41-
### pagy_materialize_compact_nav(pagy, ...)
41+
### pagy_materialize_compact_nav_js(pagy, ...)
4242

43-
This method is the same as the `pagy_plain_compact_nav`, but customized for the Materialize CSS framework.
43+
This method is the same as the `pagy_plain_compact_nav_js`, but customized for the Materialize CSS framework.
4444

4545
Here is an example:
4646

4747
![pagy-compact-materialize](../assets/images/pagy-compact-materialize-g.png)
4848

4949
See more details in the [compact navs](plain.md#compact-navs) documentation.
5050

51-
### pagy_materialize_responsive_nav(pagy, ...)
51+
### pagy_materialize_nav_js(pagy, ...)
5252

53-
This method is the same as the `pagy_plain_responsive_nav`, but customized for the Materialize CSS framework.
53+
This method is the same as the `pagy_plain_nav_js`, but customized for the Materialize CSS framework.
5454

5555
See more details in the [responsive navs](plain.md#responsive-navs) documentation.
5656

docs/extras/plain.md

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Plain
33
---
44
# Plain Extra
55

6-
This extra adds a couple of nav helpers to the `Pagy::Frontend` module: `pagy_plain_compact_nav` and `pagy_plain_responsive_nav`. It also adds the `:pagy_plain_nav` alias (pointing to the `:pagy_nav` for naming consistency). These are the plain/unstyled nav helpers for pagination.
6+
This extra adds a couple of nav helpers to the `Pagy::Frontend` module: `pagy_plain_compact_nav_js` and `pagy_plain_nav_js`. It also adds the `:pagy_plain_nav` alias (pointing to the `:pagy_nav` for naming consistency). These are the plain/unstyled nav helpers for pagination.
77

88
Other extras (e.g. [bootstrap](bootstrap.md), [bulma](bulma.md), [foundation](foundation.md), [materialize](materialize.md), [semantic](semantic.md)) provide framework-styled versions of the same `nav`, `responsive` and `compact` helpers, so you may not need this extra if you use one of those.
99

@@ -34,26 +34,26 @@ It is especially useful for small size screens, but it is used also with wide la
3434
Use the responsive helper(s) in any view:
3535

3636
```erb
37-
<%== pagy_plain_compact_nav(@pagy) %>
37+
<%== pagy_plain_compact_nav_js(@pagy) %>
3838
```
3939

4040
Other extras provide also the following framework-styled helpers:
4141

4242
```erb
43-
<%== pagy_bootstrap_compact_nav(@pagy) %>
44-
<%== pagy_bulma_compact_nav(@pagy) %>
45-
<%== pagy_foundation_compact_nav(@pagy) %>
46-
<%== pagy_materialize_compact_nav(@pagy) %>
47-
<%== pagy_semantic_compact_nav(@pagy) %>
43+
<%== pagy_bootstrap_compact_nav_js(@pagy) %>
44+
<%== pagy_bulma_compact_nav_js(@pagy) %>
45+
<%== pagy_foundation_compact_nav_js(@pagy) %>
46+
<%== pagy_materialize_compact_nav_js(@pagy) %>
47+
<%== pagy_semantic_compact_nav_js(@pagy) %>
4848
```
4949

5050
## Methods
5151

52-
### pagy_plain_compact_nav(pagy, ...)
52+
### pagy_plain_compact_nav_js(pagy, ...)
5353

5454
Renders a compact navigation with a style similar to the `pagy_nav` helper.
5555

56-
It can take an extra `id` argument, which is used to build the `id` attribute of the `nav` tag. Since the internal automatic id assignation is based on the code line where you use the helper, you _must_ pass an explicit id if you are going to use more than one `pagy_*_responsive_nav` or `pagy_*_compact_nav` call in the same line for the same page.
56+
It can take an extra `id` argument, which is used to build the `id` attribute of the `nav` tag. Since the internal automatic id assignation is based on the code line where you use the helper, you _must_ pass an explicit id if you are going to use more than one `pagy_*_nav_js` or `pagy_*_compact_nav_js` call in the same line for the same page.
5757

5858
**Notice**: passing an explicit id is also a bit faster than having pagy to generate one.
5959

@@ -68,65 +68,63 @@ Here is a screenshot (from the `bootstrap`extra) of how the same pagination nav
6868
## Synopsis
6969

7070
```ruby
71-
# set your default custom breakpoints (width/size pairs) globally (it can be overridden per Pagy instance)
72-
Pagy::VARS[:breakpoints] = { 0 => [1,0,0,1], 540 => [2,3,3,2], 720 => [3,4,4,3] }
71+
# set your default custom sizes (width/size pairs) globally (it can be overridden per Pagy instance)
72+
Pagy::VARS[:sizes] = { 0 => [1,0,0,1], 540 => [2,3,3,2], 720 => [3,4,4,3] }
7373
```
7474

7575
Use the responsive helper(s) in any view:
7676

7777
```erb
78-
<%== pagy_plain_responsive_nav(@pagy) %>
78+
<%== pagy_plain_nav_js(@pagy) %>
7979
```
8080

8181
Other extras provide also the following framework-styled helpers:
8282

8383
```erb
84-
<%== pagy_bootstrap_responsive_nav(@pagy) %>
85-
<%== pagy_bulma_responsive_nav(@pagy) %>
86-
<%== pagy_foundation_responsive_nav(@pagy) %>
87-
<%== pagy_materialize_responsive_nav(@pagy) %>
88-
<%== pagy_semantic_responsive_nav(@pagy) %>
84+
<%== pagy_bootstrap_nav_js(@pagy) %>
85+
<%== pagy_bulma_nav_js(@pagy) %>
86+
<%== pagy_foundation_nav_js(@pagy) %>
87+
<%== pagy_materialize_nav_js(@pagy) %>
88+
<%== pagy_semantic_nav_js(@pagy) %>
8989
```
9090

9191
## Variables
9292

93-
### :breakpoints
93+
### :sizes
9494

95-
The `:breakpoints` variable is a non-core variable used by the `responsive` navs. It allows you to control how the page links will get shown at different widths. It is a hash where the keys are integers representing the breakpoint widths in pixels and the values are the Pagy `:size` variables to be applied for that width.
95+
The `:sizes` variable is a non-core variable used by the `responsive` navs. It allows you to control how the page links will get shown at different widths. It is a hash where the keys are integers representing the widths in pixels and the values are the Pagy `:size` variables to be applied for that width.
9696
For example:
9797

9898
```ruby
99-
Pagy::VARS[:breakpoints] = { 0 => [2,3,3,2], 540 => [3,5,5,3], 720 => [5,7,7,5] }
99+
Pagy::VARS[:sizes] = { 0 => [2,3,3,2], 540 => [3,5,5,3], 720 => [5,7,7,5] }
100100
```
101101

102102
The above statement means that from `0` to `540` pixels width, Pagy will use the `[2,3,3,2]` size, from `540` to `720` it will use the `[3,5,5,3]` size and over `720` it will use the `[5,7,7,5]` size. (Read more about the `:size` variable in the [How to control the page links](../how-to.md#controlling-the-page-links) section).
103103

104-
**IMPORTANT**: You can set any number of breakpoints with any arbitrary width and size. The only requirement is that the `:breakpoints` hash must contain always the `0` size. An `ArgumentError` exception will be raises if it is missing.
104+
**IMPORTANT**: You can set any number of sizes with any arbitrary width and size. The only requirement is that the `:sizes` hash must contain always the `0` size. An `ArgumentError` exception will be raises if it is missing.
105105

106-
**Notice**: Each added breakpoint slowers down Pagy of less than 10%. For example: with 5 breakpoints the nav will be rendered rougly in less than twice the normal time. That will still run about 16 times faster than Kaminari and 7 times faster than WillPaginate, so it doesn't look like an issue.
106+
#### Setting the right sizes
107107

108-
#### Setting the right breakpoints
109-
110-
Setting the width and the size of your breakpoints is what can create a nice transition between sizes... or some apparently erratic behavior.
108+
Setting the width and the size of your sizes is what can create a nice transition between sizes... or some apparently erratic behavior.
111109

112110
Here is what you should consider/ensure:
113111

114-
1. The pagy size can only change in discrete steps: each widht/size pair in your `:breakpoints` represents a step.
112+
1. The pagy size can only change in discrete steps: each widht/size pair in your `:sizes` represents a step.
115113

116-
2. The transition from one breakpoint/size to another depends on the width available to the pagy nav. That width is the _internal available width_ of its container (excluding eventual horizontal padding).
114+
2. The transition from one size to another depends on the width available to the pagy nav. That width is the _internal available width_ of its container (excluding eventual horizontal padding).
117115

118-
3. You should ensure that each pagy `:size` in your breakpoints produces a nav that can be contained in its its width.
116+
3. You should ensure that each pagy `:size` in your `sizes` produces a nav that can be contained in its its width.
119117

120-
4. You should ensure that the minimum internal width for the container div be equal (or a bit bigger) to the smaller positive `:breakpoints` width. (`540` pixels in our previous example).
118+
4. You should ensure that the minimum internal width for the container div be equal (or a bit bigger) to the smaller positive `:sizes` width. (`540` pixels in our previous example).
121119

122-
5. If the container width snaps to specific widths in discrete steps, you should sync the quantity and widths of the pagy `:brakpoints` to the quantity and internal widths for each discrete step of the container.
120+
5. If the container width snaps to specific widths in discrete steps, you should sync the quantity and widths of the pagy `:sizes` to the quantity and internal widths for each discrete step of the container.
123121

124122
## Methods
125123

126-
### pagy_plain_responsive_nav(pagy, ...)
124+
### pagy_plain_nav_js(pagy, ...)
127125

128126
Similar to the `pagy_nav` helper, with added responsiveness.
129127

130-
It can take an extra `id` argument, which is used to build the `id` attribute of the `nav` tag. Since the internal automatic id assignation is based on the code line where you use the helper, you _must_ pass an explicit id if you are going to use more than one `pagy_*_responsive_nav` or `pagy_*_compact_nav` call in the same line for the same file.
128+
It can take an extra `id` argument, which is used to build the `id` attribute of the `nav` tag. Since the internal automatic id assignation is based on the code line where you use the helper, you _must_ pass an explicit id if you are going to use more than one `pagy_*_nav_js` or `pagy_*_compact_nav_js` call in the same line for the same file.
131129

132130
**Notice**: passing an explicit id is also a bit faster than having pagy to generate one.

0 commit comments

Comments
 (0)