module

Plombir::Content::Pagination

Class methods

page_items(rows : Array(Hash(String, String)), page : Int32, per_page : Int32) : Array(Hash(String, String))

Windows rows to the 1-based page slice.

Pagination.page_items(rows, 2, 5) # => rows[5, 5]? || []
Source
page_url(base_url : String, pattern : String | Nil, page_number : Int32) : String

Builds the URL for page_number (2..N). Page 1 keeps the listing page's own URL, so callers never ask for it here. pattern (e.g. /blog/page:num/) wins when set; otherwise <base_url>page/:num/ (/ → /page/2/).

Pagination.page_url("/blog/", nil, 2) # => "/blog/page/2/"
Source
total_pages(total_items : Int32, per_page : Int32) : Int32

Counts pages for total_items at per_page items each. Empty collections still render page 1, so the minimum is 1.

Pagination.total_pages(7, 5) # => 2
Source
vars(collection : String, per_page : Int32, page : Int32, total_pages : Int32, total_items : Int32, items : Array(Hash(String, String)), base_url : String, pattern : String | Nil) : Hash(String, Renderer::Page::Value)

Builds the flat paginator.* template vars for one page. Numbers are strings (the template engine stays flat), missing neighbours are "" (falsy in {% if %}).

vars = Pagination.vars("posts", 5, 1, 2, 7, items, "/", nil)
vars["paginator.page"] # => "1"
Source