gorm wire
This commit is contained in:
61
internal/pkg/render/funcs/method.go
Normal file
61
internal/pkg/render/funcs/method.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package funcs
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Methods() map[string]any {
|
||||
res := make(map[string]any, 1)
|
||||
|
||||
res["dateFormat"] = func(dt time.Time) template.HTML {
|
||||
return template.HTML(dt.Format(time.DateTime))
|
||||
}
|
||||
|
||||
res["today"] = func() template.HTML {
|
||||
return template.HTML(time.Now().Format("2006-01-02"))
|
||||
}
|
||||
|
||||
res["threeMonth"] = func() template.HTML {
|
||||
return template.HTML(time.Now().AddDate(0, 3, 0).Format("2006-01-02"))
|
||||
}
|
||||
|
||||
res["yearBegin"] = func() template.HTML {
|
||||
dt := time.Now()
|
||||
t := dt.AddDate(0, -int(dt.Month())+1, -dt.Day()+1)
|
||||
return template.HTML(t.Format("2006-01-02") + " 00:00:00")
|
||||
}
|
||||
|
||||
res["monthBegin"] = func() template.HTML {
|
||||
dt := time.Now()
|
||||
t := dt.AddDate(0, 0, -dt.Day()+1)
|
||||
return template.HTML(t.Format("2006-01-02") + " 00:00:00")
|
||||
}
|
||||
|
||||
res["monthEnd"] = func() template.HTML {
|
||||
dt := time.Now()
|
||||
t := dt.AddDate(0, 0, -dt.Day()+1).AddDate(0, 1, -1)
|
||||
return template.HTML(t.Format("2006-01-02") + " 23:59:59")
|
||||
}
|
||||
|
||||
res["trimSpace"] = func(s string) template.HTML {
|
||||
return template.HTML(strings.TrimSpace(s))
|
||||
}
|
||||
|
||||
res["expandTags"] = func(s []string) template.HTML {
|
||||
if len(s) == 0 {
|
||||
return ""
|
||||
}
|
||||
if len(s) == 1 && s[0] == "all" {
|
||||
return ""
|
||||
}
|
||||
return template.HTML(strings.Join(s, ","))
|
||||
}
|
||||
|
||||
res["toString"] = func(b []byte) string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
Reference in New Issue
Block a user