Search Apps Documentation Source Content File Folder Download Copy Actions Download

format.gno

1.02 Kb ยท 59 lines
 1package boards2
 2
 3import (
 4	"strconv"
 5	"strings"
 6
 7	"gno.land/p/moul/md"
 8
 9	"gno.land/r/sys/users"
10)
11
12const dateFormat = "2006-01-02 3:04pm MST"
13
14func padLeft(s string, length int) string {
15	if len(s) >= length {
16		return s
17	}
18	return strings.Repeat(" ", length-len(s)) + s
19}
20
21func padZero(u64 uint64, length int) string {
22	s := strconv.Itoa(int(u64))
23	if len(s) >= length {
24		return s
25	}
26	return strings.Repeat("0", length-len(s)) + s
27}
28
29func indentBody(indent string, body string) string {
30	var (
31		res   string
32		lines = strings.Split(body, "\n")
33	)
34	for i, line := range lines {
35		if i > 0 {
36			res += "\n"
37		}
38		res += indent + line
39	}
40	return res
41}
42
43func summaryOf(text string, length int) string {
44	lines := strings.SplitN(text, "\n", 2)
45	line := lines[0]
46	if len(line) > length {
47		line = line[:(length-3)] + "..."
48	} else if len(lines) > 1 {
49		line = line + "..."
50	}
51	return line
52}
53
54func userLink(addr address) string {
55	if u := users.ResolveAddress(addr); u != nil {
56		return md.UserLink(u.Name())
57	}
58	return md.UserLink(addr.String())
59}