github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/Unknwon/paginater/README.md (about)

     1  Paginater [![Build Status](https://drone.io/github.com/Unknwon/paginater/status.png)](https://drone.io/github.com/Unknwon/paginater/latest) [![](http://gocover.io/_badge/github.com/Unknwon/paginater)](http://gocover.io/github.com/Unknwon/paginater)
     2  =========
     3  
     4  Package paginater is a helper module for custom pagination calculation.
     5  
     6  ## Installation
     7  
     8  	go get github.com/Unknwon/paginater
     9  
    10  ## Getting Started
    11  
    12  The following code shows an example of how to use paginater:
    13  
    14  ```go
    15  package main
    16  
    17  import "github.com/Unknwon/paginater"
    18  
    19  func main() {
    20  	// Arguments:
    21  	// - Total number of rows
    22  	// - Number of rows in one page
    23  	// - Current page number 
    24  	// - Number of page links
    25  	p := paginater.New(45, 10, 3, 3)
    26  	
    27  	// Then use p as a template object named "Page" in "demo.html"
    28  	// ...
    29  }
    30  ```
    31  
    32  `demo.html`
    33  
    34  ```html
    35  {{if not .Page.IsFirst}}[First](1){{end}}
    36  {{if .Page.HasPrevious}}[Previous]({{.Page.Previous}}){{end}}
    37  
    38  {{range .Page.Pages}}
    39  	{{if eq .Num -1}}
    40  	...
    41  	{{else}}
    42  	{{.Num}}{{if .IsCurrent}}(current){{end}}
    43  	{{end}}
    44  {{end}}
    45  
    46  {{if .Page.HasNext}}[Next]({{.Page.Next}}){{end}}
    47  {{if not .Page.IsLast}}[Last]({{.Page.TotalPages}}){{end}}
    48  ```
    49  
    50  Possible output:
    51  
    52  ```
    53  [First](1) [Previous](2) ... 2 3(current) 4 ... [Next](4) [Last](5)
    54  ```
    55  
    56  As you may guess, if the `Page` value is `-1`, you should print `...` in the HTML as common practice.
    57  
    58  ## Getting Help
    59  
    60  - [API Documentation](https://gowalker.org/github.com/Unknwon/paginater)
    61  - [File An Issue](https://github.com/Unknwon/paginater/issues/new)
    62  
    63  ## License
    64  
    65  This project is under Apache v2 License. See the [LICENSE](LICENSE) file for the full license text.