You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+6-4Lines changed: 6 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,21 +78,23 @@ Python 3.5+ required. Python 2 is not and will not be supported.
78
78
| `!Exists` | JSONPath expression | `!Exists foo` | Returns `true` if the JSONPath expression returns one or more matches, `false` otherwise. |
79
79
| `!Filter` | `test`, `over` | See `tests/test_cond.py` | Takes in a list and only returns elements that pass a predicate. |
80
80
| `!Format` | Format string | `!Format "{foo} {bar!d}"` | Interpolate strings using [Python format strings](https://docs.python.org/3/library/string.html#formatstrings). <br> JSONPath supported in variable lookup (eg. `{people[0].first_name}` will do the right thing). <br> **NOTE:** When the format string starts with `{`, you need to quote it in order to avoid being interpreted as a YAML object. |
81
+
| `!Group` | Accepts the same arguments as `!Loop`, except `template` is optional (default identity), plus the following: <br> `by`: (required) An expression used to determine the key for the current value <br> `result_as`: (optional, string) When evaluating `by`, the enriched `template` is available under this name. | TBD | Makes a dict out of a list. Keys are determined by `by`. Items with the same key are grouped in a list. |
81
82
| `!If` | `test`, `then`, `else` | See `tests/test_cond.py` | Returns one of two values based on a condition. |
82
83
| `!Include` | Path to a template to include | `!Include ../foo.yml` | Renders the requested template at this location. Both absolute and relative paths work. |
83
84
| `!IncludeBase64` | Path to a binary file | `!IncludeBase64 ../foo.pdf` | Loads the given binary file and returns the contents encoded as Base64. |
84
85
| `!IncludeBinary` | Path to a binary file | `!IncludeBinary ../foo.pdf` | Loads the given binary file and returns the contents as bytes. This is practically only useful for hashing. |
85
86
| `!IncludeText` | Path to an UTF-8 text file | `!IncludeText ../foo.toml` | Loads the given UTF-8 text file and returns the contents as a string. |
87
+
| `!Index` | Accepts the same arguments as `!Loop`, except `template` is optional (default identity), plus the following: <br> `by`: (required) An expression used to determine the key for the current value <br> `result_as`: (optional, string) When evaluating `by`, the enriched `template` is available under this name. <br> `duplicates`: (optional, default `error`) `error`, `warn(ing)` or `ignore` duplicate values. | TBD | Makes a dict out of a list. Keys are determined by `by`. |
86
88
| `!Join` | `items`: (required) A list of items to be joined together. <br> `separator`: (optional, default space) The separator to place between the items. <br> **OR** <br> a list of items to be joined together with a space as the separator. | `!Join [foo, bar]` <br> `!Join { items: [foo, bar], separator: ', ' }` | Joins a list of items together with a separator. The result is always a string. |
87
89
| `!Lookup` | JSONPath expression | `!Lookup people[0].first_name` | Performs a JSONPath lookup returning the first match. If there is no match, an error is raised. |
88
90
| `!LookupAll` | JSONPath expression | `!LookupAll people[*].first_name` | Performs a JSONPath lookup returning all matches as a list. If no matches are found, the empty list `[]` is returned. |
89
-
| `!Loop` | `over`: (required) The data to iterate over (a literal list or dict, or !Var) <br> `as`: (optional, default `item`) The variable name given to the current value <br> `index_as`: (optional) The variable name given to the loop index. If over is a list, this is a numeric index starting from `0`. If over is a dict, this is the dict key. <br> `index_start`: (optional, default `0`) First index, for eg. 1-based indexing. <br> `template`: (required) The template to process for each iteration of the loop. | See `examples/loop/`. | Loops over a list or dict and renders a template for each iteration. The output is always a list. |
90
-
| `!MD5` | Data to hash | `!MD5 'Törkylempijävongahdus' | Hashes the given data using the MD5 algorithm. If the data is not binary, it is converted to UTF-8 bytes. |
91
+
| `!Loop` | `over`: (required) The data to iterate over (a literal list or dict, or !Var) <br> `as`: (optional, default `item`) The variable name given to the current value <br> `index_as`: (optional) The variable name given to the loop index. If over is a list, this is a numeric index starting from `0`. If over is a dict, this is the dict key. <br> `index_start`: (optional, default `0`) First index, for eg. 1-based indexing. <br> `previous_as`: (optional) The variable name given to the previous value. On the first iteration of the loop, the previous value is `null`. _Added in 0.2.0_ <br> `template`: (required) The template to process for each iteration of the loop. | See `examples/loop/`. | Loops over a list or dict and renders a template for each iteration. The output is always a list. |
92
+
| `!MD5` | Data to hash | `!MD5 'some data to hash'` | Hashes the given data using the MD5 algorithm. If the data is not binary, it is converted to UTF-8 bytes. |
91
93
| `!Merge` | A list of dicts | `!Merge [{a: 5}, {b: 6}]` | Merges objects. For overlapping keys the last one takes precedence. |
92
94
| `!Not` | a value | `!Not !Var foo` | Logically negates the given value (in Python semantics). |
93
95
| `!Op` | `a`, `op`, `b` | See `tests/test_cond.py` | Performs binary operators. Especially useful with `!If` to implement greater-than etc. |
94
-
| `!SHA1` | Data to hash | `!SHA1 'Törkylempijävongahdus' | Hashes the given data using the SHA1 algorithm. If the data is not binary, it is converted to UTF-8 bytes. |
95
-
| `!SHA256` | Data to hash | `!SHA256 'Törkylempijävongahdus' | Hashes the given data using the SHA256 algorithm. If the data is not binary, it is converted to UTF-8 bytes. |
96
+
| `!SHA1` | Data to hash | `!SHA1 'some data to hash'` | Hashes the given data using the SHA1 algorithm. If the data is not binary, it is converted to UTF-8 bytes. |
97
+
| `!SHA256` | Data to hash | `!SHA256 'some data to hash'` | Hashes the given data using the SHA256 algorithm. If the data is not binary, it is converted to UTF-8 bytes. |
96
98
| `!URLEncode` | A string to encode <br> **OR** <br> `url`: The URL to combine query parameters into <br> `query`: An object of query string parameters to add. | `!URLEncode "foo+bar"` <br> `!URLEncode { url: "https://example.com/", query: { foo: bar } }` | Encodes strings for safe inclusion in a URL, or combines query string parameters into a URL. |
97
99
| `!Var` | Variable name | `!Var image_name` | Replaced with the value of the variable. |
98
100
| `!Void` | Anything or nothing | `foo: !Void`| The dict key, list item or YAML document that resolves to `!Void` is removed from the output. |
Copy file name to clipboardExpand all lines: emrichen/tags/loop.py
+21-5Lines changed: 21 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -40,12 +40,13 @@ class Loop(BaseTag):
40
40
`as`: (optional, default `item`) The variable name given to the current value
41
41
`index_as`: (optional) The variable name given to the loop index. If over is a list, this is a numeric index starting from `0`. If over is a dict, this is the dict key.
42
42
`index_start`: (optional, default `0`) First index, for eg. 1-based indexing.
43
+
`previous_as`: (optional) The variable name given to the previous value. On the first iteration of the loop, the previous value is `null`. _Added in 0.2.0_
43
44
`template`: (required) The template to process for each iteration of the loop.
44
45
example: See `examples/loop/`.
45
46
description: Loops over a list or dict and renders a template for each iteration. The output is always a list.
0 commit comments