mirror of
https://github.com/thegeeklab/ansible-doctor.git
synced 2024-11-24 13:50:42 +00:00
fix: join lines with newline instead of space in markdown templates (#446)
This commit is contained in:
parent
a761b3c874
commit
3aad08646f
@ -2,5 +2,6 @@
|
|||||||
default: True
|
default: True
|
||||||
MD013: False
|
MD013: False
|
||||||
MD041: False
|
MD041: False
|
||||||
|
MD024: False
|
||||||
MD004:
|
MD004:
|
||||||
style: dash
|
style: dash
|
||||||
|
@ -119,7 +119,9 @@ class Generator:
|
|||||||
)
|
)
|
||||||
jenv.filters["to_nice_yaml"] = self._to_nice_yaml
|
jenv.filters["to_nice_yaml"] = self._to_nice_yaml
|
||||||
jenv.filters["deep_get"] = self._deep_get
|
jenv.filters["deep_get"] = self._deep_get
|
||||||
jenv.filters["save_join"] = self._save_join
|
jenv.filters["safe_join"] = self._safe_join
|
||||||
|
# keep the old name of the function to not break custom templates.
|
||||||
|
jenv.filters["save_join"] = self._safe_join
|
||||||
data = jenv.from_string(data).render(role_data, role=role_data)
|
data = jenv.from_string(data).render(role_data, role=role_data)
|
||||||
if not self.config.config["dry_run"]:
|
if not self.config.config["dry_run"]:
|
||||||
with open(doc_file, "wb") as outfile:
|
with open(doc_file, "wb") as outfile:
|
||||||
@ -129,7 +131,9 @@ class Generator:
|
|||||||
else:
|
else:
|
||||||
self.logger.info(f"Writing to: {doc_file}")
|
self.logger.info(f"Writing to: {doc_file}")
|
||||||
except (
|
except (
|
||||||
jinja2.exceptions.UndefinedError, jinja2.exceptions.TemplateSyntaxError
|
jinja2.exceptions.UndefinedError,
|
||||||
|
jinja2.exceptions.TemplateSyntaxError,
|
||||||
|
jinja2.exceptions.TemplateRuntimeError
|
||||||
) as e:
|
) as e:
|
||||||
self.log.sysexit_with_message(
|
self.log.sysexit_with_message(
|
||||||
"Jinja2 templating error while loading file: '{}'\n{}".format(
|
"Jinja2 templating error while loading file: '{}'\n{}".format(
|
||||||
@ -157,7 +161,7 @@ class Generator:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@pass_eval_context
|
@pass_eval_context
|
||||||
def _save_join(self, eval_ctx, value, d=""):
|
def _safe_join(self, eval_ctx, value, d=""):
|
||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
value = [value]
|
value = [value]
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
{% for key, item in tag | dictsort %}
|
{% for key, item in tag | dictsort %}
|
||||||
|
|
||||||
{{ key }}
|
{{ key }}
|
||||||
{% if item.description is defined and item.description | save_join(" ") | striptags %}
|
{% if item.description is defined and item.description | safe_join(" ") | striptags %}
|
||||||
: {{ item.description | save_join(" ") | striptags }}
|
: {{ item.description | safe_join(" ") | striptags }}
|
||||||
{% else %}
|
{% else %}
|
||||||
:
|
:
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -4,15 +4,15 @@
|
|||||||
|
|
||||||
{% for key, item in todo | dictsort %}
|
{% for key, item in todo | dictsort %}
|
||||||
{% for line in item %}
|
{% for line in item %}
|
||||||
{% if line.value is defined and line.value | save_join(" ") | striptags and key == "default" %}
|
{% if line.value is defined and line.value | safe_join(" ") | striptags and key == "default" %}
|
||||||
- {{ line.value | save_join(" ") | striptags }}
|
- {{ line.value | safe_join(" ") | striptags }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% for key, item in todo | dictsort %}
|
{% for key, item in todo | dictsort %}
|
||||||
{% for line in item %}
|
{% for line in item %}
|
||||||
{% if line.value is defined and line.value | save_join(" ") | striptags and key != "default" %}
|
{% if line.value is defined and line.value | safe_join(" ") | striptags and key != "default" %}
|
||||||
- ({{ key }}): {{ line.value | save_join(" ") | striptags }}
|
- ({{ key }}): {{ line.value | safe_join(" ") | striptags }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
### {{ key }}
|
### {{ key }}
|
||||||
{% if item.description is defined and item.description %}
|
{% if item.description is defined and item.description %}
|
||||||
|
|
||||||
{{ item.description | save_join(" ") }}
|
{{ item.description | map("replace", "\n\n", "\n") | safe_join("\n") }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if item.value is defined and item.value %}
|
{% if item.value is defined and item.value %}
|
||||||
|
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
{% if not append | deep_get(role, "internal.append") %}
|
{% if not append | deep_get(role, "internal.append") %}
|
||||||
{% set meta = role.meta | default({}) %}
|
{% set meta = role.meta | default({}) %}
|
||||||
---
|
---
|
||||||
title: {{ meta.name.value | save_join(" ") }}
|
title: {{ meta.name.value | safe_join(" ") }}
|
||||||
type: docs
|
type: docs
|
||||||
{% if summary | deep_get(meta, "summary.value") %}
|
{% if summary | deep_get(meta, "summary.value") %}
|
||||||
summary: {{ meta.summary.value | save_join(" ") }}
|
summary: {{ meta.summary.value | safe_join(" ") }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
---
|
---
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if description | deep_get(meta, "description.value") %}
|
{% if description | deep_get(meta, "description.value") %}
|
||||||
|
|
||||||
{{ meta.description.value | save_join(" ") }}
|
{{ meta.description.value | map("replace", "\n\n", "\n") | safe_join("\n") }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<!--more-->
|
<!--more-->
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
{% if not append | deep_get(role, "internal.append") %}
|
{% if not append | deep_get(role, "internal.append") %}
|
||||||
{% set meta = role.meta | default({}) %}
|
{% set meta = role.meta | default({}) %}
|
||||||
# {{ meta.name.value | save_join(" ") }}
|
# {{ meta.name.value | safe_join(" ") }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if description | deep_get(meta, "description.value") %}
|
{% if description | deep_get(meta, "description.value") %}
|
||||||
|
|
||||||
{{ meta.description.value | save_join(" ") }}
|
{{ meta.description.value | map("replace", "\n\n", "\n") | safe_join("\n") }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# TOC #}
|
{# TOC #}
|
||||||
|
@ -26,6 +26,6 @@ None.
|
|||||||
|
|
||||||
## Author
|
## Author
|
||||||
|
|
||||||
{{ meta.author.value | save_join(" ") }}
|
{{ meta.author.value | safe_join(" ") }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
{% if tag %}
|
{% if tag %}
|
||||||
## Discovered Tags
|
## Discovered Tags
|
||||||
{% for key, item in tag | dictsort %}
|
{% for key, item in tag | dictsort %}
|
||||||
{% set is_desc = item.description is defined and item.description | save_join(" ") | striptags %}
|
{% set is_desc = item.description is defined and item.description | safe_join(" ") | striptags %}
|
||||||
|
|
||||||
**_{{ key }}_**{{ "\\" if is_desc else "" }}
|
**_{{ key }}_**{{ "\\" if is_desc else "" }}
|
||||||
{% if is_desc %}
|
{% if is_desc %}
|
||||||
 {{ item.description | save_join(" ") | striptags }}
|
 {{ item.description | safe_join(" ") | striptags }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -4,15 +4,15 @@
|
|||||||
|
|
||||||
{% for key, item in todo | dictsort %}
|
{% for key, item in todo | dictsort %}
|
||||||
{% for line in item %}
|
{% for line in item %}
|
||||||
{% if line.value is defined and line.value | save_join(" ") | striptags and key == "default" %}
|
{% if line.value is defined and line.value | safe_join(" ") | striptags and key == "default" %}
|
||||||
- {{ line.value | save_join(" ") | striptags }}
|
- {{ line.value | safe_join(" ") | striptags }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% for key, item in todo | dictsort %}
|
{% for key, item in todo | dictsort %}
|
||||||
{% for line in item %}
|
{% for line in item %}
|
||||||
{% if line.value is defined and line.value | save_join(" ") | striptags and key != "default" %}
|
{% if line.value is defined and line.value | safe_join(" ") | striptags and key != "default" %}
|
||||||
- ({{ key }}): {{ line.value | save_join(" ") | striptags }}
|
- ({{ key }}): {{ line.value | safe_join(" ") | striptags }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
### {{ key }}
|
### {{ key }}
|
||||||
{% if item.description is defined and item.description %}
|
{% if item.description is defined and item.description %}
|
||||||
|
|
||||||
{{ item.description | save_join(" ") }}
|
{{ item.description | map("replace", "\n\n", "\n") | safe_join("\n") }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if item.value is defined and item.value %}
|
{% if item.value is defined and item.value %}
|
||||||
|
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
[![Build Status](https://img.shields.io/drone/build/thegeeklab/ansible-doctor?logo=drone&server=https%3A%2F%2Fdrone.thegeeklab.de)](https://drone.thegeeklab.de/thegeeklab/ansible-doctor)
|
[![Build Status](https://img.shields.io/drone/build/thegeeklab/ansible-doctor?logo=drone&server=https%3A%2F%2Fdrone.thegeeklab.de)](https://drone.thegeeklab.de/thegeeklab/ansible-doctor)
|
||||||
[![License: GPL-3.0](https://img.shields.io/github/license/thegeeklab/ansible-doctor)](https://github.com/thegeeklab/ansible-doctor/blob/main/LICENSE)
|
[![License: GPL-3.0](https://img.shields.io/github/license/thegeeklab/ansible-doctor)](https://github.com/thegeeklab/ansible-doctor/blob/main/LICENSE)
|
||||||
|
|
||||||
Role to demonstrate ansible-doctor. It is also possible to overwrite the default description with an annotation.
|
Role to demonstrate ansible-doctor. It is also possible to overwrite
|
||||||
|
the default description with an annotation.
|
||||||
|
|
||||||
## Table of content
|
## Table of content
|
||||||
|
|
||||||
@ -61,7 +62,8 @@ demo_role_empty: ''
|
|||||||
|
|
||||||
### demo_role_empty_dict
|
### demo_role_empty_dict
|
||||||
|
|
||||||
... or valid json can be used. In this case, the json will be automatically prefixed with the annotation key and filters like `to_nice_yaml` can be used in templates. To get it working, the json need to be prefixed with a `$`.
|
... or valid json can be used. In this case, the json will be automatically prefixed with the annotation key
|
||||||
|
and filters like `to_nice_yaml` can be used in templates. To get it working, the json need to be prefixed with a `$`.
|
||||||
|
|
||||||
#### Default value
|
#### Default value
|
||||||
|
|
||||||
@ -127,7 +129,12 @@ demo_role_single: b
|
|||||||
|
|
||||||
### demo_role_undefined_var
|
### demo_role_undefined_var
|
||||||
|
|
||||||
To highlight a variable that has not set a value by default, this is one way to achieve it. Make sure to flag it as json value: `@var demo_role_undefined_var: $ "_unset_"`
|
To highlight a variable that has not set a value by default, this is one way to achieve it.
|
||||||
|
Make sure to flag it as json value: `@var demo_role_undefined_var: $ "_unset_"`
|
||||||
|
|
||||||
|
| Attribute | Description |
|
||||||
|
| --- | --- |
|
||||||
|
| value1 | desc1 |
|
||||||
|
|
||||||
#### Default value
|
#### Default value
|
||||||
|
|
||||||
|
@ -31,6 +31,11 @@ demo_role_dict:
|
|||||||
# @var demo_role_undefined_var:description: >
|
# @var demo_role_undefined_var:description: >
|
||||||
# To highlight a variable that has not set a value by default, this is one way to achieve it.
|
# To highlight a variable that has not set a value by default, this is one way to achieve it.
|
||||||
# Make sure to flag it as json value: `@var demo_role_undefined_var: $ "_unset_"`
|
# Make sure to flag it as json value: `@var demo_role_undefined_var: $ "_unset_"`
|
||||||
|
#
|
||||||
|
# | Attribute | Description |
|
||||||
|
# | --- | --- |
|
||||||
|
# | value1 | desc1 |
|
||||||
|
#
|
||||||
# @end
|
# @end
|
||||||
# @var demo_role_undefined_var: $ "_unset_"
|
# @var demo_role_undefined_var: $ "_unset_"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user