1// Package userbook demonstrates a small userbook system working with gnoweb
2package userbook
3
4import (
5 "strconv"
6
7 "gno.land/r/demo/users"
8
9 "gno.land/p/demo/avl/pager"
10 "gno.land/p/demo/ufmt"
11 "gno.land/p/moul/txlink"
12)
13
14const usersLink = "/r/demo/users"
15
16func Render(path string) string {
17 p := pager.NewPager(signupsTree, 20, true)
18 page := p.MustGetPageByPath(path)
19
20 out := "# Welcome to UserBook!\n\n"
21
22 out += ufmt.Sprintf("## [Click here to sign up!](%s)\n\n", txlink.Call("SignUp"))
23 out += "---\n\n"
24
25 for _, item := range page.Items {
26 signup := item.Value.(*Signup)
27 user := signup.address.String()
28
29 if data := users.GetUserByAddress(signup.address); data != nil {
30 user = ufmt.Sprintf("[%s](%s:%s)", data.Name, usersLink, data.Name)
31 }
32
33 out += ufmt.Sprintf("- **User #%d - %s - signed up on %s**\n\n", signup.ordinal, user, signup.timestamp.Format("January 2 2006, 03:04:04 PM"))
34 }
35
36 out += "---\n\n"
37 out += "**Page " + strconv.Itoa(page.PageNumber) + " of " + strconv.Itoa(page.TotalPages) + "**\n\n"
38 out += page.Picker()
39 return out
40}
render.gno
1.04 Kb ยท 40 lines