Skip to content

Commit 7e1ace0

Browse files
committed
2 parents c6d7e61 + 52167a1 commit 7e1ace0

1 file changed

Lines changed: 111 additions & 3 deletions

File tree

README.md

Lines changed: 111 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Goplater uses Go's [builtin templating library](https://pkg.go.dev/text/template
3131
File Content: $​{​{​{ read "./myfile.txt" }​}​}
3232
```
3333

34-
### Functions
34+
### Simple Functions
3535

3636
As you saw in the example above `read` is used for reading and output file contents.
3737
But there are more as you will see in the following…
@@ -161,6 +161,14 @@ Joins strings with separator.
161161
join "Apple" "Banana" "Strawberry" ", "
162162
```
163163

164+
#### `append`
165+
166+
Appends another string to string.
167+
168+
```
169+
append "Hello " "World!"
170+
```
171+
164172
#### `regexMatch`
165173

166174
Outputs wether string matches regex.
@@ -198,17 +206,109 @@ regexReplace "string" "replace_regex" "replace_with"
198206
Deletes an entry from a dictionary or array.
199207

200208
```
201-
202209
delete map "key"
210+
```
211+
212+
```
213+
delete array 0
214+
```
215+
216+
#### `set`
203217

218+
Sets key in dictionary or array to value.
219+
220+
```
221+
set map "key" value
204222
```
205223

224+
```
225+
set array 0 value
206226
```
207227

208-
delete array 0
228+
#### `push`
229+
230+
Pushes value onto top of array.
231+
232+
```
233+
push array value
234+
```
235+
236+
### Advanced Functions
237+
238+
In addition to the function in the [Simple Functions](#simple-functions) section, there are also some functions for advanced usage.
239+
240+
#### `import`
241+
242+
Imports a file and executes it as template, output is discarded.
243+
244+
```
245+
import "functions.inc.gtmpl"
246+
```
209247

248+
#### `globalSet`
249+
250+
Sets key globally to value.
251+
252+
```
253+
globalSet "key" value
210254
```
211255

256+
#### `globalGet`
257+
258+
Returns global value at key.
259+
260+
#### `funcDefine`
261+
262+
Defines a global function.
263+
264+
```
265+
funcDefine "name" "{{{ return 0 "Hello World" }}}"
266+
```
267+
268+
The second argument is the template body, notice the `{{{ ... }}}` instead of `${{{ ... }}}`.
269+
270+
> [!WARNING]
271+
> You may need to escape some characters like `"` with `\`
272+
273+
Raw output is discarded only output via [`return`](#return) persists.
274+
275+
##### `return`
276+
277+
> [!WARNING]
278+
> This function is **only** accessible from within functions!
279+
280+
Sets return argument at index to value.
281+
282+
```
283+
funcDefine "helloWorld" "{{{ return 0 "Hello World!" }}}"
284+
```
285+
286+
Overwriting previous return arguments is possible.
287+
288+
#### `funcCall`
289+
290+
Calls a global function by its name (without passing any arguments).
291+
292+
```
293+
294+
funcCall "name"
295+
296+
```
297+
298+
Returns list of [`return`](#return) outputs in order of index.
299+
300+
#### `funcCallArgs`
301+
302+
Same as [`funcCall`](#funccall), but arguments can be passed.
303+
304+
```
305+
306+
funcCallArgs "name" arg1 arg2
307+
308+
```
309+
310+
Arguments are accessible in function body with `{{{ index .args 0 }}}`.
311+
212312
## Contributing
213313

214314
Found a bug or just want to change or add something?
@@ -226,3 +326,11 @@ This Project is licensed under the [MIT License](./LICENSE).
226326
## Legal
227327

228328
Logo designed by [@CodeShellDev](https://github.com/codeshelldev) — All Rights Reserved. Go gopher mascot originally created by [Renée French](https://instagram.com/reneefrench/), used under the [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) license.
329+
330+
```
331+
332+
```
333+
334+
```
335+
336+
```

0 commit comments

Comments
 (0)