This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
/
render.go
72 lines (60 loc) · 1.55 KB
/
render.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
package actions
import (
"bytes"
"html/template"
"strings"
"github.com/gobuffalo/buffalo/render"
"github.com/gobuffalo/packr/v2"
"github.com/gobuffalo/tags"
"github.com/gobuffalo/toolkit/models/discovery"
)
var r *render.Engine
var assetsBox = packr.New("../public", "../public")
var Helpers = render.Helpers{
"knownTagsMD": knownTagsMD,
"topicLinks": topicLinks,
"knownTagsHTML": knownTagsHTML,
}
func init() {
r = render.New(render.Options{
// HTML layout to be used for all HTML requests:
HTMLLayout: "application.plush.html",
// Box containing all of the templates:
TemplatesBox: packr.New("../templates", "../templates"),
AssetsBox: assetsBox,
// Add template helpers here:
Helpers: Helpers,
})
}
func knownTagsMD() string {
bb := &bytes.Buffer{}
for _, tag := range discovery.KnownTags {
bb.WriteString("* `" + tag.Tag + "` - " + tag.Description + "\n")
}
return bb.String()
}
func knownTagsHTML() (template.HTML, error) {
t := tags.New("span", nil)
var as []string
for _, tag := range discovery.KnownTags {
as = append(as, tags.New("a", tags.Options{
"href": "/tools?topic=" + tag.Tag,
"body": tag.Tag,
"class": "category-link",
}).String())
}
t.Append(strings.Join(as, " "))
return t.HTML(), nil
}
func topicLinks(topics []string) (template.HTML, error) {
t := tags.New("span", nil)
var as []string
for _, topic := range topics {
as = append(as, tags.New("a", tags.Options{
"href": "/tools?topic=" + topic,
"body": topic,
}).String())
}
t.Append(strings.Join(as, " "))
return t.HTML(), nil
}