v0.30: product pages, categories, sale prices and order status timeline
This commit is contained in:
@@ -7,6 +7,9 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"regexp"
|
||||
|
||||
"shop/internal/models"
|
||||
"shop/internal/orderstatus"
|
||||
)
|
||||
|
||||
//go:embed templates/*
|
||||
@@ -21,9 +24,27 @@ func stripHTML(s string) string {
|
||||
return tagRe.ReplaceAllString(s, "")
|
||||
}
|
||||
|
||||
func effectivePrice(p models.Product) float64 { return p.EffectivePrice() }
|
||||
|
||||
func ParseTemplates() (*template.Template, error) {
|
||||
funcMap := template.FuncMap{
|
||||
"plain": stripHTML,
|
||||
"plain": stripHTML,
|
||||
"effective": effectivePrice,
|
||||
"safeHTML": func(s string) template.HTML { return template.HTML(s) },
|
||||
"orderLabel": orderstatus.Label,
|
||||
"orderClass": orderstatus.Class,
|
||||
"orderStep": orderstatus.Step,
|
||||
"orderTimeline": func() []string { return orderstatus.Timeline },
|
||||
"stepDone": func(status, step string) bool {
|
||||
cur, s := orderstatus.Step(status), orderstatus.Step(step)
|
||||
return cur > 0 && s > 0 && s < cur
|
||||
},
|
||||
"stepCurrent": func(status, step string) bool {
|
||||
return orderstatus.Step(status) == orderstatus.Step(step)
|
||||
},
|
||||
"catSelected": func(catID int, productCatID *int) bool {
|
||||
return productCatID != nil && *productCatID == catID
|
||||
},
|
||||
}
|
||||
return template.New("").Funcs(funcMap).ParseFS(templateFS, "templates/*.html")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user