Nils Diewald > Mojolicious-Plugin-TagHelpers-Pagination-0.04 > Mojolicious::Plugin::TagHelpers::Pagination

Download:
Mojolicious-Plugin-TagHelpers-Pagination-0.04.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.04   Source  

NAME ^

Mojolicious::Plugin::TagHelpers::Pagination - Pagination Helper for Mojolicious

SYNOPSIS ^

  # Mojolicious
  $app->plugin('TagHelpers::Pagination' => {
    separator => ' ',
    current => '<strong>{current}</strong>'
  });

  # Mojolicious::Lite
  plugin 'TagHelpers::Pagination' => {
    separator => ' ',
    current   =>  '<strong>{current}</strong>'
  };

  # In Templates
  %= pagination(2, 4, '?page={page}' => { separator => "\n" })
  # <a href="?page=1" rel="prev">&lt;</a>
  # <a href="?page=1">1</a>
  # <a rel="self"><strong>2</strong></a>
  # <a href="?page=3">3</a>
  # <a href="?page=4">4</a>
  # <a href="?page=3" rel="next">&gt;</a>

DESCRIPTION ^

Mojolicious::Plugin::TagHelpers::Pagination helps you to create pagination elements in your templates, like this:

< 1 ... 5 [6] 7 ... 18 >

METHODS ^

Mojolicious::Plugin::TagHelpers::Pagination inherits all methods from Mojolicious::Plugin and implements the following new one.

register

  # Mojolicious
  $app->plugin('TagHelpers::Pagination' => {
    separator => ' ',
    current => '<strong>{current}</strong>'
  });

  # Or in your config file
  {
    'TagHelpers-Pagination' => {
      separator => ' ',
      current => '<strong>{current}</strong>'
    }
  }

Called when registering the plugin.

All parameters can be set either as part of the configuration file with the key TagHelpers-Pagination or on registration (that can be overwritten by configuration).

HELPERS ^

pagination

  # In Templates:
  %= pagination(4, 6 => '/page-{page}.html');
  % my $url = Mojo::URL->new->query({ page => '{page}'});
  %= pagination(4, 6 => $url);
  %= pagination(4, 6 => '/page/{page}.html', { current => '<b>{current}</b>' });

Generates a pagination string. Expects at least two numeric values: the current page number and the total count of pages. Additionally it accepts a link pattern and a hash reference with parameters overwriting the default plugin parameters for pagination. The link pattern can be a string using a placeholder in curly brackets (defaults to page) for the page number it should link to. It's also possible to give a Mojo::URL object containing the placeholder. The placeholder can be used multiple times.

PARAMETERS ^

For the layout of the pagination string, the plugin accepts the following parameters, that are able to overwrite the default layout elements. These parameters can again be overwritten in the pagination helper.

current

Pattern for current page number. The {current} is a placeholder for the current number. Defaults to [{current}]. Instead of a pattern, both sides of the current number can be defined with current_start and current_end.

ellipsis

Placeholder symbol for hidden pages. Defaults to ....

next

Symbol for next pages. Defaults to &gt;.

page

Pattern for page number. The {page} is a placeholder for the page number. Defaults to {page}. Instead of a pattern, both sides of the page number can be defined with page_start and page_end.

placeholder

String representing the placeholder for the page number in the URL pattern. Defaults to page.

prev

Symbol for previous pages. Defaults to &lt;.

separator

Symbol for the separation of pagination elements. Defaults to &nbsp;.

DEPENDENCIES ^

Mojolicious.

AVAILABILITY ^

  https://github.com/Akron/Mojolicious-Plugin-TagHelpers-Pagination

COPYRIGHT AND LICENSE ^

Copyright (C) 2012-2014, Nils Diewald.

This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.

syntax highlighting: