1
0
Fork 0
mirror of https://github.com/Luzifer/korvike.git synced 2024-11-08 15:30:05 +00:00

Add basic string manipulation join and split

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2022-03-30 21:10:35 +02:00
parent d57cf8eb59
commit bea23f0bf1
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D
2 changed files with 20 additions and 0 deletions

View file

@ -47,6 +47,12 @@
$ echo '{{ hash "sha256" "this is a test" }}' | korvike
2e99758548972a8e8822ad47fa1017ff72f06f3ff6a016851f45c398732bc50c
```
- `{{ join <string> <delim> }}`
Joins the given slice of strings with given delimiter.
```console
$ echo '{{ join (split "a,b,c" ",") "|" }}' | korvike
a|b|c
```
- `{{ markdown <source> }}`
Format the source using a markdown parser
```console
@ -59,6 +65,12 @@
$ echo '{{ now "2006-01-02 15:04:05" }}' | korvike
2017-04-17 16:27:34
```
- `{{ split <string> <sep> }}`
Splits the given string by given separator.
```console
$ echo '{{ range (split "a,b,c" ",") }}{{ . }} {{ end }}' | korvike
a b c
```
- `{{ tplexec (file "my.tpl") }}`
Execute the given template with the same function set and variables as the parent template.
```console

View file

@ -0,0 +1,8 @@
package functions
import "strings"
func init() {
registerFunction("join", strings.Join)
registerFunction("split", strings.Split)
}