Documentation ¶
Index ¶
Constants ¶
const ( // FlagNoPrevNext removes the links to the previous and // next page at the start and the end of the paginator. FlagNoPrevNext = 1 << iota // FlagNoBoundaries does not show the paginator boundaries. // When showing the boundaries the first and the last page are // always shown. FlagNoBoundaries )
Variables ¶
var (
DefaultOffset = 5
)
Functions ¶
func SetDefaultRenderer ¶
func SetDefaultRenderer(f func() Renderer)
SetDefaultRenderer sets the function which will return a default renderer. The default value returns an ElementRenderer using a ul to wrap all the paginator and a li for each page.
Types ¶
type ElementRenderer ¶
type ElementRenderer struct { RootElement *html.Node Element *html.Node CurrentClass string DisabledClass string }
ElementRenderer implements a Renderer which returns all HTML nodes inside its RootElement and creates each page element by copying its Element attribute and adding CurrentClass and/or DisabledClass as aproppriate. Note that Element must contain an "a" node.
func (*ElementRenderer) Root ¶
func (r *ElementRenderer) Root() *html.Node
type Pager ¶
Pager represents an interface which returns the URL for the given page number. Note that page numbers are 1-indexed (i.e. the first page is page 1, not page 0).
type Paginator ¶
type Paginator struct { // Count is the total number of pages Count int // Current represents the page number (1-indexed) // to be rendered as the current page Current int // Offset is the number of pages shown at each // side of the current one. Its default value // is copied from DefaultOffset when a Paginator // is created via New. Offset int // Flags control several aspects of the rendering. // See the Flags type constants for the available ones. Flags Flags // Labels used in the paginator. If empty, their values // will default to «, … and », respectivelly. Previous, Separator, Next string // Interfaces used to render the HTML Pager Pager Renderer Renderer }
func New ¶
New returns a new Paginator with the given item count, items per page, the current page and Pager to obtain the URL for each page. Note that the number of pages is not explicitely provided, but calculated from the number of items and the items per page.
The returned Paginator will use the Renderer returned by DefaultRenderer, but its Renderer attribute might be modified at any time.
type Renderer ¶
type Renderer interface { // Root returns the root node for the paginator. All page // Nodes will be added as children of this node. Root() *html.Node // Node returns the HTML node for the given page number // and flags. // The returned node must be or contain an "a" node. // Each node returned from this function will be added // as a child of the returned Root Node Node(page int, flags PageFlags) *html.Node }
Render is the interface implemented by the paginator Renderer.
func DefaultRenderer ¶
func DefaultRenderer() Renderer
DefaultRenderer return a new Renderer using the default function.