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:
parent
d57cf8eb59
commit
bea23f0bf1
2 changed files with 20 additions and 0 deletions
12
README.md
12
README.md
|
@ -47,6 +47,12 @@
|
||||||
$ echo '{{ hash "sha256" "this is a test" }}' | korvike
|
$ echo '{{ hash "sha256" "this is a test" }}' | korvike
|
||||||
2e99758548972a8e8822ad47fa1017ff72f06f3ff6a016851f45c398732bc50c
|
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> }}`
|
- `{{ markdown <source> }}`
|
||||||
Format the source using a markdown parser
|
Format the source using a markdown parser
|
||||||
```console
|
```console
|
||||||
|
@ -59,6 +65,12 @@
|
||||||
$ echo '{{ now "2006-01-02 15:04:05" }}' | korvike
|
$ echo '{{ now "2006-01-02 15:04:05" }}' | korvike
|
||||||
2017-04-17 16:27:34
|
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") }}`
|
- `{{ tplexec (file "my.tpl") }}`
|
||||||
Execute the given template with the same function set and variables as the parent template.
|
Execute the given template with the same function set and variables as the parent template.
|
||||||
```console
|
```console
|
||||||
|
|
8
functions/func_strings.go
Normal file
8
functions/func_strings.go
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
package functions
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
registerFunction("join", strings.Join)
|
||||||
|
registerFunction("split", strings.Split)
|
||||||
|
}
|
Loading…
Reference in a new issue