2023-05-04 13:39:29 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-05-06 15:00:43 +00:00
|
|
|
"embed"
|
|
|
|
"github.com/fthvgb1/wp-go/app/cmd/route"
|
2023-05-04 13:39:29 +00:00
|
|
|
"github.com/fthvgb1/wp-go/app/pkg/constraints"
|
2023-05-06 15:00:43 +00:00
|
|
|
"github.com/fthvgb1/wp-go/app/pkg/logs"
|
|
|
|
"github.com/fthvgb1/wp-go/app/plugins/wphandle"
|
2023-05-04 13:39:29 +00:00
|
|
|
"github.com/fthvgb1/wp-go/app/theme"
|
|
|
|
"github.com/fthvgb1/wp-go/app/theme/wp"
|
2023-05-06 15:00:43 +00:00
|
|
|
"github.com/fthvgb1/wp-go/app/theme/wp/components"
|
|
|
|
"github.com/fthvgb1/wp-go/app/theme/wp/components/widget"
|
|
|
|
route2 "github.com/fthvgb1/wp-go/app/theme/wp/route"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"html/template"
|
|
|
|
"net/http"
|
2023-05-04 13:39:29 +00:00
|
|
|
"plugintt/xx"
|
|
|
|
)
|
|
|
|
|
2023-05-06 15:00:43 +00:00
|
|
|
//go:embed a.gohtml
|
|
|
|
var em embed.FS
|
|
|
|
var tt *template.Template
|
|
|
|
|
2023-05-04 13:39:29 +00:00
|
|
|
func init() {
|
2023-05-06 15:00:43 +00:00
|
|
|
// register as theme
|
|
|
|
theme.AddThemeHookFunc("themename", hook)
|
|
|
|
|
|
|
|
//use the local template
|
|
|
|
//note: must use embed.FS
|
|
|
|
t, err := template.ParseFS(em, "a.gohtml")
|
|
|
|
if err != nil {
|
|
|
|
logs.Error(err, "")
|
|
|
|
}
|
|
|
|
tt = t
|
|
|
|
|
|
|
|
// register gin route. it will be effecting when server restart.
|
|
|
|
route.Hook(func(r *gin.Engine) {
|
|
|
|
r.GET("xx", func(c *gin.Context) {
|
|
|
|
c.String(http.StatusOK, "xxoo")
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func hook(h *wp.Handle) {
|
|
|
|
wp.Run(h, config)
|
|
|
|
}
|
|
|
|
|
|
|
|
func config(h *wp.Handle) {
|
|
|
|
// same theme config
|
|
|
|
wphandle.UsePlugins(h)
|
|
|
|
wp.InitPipe(h)
|
|
|
|
h.PushHandler(constraints.PipeMiddleware, constraints.Home,
|
|
|
|
wp.NewHandleFn(widget.IsCategory, 100, "widget.IsCategory"))
|
|
|
|
components.WidgetArea(h)
|
|
|
|
h.PushHandler(constraints.PipeRender, constraints.Home, wp.NewHandleFn(func(h *wp.Handle) {
|
|
|
|
h.SetData("aa", "xyxxxx")
|
|
|
|
h.RenderHtml(tt, http.StatusOK, "a.gohtml")
|
|
|
|
h.Abort()
|
|
|
|
h.StopPipe()
|
|
|
|
}, 10, "renderHome"))
|
|
|
|
|
|
|
|
// use simple reg route
|
|
|
|
route2.PushRoute(`(?P<control>\w+)/(?P<method>\w+)`, route2.Route{
|
|
|
|
Path: `(?P<control>\w+)/(?P<method>\w+)`,
|
|
|
|
Scene: constraints.Home,
|
|
|
|
Method: []string{"GET"},
|
|
|
|
Type: "reg",
|
|
|
|
})
|
|
|
|
//...
|
2023-05-04 13:39:29 +00:00
|
|
|
}
|
|
|
|
|
2023-05-06 15:00:43 +00:00
|
|
|
// Xo to be a func when theme init
|
2023-05-04 13:39:29 +00:00
|
|
|
func Xo(h *wp.Handle) {
|
2023-05-06 15:00:43 +00:00
|
|
|
xx.Xo()
|
|
|
|
route2.Delete(`(?P<control>\w+)/(?P<method>\w+)`)
|
|
|
|
h.ReplaceHandle(constraints.PipeRender, "wp.RenderTemplate", func(h *wp.Handle) {
|
|
|
|
h.SetData("aa", "xyxxxx")
|
|
|
|
h.RenderHtml(tt, http.StatusOK, "a.gohtml")
|
|
|
|
h.StopPipe()
|
2023-05-04 13:39:29 +00:00
|
|
|
})
|
|
|
|
}
|