-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
105 lines (95 loc) · 2.43 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package actions
import (
"html/template"
)
func shortenHelper(s string, l int) string {
if len(s) > l {
return s[0:l-3] + "..."
}
return s
}
func imageForHelper(url, class string) template.HTML {
return template.HTML(`<img class="` + class + `" src="` + url + `">`)
}
/*
func paginateHelper(sp models.SearchParams) template.HTML {
var str string
pagerLen := 11
center := pagerLen/2 + 1
arm := pagerLen/2 - 2
loopStart := 1
loogEnd := sp.TotalPages
query := ""
if sp.Sort != "" {
query += "&sort=" + sp.Sort
}
if sp.FilterKey != "" {
value := url.QueryEscape(fmt.Sprintf("%v", sp.FilterValue))
query += fmt.Sprintf("&filter=%v&value=%v", sp.FilterKey, value)
}
if sp.TotalPages > pagerLen {
loogEnd = pagerLen - 2
if sp.Page > center {
loopStart = sp.Page - arm
loogEnd = sp.Page + arm
str += fmt.Sprintf(`<li><a href="?page=1&pp=%v%v">1</a></li>`,
sp.PerPage, query)
str += `<li><a>...</a></li>`
}
if sp.Page > (sp.TotalPages - arm - 3) {
loogEnd = sp.TotalPages
loopStart = sp.TotalPages - pagerLen + 3
}
}
for i := loopStart; i <= loogEnd; i++ {
attr := ""
if i == sp.Page {
attr = ` class="active"`
}
str += fmt.Sprintf(`<li%v><a href="?page=%v&pp=%v%v">%v</a></li>`,
attr, i, sp.PerPage, query, i)
}
if sp.TotalPages > loogEnd {
str += `<li><a>...</a></li>`
str += fmt.Sprintf(`<li><a href="?page=%v&pp=%v%v">%v</a></li>`,
sp.TotalPages, sp.PerPage, query, sp.TotalPages)
}
prev := sp.Page - 1
next := sp.Page + 1
prevQuery := fmt.Sprintf(`?page=%v&pp=%v%v`, prev, sp.PerPage, query)
nextQuery := fmt.Sprintf(`?page=%v&pp=%v%v`, next, sp.PerPage, query)
prevClass := ""
nextClass := ""
if next > sp.TotalPages {
nextClass = "disabled"
nextQuery = ""
}
if prev == 0 {
prevClass = "disabled"
prevQuery = ""
}
return template.HTML(`<nav aria-label="Page navigation" class="text-center">
<ul class="pagination">
<li class="` + prevClass + `">
<a href="` + prevQuery + `" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</li>
` + str +
` <li class="` + nextClass + `">
<a href="` + nextQuery + `" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</li>
</ul>
</nav>`)
}
*/
func logoForHelper(name string) template.HTML {
fontName := map[string]string{
"gplus": "google",
"facebook": "facebook-official",
"github": "github",
}
return template.HTML(`<i class="fa fa-` + fontName[name] + `"></i>`)
}