gpage

package
v2.1.0-rc3 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: MIT Imports: 4 Imported by: 6

Documentation

Overview

Package gpage provides useful paging functionality for web pages.

Index

Constants

View Source
const (
	DefaultPageName        = "page"    // DefaultPageName defines the default page name.
	DefaultPagePlaceHolder = "{.page}" // DefaultPagePlaceHolder defines the place holder for the url template.
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Page

type Page struct {
	TotalSize      int    // Total size.
	TotalPage      int    // Total page, which is automatically calculated.
	CurrentPage    int    // Current page number >= 1.
	UrlTemplate    string // Custom url template for page url producing.
	LinkStyle      string // CSS style name for HTML link tag `a`.
	SpanStyle      string // CSS style name for HTML span tag `span`, which is used for first, current and last page tag.
	SelectStyle    string // CSS style name for HTML select tag `select`.
	NextPageTag    string // Tag name for next p.
	PrevPageTag    string // Tag name for prev p.
	FirstPageTag   string // Tag name for first p.
	LastPageTag    string // Tag name for last p.
	PrevBarTag     string // Tag string for prev bar.
	NextBarTag     string // Tag string for next bar.
	PageBarNum     int    // Page bar number for displaying.
	AjaxActionName string // Ajax function name. Ajax is enabled if this attribute is not empty.
}

Page is the pagination implementer. All the attributes are public, you can change them when necessary.

func New

func New(totalSize, pageSize, currentPage int, urlTemplate string) *Page

New creates and returns a pagination manager. Note that the parameter `urlTemplate` specifies the URL producing template, like: /user/list/{.page}, /user/list/{.page}.html, /user/list?page={.page}&type=1, etc. The build-in variable in `urlTemplate` "{.page}" specifies the page number, which will be replaced by certain page number when producing.

func (*Page) FirstPage

func (p *Page) FirstPage() string

FirstPage returns the HTML content for the first page.

func (*Page) GetContent

func (p *Page) GetContent(mode int) string

GetContent returns the page content for predefined mode. These predefined contents are mainly for chinese localization purpose. You can defines your own page function retrieving the page content according to the implementation of this function.

func (p *Page) GetLink(page int, text, title string) string

GetLink returns the HTML link tag `a` content for given page number.

func (*Page) GetUrl

func (p *Page) GetUrl(page int) string

GetUrl parses the UrlTemplate with given page number and returns the URL string. Note that the UrlTemplate attribute can be either an URL or a URI string with "{.page}" place holder specifying the page number position.

func (*Page) LastPage

func (p *Page) LastPage() string

LastPage returns the HTML content for the last page.

func (*Page) NextPage

func (p *Page) NextPage() string

NextPage returns the HTML content for the next page.

func (*Page) PageBar

func (p *Page) PageBar() string

PageBar returns the HTML page bar content with link and span tags.

func (*Page) PrevPage

func (p *Page) PrevPage() string

PrevPage returns the HTML content for the previous page.

func (*Page) SelectBar

func (p *Page) SelectBar() string

SelectBar returns the select HTML content for pagination.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL