Skip to content

Commit 12af2c7

Browse files
Merge pull request #5 from kohkimakimoto/dev
Add config options to register pongo2 tags and filters
2 parents 4d141de + a6c1b70 commit 12af2c7

File tree

7 files changed

+33
-3
lines changed

7 files changed

+33
-3
lines changed

examples/helloworld/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
)
99

1010
require (
11+
github.com/google/uuid v1.6.0 // indirect
1112
github.com/labstack/gommon v0.4.2 // indirect
1213
github.com/mattn/go-colorable v0.1.13 // indirect
1314
github.com/mattn/go-isatty v0.0.20 // indirect

examples/helloworld/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
4+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
35
github.com/labstack/echo/v4 v4.13.3 h1:pwhpCPrTl5qry5HRdM5FwdXnhXSLSY+WE+YQSeCaafY=
46
github.com/labstack/echo/v4 v4.13.3/go.mod h1:o90YNEeQWjDozo584l7AwhJMHN0bOC4tAfg+Xox9q5g=
57
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=

examples/sharedcontext/go.mod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ module github.com/kohkimakimoto/echo-viewkit/examples/sharedcontext
22

33
go 1.23.1
44

5-
require github.com/kohkimakimoto/echo-viewkit v0.0.0-00010101000000-000000000000
5+
require (
6+
github.com/kohkimakimoto/echo-viewkit v0.0.0-00010101000000-000000000000
7+
github.com/labstack/echo/v4 v4.13.3
8+
)
69

710
require (
8-
github.com/labstack/echo/v4 v4.13.3 // indirect
11+
github.com/google/uuid v1.6.0 // indirect
912
github.com/labstack/gommon v0.4.2 // indirect
1013
github.com/mattn/go-colorable v0.1.13 // indirect
1114
github.com/mattn/go-isatty v0.0.20 // indirect

examples/sharedcontext/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
4+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
35
github.com/labstack/echo/v4 v4.13.3 h1:pwhpCPrTl5qry5HRdM5FwdXnhXSLSY+WE+YQSeCaafY=
46
github.com/labstack/echo/v4 v4.13.3/go.mod h1:o90YNEeQWjDozo584l7AwhJMHN0bOC4tAfg+Xox9q5g=
57
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=

examples/vite/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
)
99

1010
require (
11+
github.com/google/uuid v1.6.0 // indirect
1112
github.com/labstack/gommon v0.4.2 // indirect
1213
github.com/mattn/go-colorable v0.1.13 // indirect
1314
github.com/mattn/go-isatty v0.0.20 // indirect

examples/vite/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
4+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
35
github.com/labstack/echo/v4 v4.13.3 h1:pwhpCPrTl5qry5HRdM5FwdXnhXSLSY+WE+YQSeCaafY=
46
github.com/labstack/echo/v4 v4.13.3/go.mod h1:o90YNEeQWjDozo584l7AwhJMHN0bOC4tAfg+Xox9q5g=
57
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=

viewkit.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ type ViewKit struct {
3434
DefaultTemplateFileExtension string
3535
// PreProcessors is a list of PreProcessor.
3636
PreProcessors []pongo2.PreProcessor
37-
37+
// Filters is a map of filters to be registered.
38+
Filters map[string]pongo2.FilterFunction
39+
// Tags is a map of tags to be registered.
40+
Tags map[string]pongo2.TagParser
3841
// Component config
3942

4043
// DisableComponentHTMLTag disables the HTML syntax extension for components.
@@ -106,6 +109,8 @@ func New() *ViewKit {
106109
BaseDir: "",
107110
DefaultTemplateFileExtension: ".html",
108111
PreProcessors: []pongo2.PreProcessor{},
112+
Filters: map[string]pongo2.FilterFunction{},
113+
Tags: map[string]pongo2.TagParser{},
109114
DisableComponentHTMLTag: false,
110115
ComponentHTMLTagPrefix: "x-",
111116
Components: []*pongo2.Component{},
@@ -186,6 +191,20 @@ func (v *ViewKit) Renderer() (*Renderer, error) {
186191
ts.ComponentSet.TemplateSetFS = templateSetFS
187192
ts.ComponentSet.DefaultTemplateFileExtension = v.DefaultTemplateFileExtension
188193

194+
// register filters
195+
for name, filter := range v.Filters {
196+
if err := ts.RegisterFilter(name, filter); err != nil {
197+
return nil, fmt.Errorf("failed to register filter %s: %w", name, err)
198+
}
199+
}
200+
201+
// register tags
202+
for name, tag := range v.Tags {
203+
if err := ts.RegisterTag(name, tag); err != nil {
204+
return nil, fmt.Errorf("failed to register tag %s: %w", name, err)
205+
}
206+
}
207+
189208
// register components
190209
for _, dir := range v.AnonymousComponentsDirectories {
191210
if err := ts.ComponentSet.RegisterTemplateFileComponentsDirectory(dir); err != nil {

0 commit comments

Comments
 (0)