Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Apr 29, 2024
1 parent e0d3a18 commit ba3c7e7
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<span>[![Gem Version](https://img.shields.io/gem/v/pagy.svg?label=Pagy&colorA=99004d&colorB=cc0066)](https://rubygems.org/gems/pagy)</span> <span>
[![Ruby](https://img.shields.io/badge/Ruby-EOL-ruby.svg?colorA=99004d&colorB=cc0066)](https://endoflife.date/ruby)</span> <span>
[![Ruby Test](https://github.com/ddnexus/pagy/actions/workflows/ruby-test.yml/badge.svg?branch=master)](https://github.com/ddnexus/pagy/actions/workflows/ruby-test.yml?query=branch%3Amaster)</span> <span>
[![E2E Test](https://github.com/ddnexus/pagy/actions/workflows/e2e-test.yml/badge.svg?branch=master)](https://github.com/ddnexus/pagy/actions/workflows/e2e-test.yml?query=branch%3Amaster)</span> <span>
[![Ruby Test](https://github.com/ddnexus/pagy/actions/workflows/ruby-test.yml/badge.svg?branch=master)](https://github.com/ddnexus/pagy/actions/workflows/ruby-test.yml)</span> <span>
[![E2E Test](https://github.com/ddnexus/pagy/actions/workflows/e2e-test.yml/badge.svg?branch=master)](https://github.com/ddnexus/pagy/actions/workflows/e2e-test.yml)</span> <span>
![Coverage](https://img.shields.io/badge/Coverage-100%25-coverage.svg?colorA=1f7a1f&colorB=2aa22a)</span> <span>
![Rubocop Status](https://img.shields.io/badge/Rubocop-passing-rubocop.svg?colorA=1f7a1f&colorB=2aa22a)</span> <span>
[![MIT license](https://img.shields.io/badge/License-MIT-mit.svg?colorA=1f7a1f&colorB=2aa22a)](http:https://opensource.org/licenses/MIT)</span> <span>
Expand Down
48 changes: 39 additions & 9 deletions docs/api/console.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ pagy_extras :array, :metadata, ...

### then you can use it like inside an app
pagy, items = pagy_array((1..1000).to_a, page: 3)
pagy_navs(pagy)
=> "<nav class=\"pagy-nav pagination\" role=\"navigation\" aria-label=\"pager\"><span class=\"page prev\"><a href=\"http:https://www.example.com/subdir?page=2&items=20\" rel=\"prev\" aria-label=\"previous\">&lsaquo;&nbsp;Prev</a></span> <span class=\"page\"><a href=\"http:https://www.example.com/subdir?page=1&items=20\" >1</a></span> <span class=\"page\"><a href=\"http:https://www.example.com/subdir?page=2&items=20\" rel=\"prev\" >2</a></span> <span class=\"page active\">3</span> <span class=\"page\"><a href=\"http:https://www.example.com/subdir?page=4&items=20\" rel=\"next\" >4</a></span> <span class=\"page\"><a href=\"http:https://www.example.com/subdir?page=5&items=20\" >5</a></span> <span class=\"page\"><a href=\"http:https://www.example.com/subdir?page=6&items=20\" >6</a></span> <span class=\"page\"><a href=\"http:https://www.example.com/subdir?page=7&items=20\" >7</a></span> <span class=\"page gap\">&hellip;</span> <span class=\"page\"><a href=\"http:https://www.example.com/subdir?page=50&items=20\" >50</a></span> <span class=\"page next\"><a href=\"http:https://www.example.com/subdir?page=4&items=20\" rel=\"next\" aria-label=\"next\">Next&nbsp;&rsaquo;</a></span></nav>"
pagy_nav(pagy)
=> [#<Pagy:0x00007fdff0234880 @count=1000, @from=41, @in=20, @items=20, @last=50, @next=4, @offset=40, @outset=0, @page=3, @prev=2, @to=60, @vars={:page=>3, :items=>20, :outset=>0, :size=>7, :cycle=>false, :count_args=>[:all], :page_param=>:page, :url=>"http:https://www.example.com/subdir", :count=>1000}>, [41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60]]
=> "<nav class=\"pagy nav\" aria-label=\"Pages\"><a href=\"http:https://www.example.com/subdir?page=2\" aria-label=\"Previous\">&lt;</a><a href=\"http:https://www.example.com/subdir?page=1\">1</a><a href=\"http:https://www.example.com/subdir?page=2\">2</a><a role=\"link\" aria-disabled=\"true\" aria-current=\"page\" class=\"current\">3</a><a href=\"http:https://www.example.com/subdir?page=4\">4</a><a href=\"http:https://www.example.com/subdir?page=5\">5</a><a href=\"http:https://www.example.com/subdir?page=6\">6</a><a href=\"http:https://www.example.com/subdir?page=7\">7</a><a href=\"http:https://www.example.com/subdir?page=4\" aria-label=\"Next\">&gt;</a></nav>"

pagy_metadata(pagy)
pagy_metadata(pagy)pagy_metadata(pagy)
=>
{ :scaffold_url => "http:https://www.example.com/subdir?page=__pagy_page__",
:first_url => "http:https://www.example.com/subdir?page=1",
Expand All @@ -40,12 +41,41 @@ pagy_metadata(pagy)
:count => 1000,
:page => 3,
:items => 20,
:vars =>
{ :page => 3,
:items => 20,
:outset => 0,
:size => [1, 4, 4, 1],
...
:vars => { :page => 3,
:items => 20,
:outset => 0,
:size => 7,
:cycle => false,
:count_args => [:all],
:page_param => :page,
:url => "http:https://www.example.com/subdir",
:metadata => [:scaffold_url,
:first_url,
:prev_url,
:page_url,
:next_url,
:last_url,
:count,
:page,
:items,
:vars,
:pages,
:last,
:in,
:from,
:to,
:prev,
:next,
:series],
:count => 1000 },
:pages => 50,
:last => 50,
:in => 20,
:from => 41,
:to => 60,
:prev => 2,
:next => 4,
:series => [1, 2, "3", 4, 5, 6, 7] }
```

+++ rails console
Expand Down
2 changes: 1 addition & 1 deletion docs/api/countless.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The `pagy_info` and all the `*_combo_nav_js` helpers that use the total `count`
## How countless pagination works

Instead of basing all the internal calculations on the `:count` variable (passed with the constructor), this class uses the number
of actually retrieved items to deduce the pagination variables.
of actually retrieved items to derive the pagination variables.

The retrieved items number can be passed in a second step to the `finalize` method, which allows pagy to determine if there is
a `next` page, or if the current page is the `last` page, or if the current request should raise a `Pagy::OverflowError`
Expand Down
4 changes: 2 additions & 2 deletions docs/api/stylesheets.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ copy.

!!!warning
You don't need any stylesheet if you use a frontend extra like:
[bootstrap](/docs/extras/bootstrap), [bulma](/docs/extras/bulma)
[bootstrap](/docs/extras/bootstrap) and [bulma](/docs/extras/bulma)
!!!

### HTML Structure
Expand All @@ -25,7 +25,7 @@ number of tags and class attributes that can identify all the parts of the nav b
- The output of `pagy_nav` and `pagy_nav_js` are a series of `a` tags inside a wrapper `nav` tag
- The disabled links are so because they are missing the `href` attributes
- The `pagy nav` and `pagy nav-js` classes are assigned to the `nav` tag
- The `current`, `gap` classes are assigned to the specific `a` tags
- The `current` and `gap` classes are assigned to the specific `a` tags

!!! Notice

Expand Down
2 changes: 1 addition & 1 deletion docs/extras/items.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,6 @@ When the items number is changed with the selector, pagy will reload the paginat
also request the _right_ page number calculated in order to contain the first item of the previously displayed page. That way the
new displayed page will roughly show the same items in the collection before the items change.

This method can take an extra `id` argument, which is used to build the `id` attribute of the `nav` tag.
This method can take an extra `id` argument, which is used as the `id` attribute of the wrapper `span` tag.

===
2 changes: 1 addition & 1 deletion docs/extras/tailwind.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ image: none
# Tailwind Style

Tailwind allows to apply styles to any DOM element, so you don't actually need any special extra to produce a different output.
You can use the standard pagy helpers and `@apply` the tailwind classes by just using the [pagy.tailwind.css](../api/stylesheets/#pagy-tailwind-css) stylesheet file.
You can use the standard pagy helpers and the [pagy.tailwind.css](../api/stylesheets/#pagy-tailwind-css) stylesheet file (that `@apply` the tailwind classes to the pagy output)
9 changes: 5 additions & 4 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ icon: alert-24
unordered.offset(pagy.offset).limit(pagy.limit)
```

!!!warning From the [PostgreSQL Documentation](https://www.postgresql.org/docs/16/queries-limit.html#:~:text=When%20using%20LIMIT,ORDER%20BY)
!!!warning From
the [PostgreSQL Documentation](https://www.postgresql.org/docs/16/queries-limit.html#:~:text=When%20using%20LIMIT,ORDER%20BY)

When using LIMIT, it is important to use an ORDER BY clause that constrains the result rows into a unique order. Otherwise you
will get an unpredictable subset of the query's rows.
Expand All @@ -35,7 +36,7 @@ ordered = unordered.order(:id)

!!!danger Don't rely on ARIA default with multiple nav elements!
Pagy sets the `aria-label` attribute of its `nav` elements with the translated and pluralized `pagy.aria_label.nav` that finds in
the locale files. That would be (always) `"Pages"` for the `en` locale.
the locale files. That would be (always) `"Page"/"Pages"` for the `en` locale.

Since the `nav` or `role="navigation"` elements of a HTML document are considered `landmark roles`, they
should be uniquely aria-identified in the page.
Expand All @@ -59,7 +60,7 @@ should be uniquely aria-identified in the page.

The `class` attribute with a value of `"pagination"` is already added by the `pagy_bootstrap_nav` so it's a duplicate HTML
attribute which is invalid html.
!!!
!!!

!!!success Easily check the native component attributes!

Expand All @@ -70,7 +71,7 @@ pagy demo
```

!!!primary
In the specific `bootstrap` example you could add the class with:
In the specific `bootstrap` example you could override the default bootstrap `"pagination"` class by adding other classes with:

```ruby
@pagy, @records = pagy_bootstrap_nav(collection, classes: 'pagination my-class')
Expand Down

0 comments on commit ba3c7e7

Please sign in to comment.