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
}
+3
View File
@@ -22,6 +22,9 @@ func AmWrap(myfunc func(AmContext) (string, any, error)) echo.HandlerFunc {
switch what {
case "template":
err = amctxt.Render(fmt.Sprintf("%v", rc))
case "framed_template":
amctxt.VarMap().Set("amsterdam_innerPage", rc)
err = amctxt.Render("frame.jet")
default:
err = fmt.Errorf("unknown rendering type: %s", what)
}
+37
View File
@@ -0,0 +1,37 @@
/*
* Amsterdam Web Communities System
* Copyright (c) 2025 Erbosoft Metaverse Design Solutions, All Rights Reserved
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package ui
import (
"io"
"github.com/CloudyKit/jet/v6"
"github.com/labstack/echo/v4"
)
var views = jet.NewSet(
jet.NewOSFileSystemLoader("./views"),
jet.DevelopmentMode(true),
)
type TemplateRenderer struct {
}
func (r *TemplateRenderer) Render(w io.Writer, name string, data any, c echo.Context) error {
view, err := views.GetTemplate(name)
if err != nil {
return err
}
var vmap jet.VarMap = nil
amctxt := AmContextFromEchoContext(c)
if amctxt != nil {
vmap = amctxt.VarMap()
}
return view.Execute(w, vmap, data)
}