started doing framing

This commit is contained in:
2025-09-13 21:21:02 -06:00
parent ee2a8a7d2b
commit 5a437a0c64
6 changed files with 164 additions and 110 deletions
+36 -4
View File
@@ -9,33 +9,65 @@
package ui
import (
"bytes"
"net/http"
"github.com/CloudyKit/jet/v6"
"github.com/labstack/echo/v4"
)
type AmContext interface {
Render(string) error
SubRender(string) ([]byte, error)
SetRC(int)
VarMap() jet.VarMap
}
type amContext struct {
echoContext echo.Context
httprc int
}
func (c *amContext) SetRC(rc int) {
c.httprc = rc
rendervars jet.VarMap
}
func (c *amContext) Render(name string) error {
return c.echoContext.Render(c.httprc, name, c)
}
func (c *amContext) SubRender(name string) ([]byte, error) {
view, err := views.GetTemplate(name)
if err != nil {
return nil, err
}
buf := new(bytes.Buffer)
err = view.Execute(buf, c.VarMap(), c)
return buf.Bytes(), err
}
func (c *amContext) SetRC(rc int) {
c.httprc = rc
}
func (c *amContext) VarMap() jet.VarMap {
return c.rendervars
}
func NewAmContext(ctxt echo.Context) AmContext {
rc := amContext{
echoContext: ctxt,
httprc: http.StatusOK,
rendervars: make(jet.VarMap),
}
ctxt.Set("amsterdam_context", &rc)
return &rc
}
func AmContextFromEchoContext(ctxt echo.Context) AmContext {
myctxt := ctxt.Get("amsterdam_context")
if myctxt != nil {
rc, ok := myctxt.(AmContext)
if ok {
return rc
}
}
return nil
}