-
Notifications
You must be signed in to change notification settings - Fork 1
/
extensions.go
36 lines (30 loc) · 914 Bytes
/
extensions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package ext
import (
gohtml "github.com/Nigel2392/go-html"
"github.com/Nigel2392/router/v3/request"
"github.com/Nigel2392/router/v3/templates/extensions"
)
type GoHTMLExtension struct {
extensions.Base
HTML func(r *request.Request) *gohtml.Element
}
func NewGoHTMLExtension(name string, callback func(r *request.Request) map[string]any, html func(r *request.Request) *gohtml.Element) *GoHTMLExtension {
return &GoHTMLExtension{
Base: extensions.Base{
ExtensionName: name,
Callback: callback,
},
HTML: html,
}
}
func (s *GoHTMLExtension) String(r *request.Request) string {
return s.HTML(r).String()
}
// Returns the name of the extension.
func (s *GoHTMLExtension) Name() string {
return s.ExtensionName
}
// Returns the template data for the extension.
func (s *GoHTMLExtension) View(r *request.Request) map[string]any {
return s.Callback(r)
}