fix: allow line-breaks in multiline annotations (#243)

This commit is contained in:
Robert Kaussow 2022-02-19 14:58:35 +01:00 committed by GitHub
parent 9bb31ca293
commit aac0ef5f20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 31 additions and 20 deletions

View File

@ -4,6 +4,7 @@
import glob
import ntpath
import os
import re
from functools import reduce
import jinja2.exceptions
@ -158,7 +159,10 @@ class Generator:
def _save_join(self, eval_ctx, value, d=u"", attribute=None):
if isinstance(value, str):
value = [value]
return jinja2.filters.do_join(eval_ctx, value, d, attribute=None)
joined = jinja2.filters.do_join(eval_ctx, value, d, attribute=None)
nornalized = re.sub(r" +(\n|\t| )", "\\1", joined)
return nornalized
def render(self):
self.logger.info("Using output dir: " + self.config.config.get("output_dir"))

View File

@ -9,7 +9,7 @@
{% set deps = meta.dependencies.value %}
{% endif %}
{% for item in deps %}
* {{ item }}
- {{ item }}
{% endfor %}
{% else %}
None.

View File

@ -1,10 +1,10 @@
{% set var = role.var | default({}) %}
{% if var %}
* [Default Variables](#default-variables)
- [Default Variables](#default-variables)
{% for key, item in var | dictsort %}
* [{{ key }}](#{{ key }})
- [{{ key }}](#{{ key }})
{% endfor %}
{% endif %}
* [Dependencies](#dependencies)
- [Dependencies](#dependencies)
---

View File

@ -7,7 +7,7 @@
### {{ key }}
{% if item.description is defined and item.description %}
{{ item.description | save_join(" ") | striptags }}
{{ item.description | save_join(" ") }}
{% endif %}
{% if item.value is defined and item.value %}
@ -18,7 +18,7 @@
{{ item.value | to_nice_yaml(indent=2) }}
{% else %}
{% for ve_line in item.value %}
{{ ve_line }}
{{ ve_line | replace("\n\n", "\n") }}
{% endfor %}
{% endif %}
```
@ -32,7 +32,7 @@
{{ item.example | to_nice_yaml(indent=2) }}
{% else %}
{% for ex_line in item.example %}
{{ ex_line }}
{{ ex_line | replace("\n\n", "\n") }}
{% endfor %}
{% endif %}
```

View File

@ -9,7 +9,7 @@
{% set deps = meta.dependencies.value %}
{% endif %}
{% for item in deps %}
* {{ item }}
- {{ item }}
{% endfor %}
{% else %}
None.

View File

@ -2,13 +2,13 @@
{% set var = role.var | default({}) %}
{% if var %}
* [Default Variables](#default-variables)
- [Default Variables](#default-variables)
{% for key, item in var | dictsort %}
* [{{ key }}](#{{ key }})
- [{{ key }}](#{{ key }})
{% endfor %}
{% endif %}
* [Dependencies](#dependencies)
* [License](#license)
* [Author](#author)
- [Dependencies](#dependencies)
- [License](#license)
- [Author](#author)
---

View File

@ -7,7 +7,7 @@
### {{ key }}
{% if item.description is defined and item.description %}
{{ item.description | save_join(" ") | striptags }}
{{ item.description | save_join(" ") }}
{% endif %}
{% if item.value is defined and item.value %}
@ -18,7 +18,7 @@
{{ item.value | to_nice_yaml(indent=2) }}
{% else %}
{% for ve_line in item.value %}
{{ ve_line }}
{{ ve_line | replace("\n\n", "\n") }}
{% endfor %}
{% endif %}
```
@ -32,7 +32,7 @@
{{ item.example | to_nice_yaml(indent=2) }}
{% else %}
{% for ex_line in item.example %}
{{ ex_line }}
{{ ex_line | replace("\n\n", "\n") }}
{% endfor %}
{% endif %}
```

View File

@ -39,6 +39,8 @@ demo_role_dict:
demo_role_dict:
key1:
sub: some value
# Inline description
key2:
sublist:
- subval1
@ -105,6 +107,8 @@ demo_role_single: b
If you want to add an explicit notice, that a var is not set by default, this is one option. Make sure to flag it as json value: `@var demo_role_undefined_var: $ "_unset_"`
Test paragarph
#### Default value
```YAML

View File

@ -4,7 +4,7 @@
demo_role_unset:
demo_role_empty: ""
demo_role_single: 'b'
demo_role_single: "b"
# @var demo_role_empty_dict:description: >
# ... or you can use a valid json. In this case,
@ -19,6 +19,8 @@ demo_role_empty_dict: {}
# demo_role_dict:
# key1:
# sub: some value
#
# # Inline description
# key2:
# sublist:
# - subval1
@ -39,9 +41,10 @@ demo_role_dict:
# ]
# @end
demo_role_other_tags: []
# @var demo_role_undefined_var:description: >
# If you want to add an explicit notice, that a var is not set by default, this is one option.
# If you want to add an explicit notice, that a var is not set by default, this is one option.
# Make sure to flag it as json value: `@var demo_role_undefined_var: $ "_unset_"`
#
# Test paragarph
# @end
# @var demo_role_undefined_var: $ "_unset_"