diff options
Diffstat (limited to 'modules/templates/helper.go')
-rw-r--r-- | modules/templates/helper.go | 36 |
1 files changed, 5 insertions, 31 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 42680827eb..c5b77989be 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -15,7 +15,6 @@ import ( "mime" "net/url" "path/filepath" - "reflect" "regexp" "strings" "time" @@ -68,11 +67,15 @@ func NewFuncMap() []template.FuncMap { "PathEscape": url.PathEscape, "PathEscapeSegments": util.PathEscapeSegments, + // utils + "StringUtils": NewStringUtils, + "SliceUtils": NewSliceUtils, + // ----------------------------------------------------------------- // string / json + // TODO: move string helper functions to StringUtils "Join": strings.Join, "DotEscape": DotEscape, - "HasPrefix": strings.HasPrefix, "EllipsisString": base.EllipsisString, "DumpVar": dumpVar, @@ -145,35 +148,6 @@ func NewFuncMap() []template.FuncMap { }, // ----------------------------------------------------------------- - // slice - "containGeneric": func(arr, v interface{}) bool { - arrV := reflect.ValueOf(arr) - if arrV.Kind() == reflect.String && reflect.ValueOf(v).Kind() == reflect.String { - return strings.Contains(arr.(string), v.(string)) - } - if arrV.Kind() == reflect.Slice { - for i := 0; i < arrV.Len(); i++ { - iV := arrV.Index(i) - if !iV.CanInterface() { - continue - } - if iV.Interface() == v { - return true - } - } - } - return false - }, - "contain": func(s []int64, id int64) bool { - for i := 0; i < len(s); i++ { - if s[i] == id { - return true - } - } - return false - }, - - // ----------------------------------------------------------------- // setting "AppName": func() string { return setting.AppName |