Add namespaces and include tag, improve whitespace handling

This commit is contained in:
2023-10-29 15:47:47 -07:00
parent fb7010dae3
commit 76c0a48b87
12 changed files with 372 additions and 162 deletions
+31
View File
@@ -0,0 +1,31 @@
package salix
import (
"reflect"
"strings"
)
var globalVars = map[string]reflect.Value{
"len": reflect.ValueOf(tmplLen),
"toUpper": reflect.ValueOf(strings.ToUpper),
"toLower": reflect.ValueOf(strings.ToLower),
"hasPrefix": reflect.ValueOf(strings.HasPrefix),
"trimPrefix": reflect.ValueOf(strings.TrimPrefix),
"hasSuffix": reflect.ValueOf(strings.HasSuffix),
"trimSuffix": reflect.ValueOf(strings.TrimSuffix),
"trimSpace": reflect.ValueOf(strings.TrimSpace),
"equalFold": reflect.ValueOf(strings.EqualFold),
"count": reflect.ValueOf(strings.Count),
"split": reflect.ValueOf(strings.Split),
"join": reflect.ValueOf(strings.Join),
}
func tmplLen(v any) int {
val := reflect.ValueOf(v)
switch val.Kind() {
case reflect.Array, reflect.Slice, reflect.String, reflect.Map:
return val.Len()
default:
return -1
}
}