2023-02-21 12:32:09 -05:00
|
|
|
package css
|
|
|
|
|
|
|
|
import (
|
2023-02-25 03:24:59 -05:00
|
|
|
"context"
|
|
|
|
|
2023-02-21 12:32:09 -05:00
|
|
|
"github.com/gohugoio/hugo/common/types/css"
|
|
|
|
"github.com/gohugoio/hugo/deps"
|
|
|
|
"github.com/gohugoio/hugo/tpl/internal"
|
|
|
|
"github.com/spf13/cast"
|
|
|
|
)
|
|
|
|
|
|
|
|
const name = "css"
|
|
|
|
|
|
|
|
// Namespace provides template functions for the "css" namespace.
|
2024-01-28 16:34:10 -05:00
|
|
|
type Namespace struct{}
|
2023-02-21 12:32:09 -05:00
|
|
|
|
|
|
|
// Quoted returns a string that needs to be quoted in CSS.
|
|
|
|
func (ns *Namespace) Quoted(v any) css.QuotedString {
|
|
|
|
s := cast.ToString(v)
|
|
|
|
return css.QuotedString(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unquoted returns a string that does not need to be quoted in CSS.
|
|
|
|
func (ns *Namespace) Unquoted(v any) css.UnquotedString {
|
|
|
|
s := cast.ToString(v)
|
|
|
|
return css.UnquotedString(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
f := func(d *deps.Deps) *internal.TemplateFuncsNamespace {
|
|
|
|
ctx := &Namespace{}
|
|
|
|
|
|
|
|
ns := &internal.TemplateFuncsNamespace{
|
|
|
|
Name: name,
|
2023-02-25 03:24:59 -05:00
|
|
|
Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil },
|
2023-02-21 12:32:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return ns
|
|
|
|
}
|
|
|
|
|
|
|
|
internal.AddTemplateFuncsNamespace(f)
|
|
|
|
}
|