mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-15 20:44:01 +02:00
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:
@@ -31,6 +31,11 @@ func init() {
|
||||
Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil },
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.Babel,
|
||||
[]string{"babel"},
|
||||
[][2]string{},
|
||||
)
|
||||
|
||||
return ns
|
||||
}
|
||||
|
||||
|
30
tpl/js/js.go
30
tpl/js/js.go
@@ -15,9 +15,12 @@
|
||||
package js
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/gohugoio/hugo/deps"
|
||||
"github.com/gohugoio/hugo/resources"
|
||||
"github.com/gohugoio/hugo/resources/resource"
|
||||
"github.com/gohugoio/hugo/resources/resource_transformers/babel"
|
||||
"github.com/gohugoio/hugo/resources/resource_transformers/js"
|
||||
"github.com/gohugoio/hugo/tpl/internal/resourcehelpers"
|
||||
)
|
||||
@@ -28,13 +31,15 @@ func New(deps *deps.Deps) *Namespace {
|
||||
return &Namespace{}
|
||||
}
|
||||
return &Namespace{
|
||||
client: js.New(deps.BaseFs.Assets, deps.ResourceSpec),
|
||||
client: js.New(deps.BaseFs.Assets, deps.ResourceSpec),
|
||||
babelClient: babel.New(deps.ResourceSpec),
|
||||
}
|
||||
}
|
||||
|
||||
// Namespace provides template functions for the "js" namespace.
|
||||
type Namespace struct {
|
||||
client *js.Client
|
||||
client *js.Client
|
||||
babelClient *babel.Client
|
||||
}
|
||||
|
||||
// Build processes the given Resource with ESBuild.
|
||||
@@ -62,3 +67,24 @@ func (ns *Namespace) Build(args ...any) (resource.Resource, error) {
|
||||
|
||||
return ns.client.Process(r, m)
|
||||
}
|
||||
|
||||
// Babel processes the given Resource with Babel.
|
||||
func (ns *Namespace) Babel(args ...any) (resource.Resource, error) {
|
||||
if len(args) > 2 {
|
||||
return nil, errors.New("must not provide more arguments than resource object and options")
|
||||
}
|
||||
|
||||
r, m, err := resourcehelpers.ResolveArgs(args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var options babel.Options
|
||||
if m != nil {
|
||||
options, err = babel.DecodeOptions(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return ns.babelClient.Process(r, options)
|
||||
}
|
||||
|
Reference in New Issue
Block a user