aboutsummaryrefslogtreecommitdiffstats
path: root/modules/templates/helper.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/templates/helper.go')
-rw-r--r--modules/templates/helper.go92
1 files changed, 5 insertions, 87 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go
index 56be050481..407b2c64f5 100644
--- a/modules/templates/helper.go
+++ b/modules/templates/helper.go
@@ -8,7 +8,6 @@ import (
"bytes"
"context"
"encoding/hex"
- "errors"
"fmt"
"html"
"html/template"
@@ -219,20 +218,6 @@ func NewFuncMap() []template.FuncMap {
"DisableImportLocal": func() bool {
return !setting.ImportLocalPaths
},
- "Dict": func(values ...interface{}) (map[string]interface{}, error) {
- if len(values)%2 != 0 {
- return nil, errors.New("invalid dict call")
- }
- dict := make(map[string]interface{}, len(values)/2)
- for i := 0; i < len(values); i += 2 {
- key, ok := values[i].(string)
- if !ok {
- return nil, errors.New("dict keys must be strings")
- }
- dict[key] = values[i+1]
- }
- return dict, nil
- },
"Printf": fmt.Sprintf,
"Escape": Escape,
"Sec2Time": util.SecToTime,
@@ -242,35 +227,7 @@ func NewFuncMap() []template.FuncMap {
"DefaultTheme": func() string {
return setting.UI.DefaultTheme
},
- // pass key-value pairs to a partial template which receives them as a dict
- "dict": func(values ...interface{}) (map[string]interface{}, error) {
- if len(values) == 0 {
- return nil, errors.New("invalid dict call")
- }
-
- dict := make(map[string]interface{})
- return util.MergeInto(dict, values...)
- },
- /* like dict but merge key-value pairs into the first dict and return it */
- "mergeinto": func(root map[string]interface{}, values ...interface{}) (map[string]interface{}, error) {
- if len(values) == 0 {
- return nil, errors.New("invalid mergeinto call")
- }
-
- dict := make(map[string]interface{})
- for key, value := range root {
- dict[key] = value
- }
-
- return util.MergeInto(dict, values...)
- },
- "percentage": func(n int, values ...int) float32 {
- sum := 0
- for i := 0; i < len(values); i++ {
- sum += values[i]
- }
- return float32(n) * 100 / float32(sum)
- },
+ "dict": dict,
"CommentMustAsDiff": gitdiff.CommentMustAsDiff,
"MirrorRemoteAddress": mirrorRemoteAddress,
"NotificationSettings": func() map[string]interface{} {
@@ -413,52 +370,13 @@ func NewTextFuncMap() []texttmpl.FuncMap {
},
"EllipsisString": base.EllipsisString,
"URLJoin": util.URLJoin,
- "Dict": func(values ...interface{}) (map[string]interface{}, error) {
- if len(values)%2 != 0 {
- return nil, errors.New("invalid dict call")
- }
- dict := make(map[string]interface{}, len(values)/2)
- for i := 0; i < len(values); i += 2 {
- key, ok := values[i].(string)
- if !ok {
- return nil, errors.New("dict keys must be strings")
- }
- dict[key] = values[i+1]
- }
- return dict, nil
- },
- "Printf": fmt.Sprintf,
- "Escape": Escape,
- "Sec2Time": util.SecToTime,
+ "Printf": fmt.Sprintf,
+ "Escape": Escape,
+ "Sec2Time": util.SecToTime,
"ParseDeadline": func(deadline string) []string {
return strings.Split(deadline, "|")
},
- "dict": func(values ...interface{}) (map[string]interface{}, error) {
- if len(values) == 0 {
- return nil, errors.New("invalid dict call")
- }
-
- dict := make(map[string]interface{})
-
- for i := 0; i < len(values); i++ {
- switch key := values[i].(type) {
- case string:
- i++
- if i == len(values) {
- return nil, errors.New("specify the key for non array values")
- }
- dict[key] = values[i]
- case map[string]interface{}:
- m := values[i].(map[string]interface{})
- for i, v := range m {
- dict[i] = v
- }
- default:
- return nil, errors.New("dict values must be maps")
- }
- }
- return dict, nil
- },
+ "dict": dict,
"QueryEscape": url.QueryEscape,
"Eval": Eval,
}}