Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jhthorsen/mojolicious-plugin-pager
Pagination plugin for Mojolicious
https://github.com/jhthorsen/mojolicious-plugin-pager
Last synced: 27 days ago
JSON representation
Pagination plugin for Mojolicious
- Host: GitHub
- URL: https://github.com/jhthorsen/mojolicious-plugin-pager
- Owner: jhthorsen
- Created: 2017-06-01T20:10:20.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2022-02-26T09:59:41.000Z (almost 3 years ago)
- Last Synced: 2024-10-16T11:58:30.180Z (3 months ago)
- Language: Perl
- Size: 20.5 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README
- Changelog: Changes
Awesome Lists containing this project
README
NAME
Mojolicious::Plugin::Pager - Pagination plugin for MojoliciousSYNOPSIS
Example lite app
use Mojolicious::Lite;plugin "pager";
get "/" => sub {
my $c = shift;
$c->stash(total_items => 1431, items_per_page => 20);
};Example template
- <%= pager_link $page %>
% for my $page (pages_for $total_items / $items_per_page) {
% }
Custom template
- <%= link_to "hey!", $url %>
% for my $page (pages_for $total_items / $items_per_page) {
% my $url = url_with; $url->query->param(x => $page->{n});
% }
DESCRIPTION
Mojolicious::Plugin::Pager is a Mojolicious plugin for creating paged
navigation, without getting in the way. There are other plugins which
ship with complete markup, but this is often not the markup that *you*
want.
Note that this plugin is currently EXPERIMENTAL.
HELPERS
pager_link
$bytestream = $c->pager_link(\%page, @args);
$bytestream = $c->pager_link(\%page, @args, sub { int(rand 100) });
Takes a %page hash and creates an anchor using "link_to" in
Mojolicious::Controller. @args is passed on, without modification, to
"link_to()". The anchor generated has some classes added.
See "pages_for" for detail about %page.
Examples output:
pages_for
@pages = $self->pages_for($total_pages);
@pages = $self->pages_for(\%args)
@pages = $self->pages_for;
Returns a list of %page hash-refs, that can be passed on to
"pager_link".
Example %page:
{
n => 2, # page number
current => 1, # if page number matches "page" query parameter
first => 1, # if this is the first page
last => 1, # if this is the last page
next => 1, # if this is last, that brings you to the next page
prev => 1, # if this is first, that brings you to the previous page
}
%args can contain:
* current
Default to the "page" query param or "1".
* items_per_page
Only useful unless "total" is specified. Default to 20.
* size
The max number of pages to show in the pagination. Default to 8 +
"Previous" and "Next" links.
* total
The total number of pages. Default to "1" or...
$total = $args->{total_items} / $args->{items_per_page}
$total = $c->stash('total_items') / $c->stash('items_per_page')
METHODS
register
$app->plugin(pager => \%config);
Used to register this plugin and the "HELPERS" above. %config can be:
* classes
Used to set default class names, used by "pager_link".
Default:
{
current => "active",
first => "first",
last => "last",
next => "next",
prev => "prev",
normal => "page",
}
* param_name
The query parameter that will be looked up to figure out which page
you are on. Can also be set in "stash" in Mojolicious::Controller on
each request under the name "page_param_name".
Default: "page"
AUTHOR
Jan Henning Thorsen
COPYRIGHT AND LICENSE
Copyright (C) 2017, Jan Henning Thorsen
This program is free software, you can redistribute it and/or modify it
under the terms of the Artistic License version 2.0.