Add ActivePath
This commit is contained in:
+28
-1
@@ -9,12 +9,28 @@ import (
|
|||||||
type HtmxContext interface {
|
type HtmxContext interface {
|
||||||
Render(node gomponents.Node)
|
Render(node gomponents.Node)
|
||||||
GetLanguage() Language
|
GetLanguage() Language
|
||||||
|
GetActivePath() *ActivePath
|
||||||
|
HasActivePath() bool
|
||||||
|
SetActivePath(activePath *ActivePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
type HtmxContextImpl struct {
|
type HtmxContextImpl struct {
|
||||||
req *http.Request
|
req *http.Request
|
||||||
res http.ResponseWriter
|
res http.ResponseWriter
|
||||||
language Language
|
language Language
|
||||||
|
activePath *ActivePath
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *HtmxContextImpl) SetActivePath(activePath *ActivePath) {
|
||||||
|
c.activePath = activePath
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *HtmxContextImpl) GetActivePath() *ActivePath {
|
||||||
|
return c.activePath
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *HtmxContextImpl) HasActivePath() bool {
|
||||||
|
return c.activePath != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HtmxContextImpl) GetLanguage() Language {
|
func (c *HtmxContextImpl) GetLanguage() Language {
|
||||||
@@ -48,6 +64,7 @@ type HtmxRoute interface {
|
|||||||
WithPathParams(params ...HtmxPathParam) HtmxRoute
|
WithPathParams(params ...HtmxPathParam) HtmxRoute
|
||||||
ToUrl(queryParams ...HtmxPathParam) string
|
ToUrl(queryParams ...HtmxPathParam) string
|
||||||
GetHtmx(queryParams ...HtmxPathParam) gomponents.Node
|
GetHtmx(queryParams ...HtmxPathParam) gomponents.Node
|
||||||
|
SetActivePath(activePath *ActivePath) HtmxRoute
|
||||||
}
|
}
|
||||||
|
|
||||||
type HtmxGetRoute struct {
|
type HtmxGetRoute struct {
|
||||||
@@ -55,6 +72,12 @@ type HtmxGetRoute struct {
|
|||||||
RouteFunc HtmxRouteFunc
|
RouteFunc HtmxRouteFunc
|
||||||
PathParams []HtmxPathParam
|
PathParams []HtmxPathParam
|
||||||
Languages []Language
|
Languages []Language
|
||||||
|
ActivePath *ActivePath
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h HtmxGetRoute) SetActivePath(activePath *ActivePath) HtmxRoute {
|
||||||
|
h.ActivePath = activePath
|
||||||
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHtmxGetRoute(path string, routeFunc HtmxRouteFunc, languages ...Language) *HtmxGetRoute {
|
func NewHtmxGetRoute(path string, routeFunc HtmxRouteFunc, languages ...Language) *HtmxGetRoute {
|
||||||
@@ -64,7 +87,11 @@ func NewHtmxGetRoute(path string, routeFunc HtmxRouteFunc, languages ...Language
|
|||||||
func (h HtmxGetRoute) Add(server *http.ServeMux) {
|
func (h HtmxGetRoute) Add(server *http.ServeMux) {
|
||||||
for _, language := range h.Languages {
|
for _, language := range h.Languages {
|
||||||
server.HandleFunc("GET /"+string(language)+h.Path, func(res http.ResponseWriter, req *http.Request) {
|
server.HandleFunc("GET /"+string(language)+h.Path, func(res http.ResponseWriter, req *http.Request) {
|
||||||
h.RouteFunc(NewHtmxContext(req, res, language))
|
context := NewHtmxContext(req, res, language)
|
||||||
|
if h.ActivePath != nil {
|
||||||
|
context.SetActivePath(h.ActivePath)
|
||||||
|
}
|
||||||
|
h.RouteFunc(context)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user