dev #16
52
seb4itik/byow/plugins/filter/listadddel.py
Normal file
52
seb4itik/byow/plugins/filter/listadddel.py
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
name: listadddel
|
||||
short_description: This filter add and remove items to/from a list.
|
||||
version_added: "0.2.2"
|
||||
author: Sébastien Namèche (@seb4itik)
|
||||
description:
|
||||
- If my_list is ["un", "deux", "trois"], then:
|
||||
- {{ my_list | listadddel(["quatre", "cinq"], ["un"]) }}
|
||||
- will produce:
|
||||
- ["deux", "trois", "quatre", "cinq"]
|
||||
options:
|
||||
_input:
|
||||
description: A list of strings.
|
||||
type: list
|
||||
elements: str
|
||||
required: true
|
||||
add:
|
||||
description: A list of string to add to _input.
|
||||
type: list
|
||||
elements: str
|
||||
default: []
|
||||
delete:
|
||||
description: A list of string to remove from _input.
|
||||
type: list
|
||||
elements: str
|
||||
default: []
|
||||
notes:
|
||||
- delete is tronger than add. If the string is present in both delete and
|
||||
add, it will not be in returned list.
|
||||
"""
|
||||
|
||||
|
||||
RETURN = r"""
|
||||
_value:
|
||||
type: list
|
||||
elements: str
|
||||
description:
|
||||
- List of strings with new and removed elements.
|
||||
"""
|
||||
|
||||
|
||||
class FilterModule(object):
|
||||
def filters(self):
|
||||
return {
|
||||
'listadddel': self.listadddel
|
||||
}
|
||||
|
||||
def listadddel(self, l, add=[], delete=[]):
|
||||
return [e for e in l+add if e not in delete]
|
||||
Reference in New Issue
Block a user