From a8ad3993d9dcd5b7c4e015a81ac3421e1f007b44 Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Thu, 23 Aug 2018 13:16:35 +0200 Subject: [PATCH] docs fixes and improvements --- README.md | 4 ++-- docs/extras/foundation.md | 2 +- docs/how-to.md | 9 +++++++++ lib/config/pagy.rb | 4 ++-- lib/pagy/extras/bulma.rb | 1 + lib/pagy/extras/foundation.rb | 4 ++-- lib/pagy/extras/trim.rb | 2 +- 7 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d22aba431..a33b8615b 100644 --- a/README.md +++ b/README.md @@ -125,8 +125,8 @@ Besides the classic pagination `nav`, Pagy offers a few ready to use alternative ### Posts and Tutorials - [Pagination with Pagy](https://www.imaginarycloud.com/blog/paginating-ruby-on-rails-apps-with-pagy) by Tiago Franco -- [Stateful Tabs Pagination](https://www.imaginarycloud.com/blog/how-to-paginate-ruby-on-rails-apps-with-pagy) by Chris Seelus -- [Quick guide for Sinatra and Sequel](https://medium.com/@vfreefly/how-to-use-pagy-with-sequel-and-sinatra-157dfec1c417) by Victor Afanasev +- [Stateful Tabs with Pagy](https://www.imaginarycloud.com/blog/how-to-paginate-ruby-on-rails-apps-with-pagy) by Chris Seelus +- [Quick guide for Pagy with Sinatra and Sequel](https://medium.com/@vfreefly/how-to-use-pagy-with-sequel-and-sinatra-157dfec1c417) by Victor Afanasev ## Please Star and Share! diff --git a/docs/extras/foundation.md b/docs/extras/foundation.md index 288d6c862..4f5baf041 100644 --- a/docs/extras/foundation.md +++ b/docs/extras/foundation.md @@ -35,7 +35,7 @@ This extra is composed of 4 files: ## Methods -This extra adds one nav helpers to the `Pagy::Frontend` module. You can customize it by overriding it directly in your own view helper. +This extra adds 3 nav helpers to the `Pagy::Frontend` module. You can customize it by overriding it directly in your own view helper. ### pagy_nav_foundation(pagy) diff --git a/docs/how-to.md b/docs/how-to.md index 8073da28a..353c62037 100644 --- a/docs/how-to.md +++ b/docs/how-to.md @@ -267,6 +267,15 @@ subset = Product.offset(100).limit(315) Assuming the `:items` default of `20`, you will get the pages with the right records you are expecting. The first page from record 101 to 120 of the main collection, and the last page from 401 to 415 of the main collection. Besides the `from` and `to` attribute readers will correctly return the numbers relative to the subset that you are paginating, i.e. from 1 to 20 for the first page and from 301 to 315 for the last page. +## Paginate non-ActiveRecord collections + +The `pagy_get_vars` method works out of the box with `ActiveRecord` collections; for other collections (e.g. `mongoid`, etc.) you may need to override it in your controller, usually by simply removing the `:all` argument passed to `count`: + +```ruby +#count = collection.count(:all) +count = collection.count +``` + ## Using the pagy_nav* helpers These helpers take the Pagy object and returns the HTML string with the pagination links, which are wrapped in a `nav` tag and are ready to use in your view. For example: diff --git a/lib/config/pagy.rb b/lib/config/pagy.rb index 5b64fe273..e0db46b21 100644 --- a/lib/config/pagy.rb +++ b/lib/config/pagy.rb @@ -41,11 +41,11 @@ # See https://ddnexus.github.io/pagy/extras/materialize # require 'pagy/extras/materialize' -# Semantic: Nav helper for Semantic UI pagination +# Semantic: Nav, responsive and compact helpers for Semantic UI pagination # See https://ddnexus.github.io/pagy/extras/semantic # require 'pagy/extras/semantic' -# Breakoints var used by the responsive nav helpers +# Breakpoints var used by the responsive nav helpers # See https://ddnexus.github.io/pagy/extras/navs#breakpoints # Pagy::VARS[:breakpoints] = { 0 => [1,2,2,1], 350 => [2,3,3,2], 550 => [3,4,4,3] } # example of width/size pairs diff --git a/lib/pagy/extras/bulma.rb b/lib/pagy/extras/bulma.rb index 6b0fea31a..ce764254d 100644 --- a/lib/pagy/extras/bulma.rb +++ b/lib/pagy/extras/bulma.rb @@ -6,6 +6,7 @@ class Pagy module Frontend + # Pagination for Bulma: it returns the html with the series of links to the pages def pagy_nav_bulma(pagy) html, link, p_prev, p_next = +'', pagy_link_proc(pagy), pagy.prev, pagy.next diff --git a/lib/pagy/extras/foundation.rb b/lib/pagy/extras/foundation.rb index 92bc9dcf1..5c4cf8ac9 100644 --- a/lib/pagy/extras/foundation.rb +++ b/lib/pagy/extras/foundation.rb @@ -6,7 +6,7 @@ class Pagy module Frontend - # Pagination for foundation: it returns the html with the series of links to the pages + # Pagination for Foundation: it returns the html with the series of links to the pages def pagy_nav_foundation(pagy) html, link, p_prev, p_next = +'', pagy_link_proc(pagy), pagy.prev, pagy.next @@ -23,7 +23,7 @@ def pagy_nav_foundation(pagy) %() end - # Compact pagination for foundation: it returns the html with the series of links to the pages + # Compact pagination for Foundation: it returns the html with the series of links to the pages # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate def pagy_nav_compact_foundation(pagy, id=caller(1,1)[0].hash) html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages diff --git a/lib/pagy/extras/trim.rb b/lib/pagy/extras/trim.rb index 350fc1f04..0e321ed73 100644 --- a/lib/pagy/extras/trim.rb +++ b/lib/pagy/extras/trim.rb @@ -5,7 +5,7 @@ class Pagy module Frontend - # boolean used by the compact extra + # boolean used by the compact navs TRIM = true def pagy_trim_url(url, param_string)