mirror of
https://github.com/gohugoio/hugo.git
synced 2025-09-02 22:52:51 +02:00
@@ -30,23 +30,23 @@ type Namespace struct {
|
||||
}
|
||||
|
||||
// ToInt converts the given value to an int.
|
||||
func (ns *Namespace) ToInt(v interface{}) (int, error) {
|
||||
func (ns *Namespace) ToInt(v any) (int, error) {
|
||||
v = convertTemplateToString(v)
|
||||
return _cast.ToIntE(v)
|
||||
}
|
||||
|
||||
// ToString converts the given value to a string.
|
||||
func (ns *Namespace) ToString(v interface{}) (string, error) {
|
||||
func (ns *Namespace) ToString(v any) (string, error) {
|
||||
return _cast.ToStringE(v)
|
||||
}
|
||||
|
||||
// ToFloat converts the given value to a float.
|
||||
func (ns *Namespace) ToFloat(v interface{}) (float64, error) {
|
||||
func (ns *Namespace) ToFloat(v any) (float64, error) {
|
||||
v = convertTemplateToString(v)
|
||||
return _cast.ToFloat64E(v)
|
||||
}
|
||||
|
||||
func convertTemplateToString(v interface{}) interface{} {
|
||||
func convertTemplateToString(v any) any {
|
||||
switch vv := v.(type) {
|
||||
case template.HTML:
|
||||
v = string(vv)
|
||||
|
@@ -27,8 +27,8 @@ func TestToInt(t *testing.T) {
|
||||
ns := New()
|
||||
|
||||
for i, test := range []struct {
|
||||
v interface{}
|
||||
expect interface{}
|
||||
v any
|
||||
expect any
|
||||
}{
|
||||
{"1", 1},
|
||||
{template.HTML("2"), 2},
|
||||
@@ -59,8 +59,8 @@ func TestToString(t *testing.T) {
|
||||
ns := New()
|
||||
|
||||
for i, test := range []struct {
|
||||
v interface{}
|
||||
expect interface{}
|
||||
v any
|
||||
expect any
|
||||
}{
|
||||
{1, "1"},
|
||||
{template.HTML("2"), "2"},
|
||||
@@ -87,8 +87,8 @@ func TestToFloat(t *testing.T) {
|
||||
ns := New()
|
||||
|
||||
for i, test := range []struct {
|
||||
v interface{}
|
||||
expect interface{}
|
||||
v any
|
||||
expect any
|
||||
}{
|
||||
{"1", 1.0},
|
||||
{template.HTML("2"), 2.0},
|
||||
|
@@ -43,7 +43,7 @@ func init() {
|
||||
|
||||
}
|
||||
|
||||
return docshelper.DocProvider{"tpl": map[string]interface{}{"funcs": namespaces}}
|
||||
return docshelper.DocProvider{"tpl": map[string]any{"funcs": namespaces}}
|
||||
}
|
||||
|
||||
docshelper.AddDocProviderFunc(docsProvider)
|
||||
|
@@ -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.ToInt,
|
||||
|
Reference in New Issue
Block a user