in src/filter-j2.py [0:0]
def splitPropertyTemplate(value):
"""
Splits the provided property template (guacamole.properties snippet
containing documentation for each property in comments) into a list of each
property, example value, and corresponding documentation. Whether the
property was commented-out is also included.
The list returned is a list of dictionaries corresponding to each property,
where each dictionary contains the following entries:
"name"
The name of the property.
"value"
An example value for the property.
"documentation"
Documentation describing the usage of the property.
"commented"
Whether the property was commented-out within the template.
:param value:
The string to filter.
:return string:
A list of dictionaries describing each property.
"""
result = []
property_docs = ''
for line in value.splitlines():
# Gradually accumulate documentation from comments that precede a
# property/value pair
if match := re.match(r'^# (\s*\S.*)$', line):
content = match.group(1)
property_docs += content + '\n'
new_paragraph = False
# Comments that are empty or consist of nothing but whitespace indicate
# a new paragraph
elif match := re.match(r'^#\s*$', line):
property_docs += '\n'
# Once a property/value pair is finally encountered, store the
# documentation accumulated so far and move on to the next property
elif match := re.match(r'^(#)?(\S+):\s+(.*)', line):
comment_char = match.group(1)
property = match.group(2)
property_value = match.group(3)
result.append({
'name' : property,
'value' : property_value,
'documentation' : property_docs.strip(),
'commented' : bool(comment_char)
})
property_docs = ''
else:
property_docs = ''
return result