1
0
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:
James Hillyerd
2012-10-21 12:42:54 -07:00
parent 9c94bb2ab1
commit 71bb52a64a
17 changed files with 238 additions and 147 deletions

View File

@@ -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
}