diff --git a/README.md b/README.md index 09ddc9650..a6a5adfa2 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Or - if you prefer - render the navigation links with a template: <%== render 'pagy/nav', locals: {pagy: @pagy} %> ``` -_(see [Quick Start](https://ddnexus.github.io/pagy/how-to#quick-start))_ +_(see [Quick Start](https://ddnexus.github.io/pagy/how-to#quick-start) for more details)_ ## Easy to extend @@ -89,7 +89,7 @@ Nav helper and templates for Bootstrap pagination. _(see [more...](http://ddnexu ### Bulma Extra -Nav helper and templates for Bulma CSS framework pagination. _(see [more...](http://ddnexus.github.io/pagy/extras/bulma))_ +Nav helper and templates for Bulma CSS pagination. _(see [more...](http://ddnexus.github.io/pagy/extras/bulma))_ ### Compact Extra @@ -101,6 +101,10 @@ An alternative UI that combines the pagination feature with the navigation info Allow the client to request a custom number of items per page with a ready to use selector UI. _(see [more...](http://ddnexus.github.io/pagy/extras/items))_ +### Materialize Extra + +Nav helper for Materialize CSS pagination. _(see [more...](http://ddnexus.github.io/pagy/extras/materialize))_ + ### Out Of Range Extra Allow for easy handling of out of range pages _(see [more...](http://ddnexus.github.io/pagy/extras/out_of_range))_ diff --git a/docs/_layouts/default.html b/docs/_layouts/default.html index ab7c44fce..d331e1c8c 100644 --- a/docs/_layouts/default.html +++ b/docs/_layouts/default.html @@ -40,6 +40,7 @@

I18n

Items

Out Of Range

+

Materialize

Responsive

Migration Tips

> Chat Support on Gitter <

diff --git a/docs/assets/images/pagy-compact-materialize-g.png b/docs/assets/images/pagy-compact-materialize-g.png new file mode 100644 index 000000000..f5c8d71ab Binary files /dev/null and b/docs/assets/images/pagy-compact-materialize-g.png differ diff --git a/docs/extras.md b/docs/extras.md index f78ca572a..98b8996e3 100644 --- a/docs/extras.md +++ b/docs/extras.md @@ -13,6 +13,7 @@ Pagy comes with a few optional extensions/extras: | `compact` | An alternative UI that combines the pagination with the nav info in a single compact element | [compact.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/compact.rb), [documentation](extras/compact.md) | | `i18n` | Use the `I18n` gem instead of the pagy implementation | [i18n.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/i81n.rb), [documentation](extras/i18n.md) | | `items` | Allow the client to request a custom number of items per page with a ready to use selector UI | [items.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/items.rb), [documentation](extras/items.md) | +| `materialize` | Nav helper for Materialize CSS [pagination component](https://materializecss.com/pagination.html) | [materialize.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/materialize.rb), [documentation](extras/materialize.md) | | `out_of_range` | Allow for easy handling of out of range pages | [out_of_range.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/out_of_range.rb), [documentation](extras/out_of_range.md) | | `responsive` | On resize, the number of page links will adapt in real-time to the available window or container width | [responsive.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/responsive.rb), [documentation](extras/responsive.md) | diff --git a/docs/extras/compact.md b/docs/extras/compact.md index 9e9820fd3..e53c11170 100644 --- a/docs/extras/compact.md +++ b/docs/extras/compact.md @@ -7,10 +7,6 @@ The `compact` extra adds an alternative pagination UI that combines the paginati It is especially useful for small size screens, but it is used also with wide layouts since it is __even faster__ than the classic nav of links, because it needs to render just a minimal HTML string. -Here is an example (bootstrap style): - -![pagy-compact](../assets/images/pagy-compact-g.png) - ## Synopsys See [extras](../extras.md) for general usage info. @@ -23,6 +19,7 @@ Then use the responsive helper(s) in any view: <%== pagy_nav_compact(@pagy) %> <%== pagy_nav_compact_bootstrap(@pagy) %> <%== pagy_nav_compact_bulma(@pagy) %> +<%== pagy_nav_compact_materialize(@pagy) %> ``` ## Files @@ -43,10 +40,22 @@ It can take an extra `id` argument, which is used to build the `id` attribute of This method is the same as the `pagy_nav_compact`, but customized for Bootstrap. +Here is an example: + +![pagy-compact](../assets/images/pagy-compact-g.png) + ### pagy_nav_compact_bulma(pagy, ...) This method is the same as the `pagy_nav_compact`, but customized for Bulma CSS framework. -Generated pagination preview: +Here is an example: ![pagy-compact-bulma](../assets/images/pagy-compact-bulma-g.png) + +### pagy_nav_compact_materialize(pagy, ...) + +This method is the same as the `pagy_nav_compact`, but customized for Materialize CSS framework. + +Here is an example: + +![pagy-compact-materialize](../assets/images/pagy-compact-materialize-g.png) diff --git a/docs/extras/materialize.md b/docs/extras/materialize.md new file mode 100644 index 000000000..978841150 --- /dev/null +++ b/docs/extras/materialize.md @@ -0,0 +1,35 @@ +--- +title: Materialize +--- +# Materialize Extra + +This extra adds nav helper and templates for Materialize CSS framework [pagination component](https://materializecss.com/pagination.html). + +## Synopsys + +See [extras](../extras.md) for general usage info. + +Render the navigation links in some view... +with a fast helper: + +```erb +<%== pagy_nav_materialize(@pagy) %> +``` + +## Files + +This extra is composed of 1 file: + +- [materialize.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/materialize.rb) + +## 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. + +### pagy_nav_materialize(pagy) + +This method is the same as the `pagy_nav`, but customized for Materialize. + +## Templates + +There is currently no template for Materialize. Please, create a Pull Request or an Issue requesting that. diff --git a/docs/extras/responsive.md b/docs/extras/responsive.md index 710bc4067..dd15fa9c9 100644 --- a/docs/extras/responsive.md +++ b/docs/extras/responsive.md @@ -29,6 +29,7 @@ Then use the responsive helper(s) in any view: <%== pagy_nav_responsive(@pagy) %> <%== pagy_nav_responsive_bootstrap(@pagy) %> <%== pagy_nav_responsive_bulma(@pagy) %> +<%== pagy_nav_responsive_materialize(@pagy) %> ``` ## Files @@ -75,3 +76,7 @@ This method is the same as the `pagy_nav_responsive`, but customized for Bootstr ### pagy_nav_responsive_bulma(pagy, ...) This method is the same as the `pagy_nav_responsive`, but customized for Bulma CSS framework. + +### pagy_nav_responsive_materialize(pagy, ...) + +This method is the same as the `pagy_nav_responsive`, but customized for Materialize CSS framework. diff --git a/docs/how-to.md b/docs/how-to.md index ffa38dc11..1da8c1e0b 100644 --- a/docs/how-to.md +++ b/docs/how-to.md @@ -211,13 +211,14 @@ These helpers take the Pagy object and returns the HTML string with the paginati **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.) -| Extra | Helpers | -| ---------------------------------- | ----------------------------------------------------------------------------------- | -| [bootstrap](extras/bootstrap.md) | `pagy_nav_bootstrap` | -| [bulma](extras/bulma.md) | `pagy_nav_bulma` | -| [compact](extras/compact.md) | `pagy_nav_compact`, `pagy_nav_compact_bootstrap`, `pagy_nav_compact_bulma` | -| [items](extras/items.md) | `pagy_items_selector` | -| [responsive](extras/responsive.md) | `pagy_nav_responsive`, `pagy_nav_responsive_bootstrap`, `pagy_nav_responsive_bulma` | +| Extra | Helpers | +| ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------- | +| [bootstrap](extras/bootstrap.md) | `pagy_nav_bootstrap` | +| [bulma](extras/bulma.md) | `pagy_nav_bulma` | +| [compact](extras/compact.md) | `pagy_nav_compact`, `pagy_nav_compact_bootstrap`, `pagy_nav_compact_bulma` , `pagy_nav_compact_materialize` | +| [items](extras/items.md) | `pagy_items_selector` | +| [materialize](extras/materialize.md) | `pagy_nav_materialize` | +| [responsive](extras/responsive.md) | `pagy_nav_responsive`, `pagy_nav_responsive_bootstrap`, `pagy_nav_responsive_bulma`, `pagy_nav_responsive_materialize` | 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 end edit it there. It is a simple concatenation of strings with a very simple logic. @@ -400,16 +401,16 @@ You can handle the exception by using the [out_of_range extra](extras/out_of_ran Here are a few options for manually handling the error in apps: - - Do nothing and let the page render a 500 - - Rescue and render a 404 - - Rescue and redirect to the last known page (Notice: the [out_of_range extra](extras/out_of_range.md) provides the same behavior without redirecting) +- Do nothing and let the page render a 500 +- Rescue and render a 404 +- Rescue and redirect to the last known page (Notice: the [out_of_range extra](extras/out_of_range.md) provides the same behavior without redirecting) ```ruby # in a controller rescue_from Pagy::OutOfRangeError, with: :redirect_to_last_page - + private - + def redirect_to_last_page(e) redirect_to url_for(page: e.pagy.last), notice: "Page ##{params[:page]} is out of range. Showing page #{e.pagy.last} instead." end diff --git a/lib/pagy/extras/compact.rb b/lib/pagy/extras/compact.rb index 59e0291b0..c1a86244b 100644 --- a/lib/pagy/extras/compact.rb +++ b/lib/pagy/extras/compact.rb @@ -55,5 +55,24 @@ def pagy_nav_compact_bulma(pagy, id=caller(1,1)[0].hash) html << %() end + # Compact pagination for materialize: 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_materialize(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 + + html << %(