feat: add support for indentation with spaces (#508)

This commit is contained in:
Robert Kaussow 2023-06-14 13:31:01 +02:00 committed by GitHub
parent b6001fe81d
commit 588f41a3ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 3 deletions

View File

@ -87,6 +87,12 @@ class Config():
"file": True,
"type": environs.Env().str
},
"template_autotrim": {
"default": True,
"env": "TEMPLATE_AUTOTRIM",
"file": True,
"type": environs.Env().bool
},
"force_overwrite": {
"default": False,
"env": "FORCE_OVERWRITE",

View File

@ -166,10 +166,12 @@ class Generator:
value = [value]
normalized = jinja2.filters.do_join(eval_ctx, value, d, attribute=None)
for s in [r" +(\n|\t| )", r"(\n|\t) +"]:
normalized = re.sub(s, "\\1", normalized)
return normalized
if self.config.config["template_autotrim"]:
for s in [r" +(\n|\t| )", r"(\n|\t) +"]:
normalized = re.sub(s, "\\1", normalized)
return jinja2.filters.do_mark_safe(normalized)
def render(self):
self.logger.info(f"Using output dir: {self.config.config.get('output_dir')}")

View File

@ -39,6 +39,11 @@ output_dir:
# Default is built-in templates directory.
template_dir:
template: readme
# By default, double spaces, spaces before and after line breaks or tab characters, etc.
# are automatically removed before the template is rendered. As a result, indenting
# with spaces does not work. If you want to use spaces to indent text, you must disable
# this option.
template_autotrim: True
# Don't ask to overwrite if output file exists.
force_overwrite: False
@ -97,6 +102,7 @@ ANSIBLE_DOCTOR_LOG_JSON=false
ANSIBLE_DOCTOR_OUTPUT_DIR=
ANSIBLE_DOCTOR_TEMPLATE_DIR=
ANSIBLE_DOCTOR_TEMPLATE=readme
ANSIBLE_DOCTOR_TEMPLATE_AUTOTRIM=true
ANSIBLE_DOCTOR_FORCE_OVERWRITE=false
ANSIBLE_DOCTOR_CUSTOM_HEADER=
ANSIBLE_DOCTOR_EXCLUDE_FILES=

View File

@ -8,6 +8,7 @@ the default description with an annotation.
## Table of content
- [Requirements](#requirements)
- [Default Variables](#default-variables)
- [demo_role_dict](#demo_role_dict)
- [demo_role_empty](#demo_role_empty)
@ -26,6 +27,11 @@ the default description with an annotation.
---
## Requirements
- Minimum Ansible version: `2.4`
## Default Variables
### demo_role_dict