NAME

HiD::Pager - Class for paging thru sets of entries

SYNOPSIS

To use pagination with just the blog pages, set the following config
options:

  pagination:
    entries: 10
    page: 'blog/%{page}s'
    template: 'blog/index.html'

C<pagination.entries> sets the number of entries per
page. C<pagination.page> sets the pattern for pages. C<pagination.template>
is the template file that will be used for each file in turn. A
C<index.html> will be appended to each page. Note that no 'page1' entry will
be generated; in the example above, the first page would be at
'blog/index.html', the second at 'blog/page2/index.html', and so on.

If you need more control, or want to use pagination inside a
L<HiD::Generator>, you can instatiate one like so:

  my $pager = HiD::Pager->new({
    entries             => $site->posts ,
    entries_per_page    => 5 ,
    hid                 => $site ,
    page_pattern        => 'blog/%{page}s' ,
  });

  while( my $page_data = $pager->next() ) {
    my $page = HiD::Page->new(
      metadata => { page_data => $page_data },
      # other page data here
    );
    # inject page into site, etc.
  }

  # in page template, assuming Kolon template syntax
  : for $page_data.posts -> $post {
  :   ## render page here
  : }

  : # other useful info for creating intra-page links and metadata
  : $page_data.current_page_url = url of current page
  : $page_data.page_number      = number of current page
  : $page_data.total_pages      = total number of pages
  : $page_data.prev_page        = number of previous page (undef if no previous)
  : $page_data.prev_page_url    = url of previous page (undef if no previous)
  : $page_data.next_page        = number of next page (undef if no next)
  : $page_data.next_page_url    = url of next page (undef if no next)

DESCRIPTION

Class providing pagination services for sets of posts. Can be used for main blog post pages by setting up the appropriate configuration, or used inside a HiD::Generator class to provide paged sets of a subset of the posts on a site.

ATTRIBUTES

entries

Array of HiD::Post objects being worked with

entries_per_page

Number of entries per page.

hid

All hail the God Object.

page_pattern

Regex used to generate per-page URLs

pager

The Data::Page object that does all the work.

METHODS

current_page_url

Returns the URL for the current page in the set.

next

Returns the data structure for the pager information.

next_page_url

Returns the URL for the next page in the set.

prev_page_url

Returns the URL for the previous page in the set.

VERSION

version 1.9

AUTHOR

John SJ Anderson <genehack@genehack.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by John SJ Anderson.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.