Clean up the css related template funcs package structure

Deprecate and move:

* resources.ToCSS => css.SASS
* resources.PostProcess => css.PostProcess
* resources.Babel => js.Babel

Updates #12618
This commit is contained in:
Bjørn Erik Pedersen
2024-06-23 12:10:35 +02:00
parent 1687a9a585
commit eddcd2bac6
7 changed files with 241 additions and 162 deletions

View File

@@ -17,7 +17,9 @@ import (
"context"
"github.com/gohugoio/hugo/deps"
"github.com/gohugoio/hugo/tpl/css"
"github.com/gohugoio/hugo/tpl/internal"
"github.com/gohugoio/hugo/tpl/js"
)
const name = "resources"
@@ -33,6 +35,22 @@ func init() {
ns := &internal.TemplateFuncsNamespace{
Name: name,
Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil },
OnCreated: func(m map[string]any) {
for _, v := range m {
switch v := v.(type) {
case *css.Namespace:
ctx.cssNs = v
case *js.Namespace:
ctx.jsNs = v
}
}
if ctx.cssNs == nil {
panic("css namespace not found")
}
if ctx.jsNs == nil {
panic("js namespace not found")
}
},
}
ns.AddMethodMapping(ctx.Get,
@@ -57,21 +75,6 @@ func init() {
[][2]string{},
)
ns.AddMethodMapping(ctx.ToCSS,
[]string{"toCSS"},
[][2]string{},
)
ns.AddMethodMapping(ctx.PostCSS,
[]string{"postCSS"},
[][2]string{},
)
ns.AddMethodMapping(ctx.Babel,
[]string{"babel"},
[][2]string{},
)
return ns
}