mirror of
https://github.com/gohugoio/hugo.git
synced 2025-09-01 22:42:45 +02:00
@@ -26,7 +26,7 @@ func init() {
|
||||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func(args ...interface{}) (interface{}, error) { return ctx, nil },
|
||||
Context: func(args ...any) (any, error) { return ctx, nil },
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.CSS,
|
||||
|
@@ -31,43 +31,43 @@ func New() *Namespace {
|
||||
type Namespace struct{}
|
||||
|
||||
// CSS returns a given string as html/template CSS content.
|
||||
func (ns *Namespace) CSS(a interface{}) (template.CSS, error) {
|
||||
func (ns *Namespace) CSS(a any) (template.CSS, error) {
|
||||
s, err := cast.ToStringE(a)
|
||||
return template.CSS(s), err
|
||||
}
|
||||
|
||||
// HTML returns a given string as html/template HTML content.
|
||||
func (ns *Namespace) HTML(a interface{}) (template.HTML, error) {
|
||||
func (ns *Namespace) HTML(a any) (template.HTML, error) {
|
||||
s, err := cast.ToStringE(a)
|
||||
return template.HTML(s), err
|
||||
}
|
||||
|
||||
// HTMLAttr returns a given string as html/template HTMLAttr content.
|
||||
func (ns *Namespace) HTMLAttr(a interface{}) (template.HTMLAttr, error) {
|
||||
func (ns *Namespace) HTMLAttr(a any) (template.HTMLAttr, error) {
|
||||
s, err := cast.ToStringE(a)
|
||||
return template.HTMLAttr(s), err
|
||||
}
|
||||
|
||||
// JS returns the given string as a html/template JS content.
|
||||
func (ns *Namespace) JS(a interface{}) (template.JS, error) {
|
||||
func (ns *Namespace) JS(a any) (template.JS, error) {
|
||||
s, err := cast.ToStringE(a)
|
||||
return template.JS(s), err
|
||||
}
|
||||
|
||||
// JSStr returns the given string as a html/template JSStr content.
|
||||
func (ns *Namespace) JSStr(a interface{}) (template.JSStr, error) {
|
||||
func (ns *Namespace) JSStr(a any) (template.JSStr, error) {
|
||||
s, err := cast.ToStringE(a)
|
||||
return template.JSStr(s), err
|
||||
}
|
||||
|
||||
// URL returns a given string as html/template URL content.
|
||||
func (ns *Namespace) URL(a interface{}) (template.URL, error) {
|
||||
func (ns *Namespace) URL(a any) (template.URL, error) {
|
||||
s, err := cast.ToStringE(a)
|
||||
return template.URL(s), err
|
||||
}
|
||||
|
||||
// SanitizeURL returns a given string as html/template URL content.
|
||||
func (ns *Namespace) SanitizeURL(a interface{}) (string, error) {
|
||||
func (ns *Namespace) SanitizeURL(a any) (string, error) {
|
||||
s, err := cast.ToStringE(a)
|
||||
return helpers.SanitizeURL(s), err
|
||||
}
|
||||
|
@@ -29,8 +29,8 @@ func TestCSS(t *testing.T) {
|
||||
ns := New()
|
||||
|
||||
for _, test := range []struct {
|
||||
a interface{}
|
||||
expect interface{}
|
||||
a any
|
||||
expect any
|
||||
}{
|
||||
{`a[href =~ "//example.com"]#foo`, template.CSS(`a[href =~ "//example.com"]#foo`)},
|
||||
// errors
|
||||
@@ -56,8 +56,8 @@ func TestHTML(t *testing.T) {
|
||||
ns := New()
|
||||
|
||||
for _, test := range []struct {
|
||||
a interface{}
|
||||
expect interface{}
|
||||
a any
|
||||
expect any
|
||||
}{
|
||||
{`Hello, <b>World</b> &tc!`, template.HTML(`Hello, <b>World</b> &tc!`)},
|
||||
// errors
|
||||
@@ -83,8 +83,8 @@ func TestHTMLAttr(t *testing.T) {
|
||||
ns := New()
|
||||
|
||||
for _, test := range []struct {
|
||||
a interface{}
|
||||
expect interface{}
|
||||
a any
|
||||
expect any
|
||||
}{
|
||||
{` dir="ltr"`, template.HTMLAttr(` dir="ltr"`)},
|
||||
// errors
|
||||
@@ -109,8 +109,8 @@ func TestJS(t *testing.T) {
|
||||
ns := New()
|
||||
|
||||
for _, test := range []struct {
|
||||
a interface{}
|
||||
expect interface{}
|
||||
a any
|
||||
expect any
|
||||
}{
|
||||
{`c && alert("Hello, World!");`, template.JS(`c && alert("Hello, World!");`)},
|
||||
// errors
|
||||
@@ -136,8 +136,8 @@ func TestJSStr(t *testing.T) {
|
||||
ns := New()
|
||||
|
||||
for _, test := range []struct {
|
||||
a interface{}
|
||||
expect interface{}
|
||||
a any
|
||||
expect any
|
||||
}{
|
||||
{`Hello, World & O'Reilly\x21`, template.JSStr(`Hello, World & O'Reilly\x21`)},
|
||||
// errors
|
||||
@@ -163,8 +163,8 @@ func TestURL(t *testing.T) {
|
||||
ns := New()
|
||||
|
||||
for _, test := range []struct {
|
||||
a interface{}
|
||||
expect interface{}
|
||||
a any
|
||||
expect any
|
||||
}{
|
||||
{`greeting=H%69&addressee=(World)`, template.URL(`greeting=H%69&addressee=(World)`)},
|
||||
// errors
|
||||
@@ -190,8 +190,8 @@ func TestSanitizeURL(t *testing.T) {
|
||||
ns := New()
|
||||
|
||||
for _, test := range []struct {
|
||||
a interface{}
|
||||
expect interface{}
|
||||
a any
|
||||
expect any
|
||||
}{
|
||||
{"http://foo/../../bar", "http://foo/bar"},
|
||||
// errors
|
||||
|
Reference in New Issue
Block a user