Refactor server and templates package

This commit is contained in:
Tom Wiesing 2023-01-19 13:22:48 +01:00
parent b6bf0a8900
commit 6ede99d7c6
No known key found for this signature in database
105 changed files with 341 additions and 339 deletions

View file

@ -1,67 +0,0 @@
package legal
import (
"context"
"net/http"
"github.com/FAU-CDI/wisski-distillery/internal/cli"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/control"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/static"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/static/custom"
_ "embed"
)
type Legal struct {
component.Base
Dependencies struct {
Static *static.Static
Custom *custom.Custom
}
}
var (
_ component.Routeable = (*Legal)(nil)
)
//go:embed "legal.html"
var legalHTML []byte
var legalTemplate = custom.Parse[legalContext]("legal.html", legalHTML, static.AssetsDefault)
type legalContext struct {
custom.BaseContext
LegalNotices string
CSRFCookie string
SessionCookie string
AssetsDisclaimer string
}
func (legal *Legal) Routes() component.Routes {
return component.Routes{
Prefix: "/legal/",
Exact: true,
CSRF: false,
}
}
func (legal *Legal) HandleRoute(ctx context.Context, route string) (http.Handler, error) {
tpl := legalTemplate.Prepare(legal.Dependencies.Custom, custom.BaseContextGaps{
Crumbs: []component.MenuItem{
{Title: "Legal", Path: "/legal/"},
},
})
return tpl.HTMLHandler(func(r *http.Request) (lc legalContext, err error) {
lc.LegalNotices = cli.LegalNotices
lc.CSRFCookie = control.CSRFCookie
lc.SessionCookie = control.SessionCookie
lc.AssetsDisclaimer = static.AssetsDisclaimer
return
}), nil
}