From 7e4857f762e6abb63cf3041508071febf1407bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=2E=20Nam=C3=A8che?= Date: Mon, 2 Feb 2026 22:08:27 +0300 Subject: [PATCH] dic2str: doc --- seb4itik/byow/plugins/filter/dic2str.py | 90 ++++++++++++++----------- 1 file changed, 49 insertions(+), 41 deletions(-) diff --git a/seb4itik/byow/plugins/filter/dic2str.py b/seb4itik/byow/plugins/filter/dic2str.py index 05e1e2c..70b35bc 100644 --- a/seb4itik/byow/plugins/filter/dic2str.py +++ b/seb4itik/byow/plugins/filter/dic2str.py @@ -1,51 +1,59 @@ #!/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): def filters(self): return { 'dict2str': self.dict2str } - def dict2str(self, d, sep1='=', sep2=';', sep3=''): - return sep2.join( + def dict2str(self, d, sep0='', sep1='=', sep2=';', sep3=''): + return sep0 + sep2.join( [ str(k) + (sep1+str(v) if v!=None and v!='' else '') for k, v in d.items() ] ) + 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. -""" \ No newline at end of file