Version: v0.0.0-...-576eb72 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2014 License: MPL-2.0 Imports: 4 Imported by: 0




View Source
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.


View Source
var (
	DefaultOffset = 5


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.


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) Node

func (r *ElementRenderer) Node(page int, flags PageFlags) *html.Node

func (*ElementRenderer) Root

func (r *ElementRenderer) Root() *html.Node

type Flags

type Flags int

type PageFlags

type PageFlags int
const (
	PageCurrent PageFlags = 1 << iota

type Pager

type Pager interface {
	URL(page int) string

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).

func Fmt

func Fmt(format string, base string) Pager

Fmt returns a Pager which returns the base URL for the first page and then fmt.Sprintf(format, base, page) for other pages.

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 &laquo;, &hellip; and &raquo;, respectivelly.
	Previous, Separator, Next string
	// Interfaces used to render the HTML
	Pager    Pager
	Renderer Renderer

func New

func New(count int, current int, pager Pager) *Paginator

New returns a new Paginator with the given page count, current page and Pager to obtain the URL for each page. The returned Paginator will use the Renderer returned by DefaultRenderer, but its Renderer attribute might be modified at any time.

func (*Paginator) Render

func (p *Paginator) Render() template.HTML

Render renders the Paginator as HTML. It's usually called from a template e.g.

 {{ with .Paginator }}
	{{ .Render }}
 {{ end }}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL