1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-18 10:07:02 +00:00

Web server now starts

Can serve static content, no dynamic stuff yet
This commit is contained in:
James Hillyerd
2012-10-20 23:03:59 -07:00
parent 81fea97a90
commit 442e8fbe14
8 changed files with 150 additions and 20 deletions

View File

@@ -1,19 +1,35 @@
package controllers
package web
import (
"github.com/robfig/revel"
"fmt"
"github.com/jhillyerd/inbucket"
"html/template"
"time"
)
func init() {
rev.TRACE.Println("Registering helpers")
rev.Funcs["friendlyTime"] = func(t time.Time) template.HTML {
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
},
// Friendly date & time rendering
"friendlyTime": func(t time.Time) template.HTML {
ty, tm, td := t.Date()
ny, nm, nd := time.Now().Date()
if (ty == ny) && (tm == nm) && (td == nd) {
return template.HTML(t.Format("03:04:05 PM"))
}
return template.HTML(t.Format("Mon Jan 2, 2006"))
}
},
}