Private
Public Access
2
0

dict2str: filter documentation

This commit is contained in:
2026-01-22 08:54:47 +03:00
parent f26493fdea
commit 0ba6b9a866

View File

@@ -10,3 +10,42 @@ class FilterModule(object):
return sep2.join( return sep2.join(
[ str(k) + (sep1+str(v) if v!=None and v!='' else '') for k, v in d.items() ] [ str(k) + (sep1+str(v) if v!=None and v!='' else '') for k, v in d.items() ]
) + sep3 ) + sep3
DOCUMENTATION = """
name: dict2str
author: Sébastien Namèche (@seb4itik)
version_added: "0.1.1"
short_description: This filter transforms a flat dict into a string using 3 separators.
description:
- If my_dict is {one: "un", two: "deux", three: "trois"}, then:
- {{ my_dict | dict2str(sep1=' is ', sep2=', ', sep3='.') }}
- will produce:
- "one is un, two is deux, three is trois."
options:
sep1:
description:
- separator between each key and value pairs of the dict
type: str
default: "="
sep2:
description:
- separator between key/value pairs of the dict that has been combined with sep1
type: str
default: ";"
sep3:
description:
- unique final separator at the end of string
type: str
default: ""
notes:
- If a value associated to a key of the dict is None or an empty string,
- sep2 will not be used.
"""
RETURN = """
data:
type: str
description:
- String representating the dict using provided separators.
"""