mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 17:47:03 +00:00
Added partial templates
mailbox/list now renders
This commit is contained in:
@@ -8,21 +8,8 @@ import (
|
||||
)
|
||||
|
||||
var TemplateFuncs = template.FuncMap{
|
||||
// Reversable routing function
|
||||
"reverse": func(name string, things ...interface{}) string {
|
||||
// Convert the things to strings
|
||||
strs := make([]string, len(things))
|
||||
for i, th := range things {
|
||||
strs[i] = fmt.Sprint(th)
|
||||
}
|
||||
// Grab the route
|
||||
u, err := Router.Get(name).URL(strs...)
|
||||
if err != nil {
|
||||
inbucket.Error("Failed to reverse route: %v", err)
|
||||
return "/ROUTE-ERROR"
|
||||
}
|
||||
return u.Path
|
||||
},
|
||||
// Reversable routing function (shared with templates)
|
||||
"reverse": reverse,
|
||||
// Friendly date & time rendering
|
||||
"friendlyTime": func(t time.Time) template.HTML {
|
||||
ty, tm, td := t.Date()
|
||||
@@ -33,3 +20,18 @@ var TemplateFuncs = template.FuncMap{
|
||||
return template.HTML(t.Format("Mon Jan 2, 2006"))
|
||||
},
|
||||
}
|
||||
|
||||
func reverse(name string, things ...interface{}) string {
|
||||
// Convert the things to strings
|
||||
strs := make([]string, len(things))
|
||||
for i, th := range things {
|
||||
strs[i] = fmt.Sprint(th)
|
||||
}
|
||||
// Grab the route
|
||||
u, err := Router.Get(name).URL(strs...)
|
||||
if err != nil {
|
||||
inbucket.Error("Failed to reverse route: %v", err)
|
||||
return "/ROUTE-ERROR"
|
||||
}
|
||||
return u.Path
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user