Skip to content

Commit

Permalink
Released version 0.02
Browse files Browse the repository at this point in the history
 - Fix missing dependencies
  • Loading branch information
Jan Henning Thorsen committed Jun 1, 2017
1 parent fde622e commit b93a96e
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 7 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/Makefile
/Makefile.old
/MANIFEST
/README
/MANIFEST.bak
/META*
/MYMETA*
Expand Down
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Revision history for perl distribution Mojolicious-Plugin-Pager

0.02 2017-06-01T22:48:06+0200
- Fix missing dependencies

0.01 2017-06-01T22:18:07+0200
- Add pager_link() and pages_for() helpers
6 changes: 3 additions & 3 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ WriteMakefile(
repository => 'https://github.com/jhthorsen/mojolicious-plugin-pager.git',
},
},
BUILD_REQUIRES => {'Test::More' => '0.88'},
PREREQ_PM => {'perl' => 'v5.10.0'},
test => {TESTS => (-e 'META.yml' ? 't/*.t' : 't/*.t xt/*.t')},
BUILD_REQUIRES => {'Test::More' => '1.30'},
PREREQ_PM => {'Mojolicious' => '7.20'},
test => {TESTS => (-e 'META.yml' ? 't/*.t' : 't/*.t xt/*.t')},
);
120 changes: 120 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
NAME
Mojolicious::Plugin::Pager - Pagination plugin for Mojolicious

SYNOPSIS
Example lite app
use Mojolicious::Lite;

plugin "pager";

get "/" => sub {
my $c = shift;
$c->stash(total_entries => 1431, entries_per_page => 20);
};

Example template
<ul class="pager">
% for my $page (pages_for $total_entries / $entries_per_page) {
<li><%= pager_link $page %></li>
% }
</ul>

Custom template
<ul class="pager">
% for my $page (pages_for $total_entries / $entries_per_page) {
% my $url = url_with; $url->query->param(x => $page->{n});
<li><%= link_to "hey!", $url %></li>
% }
</ul>

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:

<a href="?page=2" class="prev" rel="prev">12</a>
<a href="?page=1" class="first">1</a>
<a href="?page=2" class="page">2</a>
<a href="?page=3" class="active">3</a>
<a href="?page=4" class="page">4</a>
<a href="?page=5" class="page">5</a>
<a href="?page=6" class="last">6</a>
<a href="?page=3" class="next" rel="next">3</a>

pages_for
@pages = $self->pages_for($total_pages);

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
}

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"

* window_size

Used to decide how many pages to show after/before the current page.

Default: 3

AUTHOR
Jan Henning Thorsen

COPYRIGHT AND LICENSE
Copyright (C) 2016, 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.

4 changes: 2 additions & 2 deletions cpanfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# You can install this projct with curl -L http://cpanmin.us | perl - https://github.com/jhthorsen/mojolicious-plugin-pager/archive/master.tar.gz
requires "perl" => "5.10.0";
test_requires "Test::More" => "0.88";
requires "Mojolicious" => "7.20";
test_requires "Test::More" => "1.30";
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/Pager.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use POSIX ();
use constant PAGE_PARAM => 'page_param_name';
use constant WINDOW_SIZE => 'pager.window_size';

our $VERSION = '0.01';
our $VERSION = '0.02';

sub pager_link {
my ($self, $c, $page, @args) = @_;
Expand Down

0 comments on commit b93a96e

Please sign in to comment.