v0.30: product pages, categories, sale prices and order status timeline

This commit is contained in:
shop
2026-06-25 17:29:43 +03:00
parent 532351e1c9
commit e000264bb1
26 changed files with 1061 additions and 248 deletions
+22 -1
View File
@@ -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")
}