From 292472e2310a90e2dd6379dd8102f5c61c22326a Mon Sep 17 00:00:00 2001 From: Ben Chang Date: Sat, 12 Dec 2020 00:06:42 +0800 Subject: [PATCH 1/2] Update template.go add a built function "isStrFullMatch" for template --- template.go | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/template.go b/template.go index a42d15c..d5d49d3 100644 --- a/template.go +++ b/template.go @@ -115,21 +115,29 @@ func loop(args ...int) (<-chan int, error) { return c, nil } +func isStrFullMatch(src, dst string) bool { + if src == dst { + return true + } + return false +} + func generateFile(templatePath, destPath string) bool { tmpl := template.New(filepath.Base(templatePath)).Funcs(template.FuncMap{ - "contains": contains, - "exists": exists, - "split": strings.Split, - "replace": strings.Replace, - "default": defaultValue, - "parseUrl": parseUrl, - "atoi": strconv.Atoi, - "add": add, - "isTrue": isTrue, - "lower": strings.ToLower, - "upper": strings.ToUpper, - "jsonQuery": jsonQuery, - "loop": loop, + "contains": contains, + "exists": exists, + "split": strings.Split, + "replace": strings.Replace, + "default": defaultValue, + "parseUrl": parseUrl, + "atoi": strconv.Atoi, + "add": add, + "isTrue": isTrue, + "lower": strings.ToLower, + "upper": strings.ToUpper, + "jsonQuery": jsonQuery, + "loop": loop, + "isStrFullMatch": isStrFullMatch, }) if len(delims) > 0 { From 36df758a0e864ab914aa3fb5dbaec0968386da61 Mon Sep 17 00:00:00 2001 From: Ben Chang Date: Sat, 12 Dec 2020 00:10:01 +0800 Subject: [PATCH 2/2] Update README.md add built in function `isStrFullMatch` for template --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b72398c..fcead74 100644 --- a/README.md +++ b/README.md @@ -178,6 +178,7 @@ There are a few built in functions as well: * `upper $value` - Uppercase a string. * `jsonQuery $json $query` - Returns the result of a selection query against a json document. * `loop` - Create for loops. + * `isStrFullMatch` - Returns true if a string is match another string ### jsonQuery