49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package templates
|
|
|
|
import (
|
|
"fmt"
|
|
"html/template"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func templateFuncs() template.FuncMap {
|
|
return template.FuncMap{
|
|
"formatDate": func(t time.Time) string {
|
|
return t.Format("Jan 2, 2006")
|
|
},
|
|
"formatDateTime": func(t time.Time) string {
|
|
return t.Format("Jan 2, 2006 3:04 PM")
|
|
},
|
|
"statusBadge": func(status string) template.HTML {
|
|
var class string
|
|
switch status {
|
|
case "open":
|
|
class = "bg-yellow-100 text-yellow-800"
|
|
case "in_progress":
|
|
class = "bg-blue-100 text-blue-800"
|
|
case "closed":
|
|
class = "bg-green-100 text-green-800"
|
|
default:
|
|
class = "bg-gray-100 text-gray-800"
|
|
}
|
|
label := strings.ReplaceAll(status, "_", " ")
|
|
return template.HTML(fmt.Sprintf(`<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium %s">%s</span>`, class, label))
|
|
},
|
|
"truncate": func(s string, n int) string {
|
|
if len(s) <= n {
|
|
return s
|
|
}
|
|
return s[:n] + "..."
|
|
},
|
|
"dict": func(values ...interface{}) map[string]interface{} {
|
|
dict := make(map[string]interface{})
|
|
for i := 0; i < len(values)-1; i += 2 {
|
|
key, _ := values[i].(string)
|
|
dict[key] = values[i+1]
|
|
}
|
|
return dict
|
|
},
|
|
}
|
|
}
|