Private
Public Access
2
0

Preparing release #14

Merged
seb merged 5 commits from dev into main 2026-02-02 20:15:54 +01:00
Showing only changes of commit 7e4857f762 - Show all commits

View File

@@ -1,51 +1,59 @@
#!/usr/bin/python #!/usr/bin/python
DOCUMENTATION = r"""
name: dict2str
short_description: This filter transforms a flat dict into a string using 4 separators.
version_added: "0.1.1"
author: Sébastien Namèche (@seb4itik)
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:
_input:
description: A flat dict.
type: dict
elements: str, int, bool
required: true
sep0:
description: Unique initial separator at the beginning of string.
type: str
default: ""
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 = r"""
_value:
type: str
description:
- String representating the dict using provided separators.
"""
class FilterModule(object): class FilterModule(object):
def filters(self): def filters(self):
return { return {
'dict2str': self.dict2str 'dict2str': self.dict2str
} }
def dict2str(self, d, sep1='=', sep2=';', sep3=''): def dict2str(self, d, sep0='', sep1='=', sep2=';', sep3=''):
return sep2.join( return sep0 + 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.
"""