Skip to content

Commit

Permalink
chore: unifi jinja template syntax and add linting (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxys authored Jun 2, 2024
1 parent 3df7e46 commit ab0372b
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 103 deletions.
3 changes: 3 additions & 0 deletions .markdownlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ MD041: False
MD024: False
MD004:
style: dash
MD033:
allowed_elements:
- "br"
9 changes: 9 additions & 0 deletions .woodpecker/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,12 @@ steps:
- poetry run ruff check ./${CI_REPO_NAME//-/}
environment:
PY_COLORS: "1"

- name: check-jinja
image: docker.io/library/python:3.12
commands:
- pip install poetry poetry-dynamic-versioning -qq
- poetry install -E ansible-core
- poetry run j2lint ansibledoctor/templates/ -i jinja-statements-indentation jinja-statements-delimiter
environment:
PY_COLORS: "1"
29 changes: 21 additions & 8 deletions ansibledoctor/templates/hugo-book/_vars_tabulated.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,43 @@
{% set found_columns = ["variable", "default"] + var.values() | map("list") | sum(start=["key"]) | unique | list %}
{% for c in columns %}
{% if c in found_columns %}
| {{ c | capitalize }} {# trimnewline #}
|{{ c | capitalize -}}
{% endif %}
{% endfor %}
|
{% for c in columns %}
{% if c in found_columns %}
| {{ "-" * (c | length) }} {# trimnewline #}
|{{ "-" * (c | length) -}}
{% endif %}
{% endfor %}
|
{% for key, item in var | dictsort %}
| {{ key }} {# trimnewline #}
| {{ (item.value | default({}))[key] | default }} {# trimnewline #}
|{{ key -}}
|{{ (item.value | default({}))[key] | default -}}
{% if "description" in found_columns %}
| {{ item.description | default([]) | safe_join("<br>") | replace("\n", "<br>") | replace("|", "\|") }} {# trimnewline #}
|{{ item.description | default([]) | safe_join("<br />") | replace("\n", "<br />") | replace("|", "\|") -}}
{% endif %}
{% if "type" in found_columns %}
| {{ item.type | default([]) | join("<br>") }} {# trimnewline #}
|{{ item.type | default([]) | join("<br />") -}}
{% endif %}
{% if "deprecated" in found_columns %}
| {{ item.deprecated | default }} {# trimnewline #}
|
{%- if "deprecated" in found_columns %}
{% if item.deprecated is defined %}
{% set deprecated = [item.deprecated] if item.deprecated is string else item.deprecated %}
{% set deprecated_string = deprecated | map("replace", "\n", "<br />") | safe_join("<br />") %}
{% if deprecated_string -%}
{{ deprecated_string }}
{%- else -%}
True
{%- endif %}
{%- else -%}
False
{%- endif %}
{% endif %}
{% endif %}
{% if "example" in found_columns %}
| {{ item.example | default([]) | safe_join("<br>") | replace("\n", "<br>") | replace("|", "\|") }} {# trimnewline #}
|{{ item.example | default([]) | safe_join("<br />") | replace("\n", "<br />") | replace("|", "\|") -}}
{% endif %}
|
{% endfor %}
Expand Down
29 changes: 21 additions & 8 deletions ansibledoctor/templates/readme/_vars_tabulated.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,43 @@
{% set found_columns = ["variable", "default"] + var.values() | map("list") | sum(start=["key"]) | unique | list %}
{% for c in columns %}
{% if c in found_columns %}
| {{ c | capitalize }} {# trimnewline #}
|{{ c | capitalize -}}
{% endif %}
{% endfor %}
|
{% for c in columns %}
{% if c in found_columns %}
| {{ "-" * (c | length) }} {# trimnewline #}
|{{ "-" * (c | length) -}}
{% endif %}
{% endfor %}
|
{% for key, item in var | dictsort %}
| {{ key }} {# trimnewline #}
| {{ (item.value | default({}))[key] | default }} {# trimnewline #}
|{{ key -}}
|{{ (item.value | default({}))[key] | default -}}
{% if "description" in found_columns %}
| {{ item.description | default([]) | safe_join("<br>") | replace("\n", "<br>") | replace("|", "\|") }} {# trimnewline #}
|{{ item.description | default([]) | safe_join("<br />") | replace("\n", "<br />") | replace("|", "\|") -}}
{% endif %}
{% if "type" in found_columns %}
| {{ item.type | default([]) | join("<br>") }} {# trimnewline #}
|{{ item.type | default([]) | join("<br />") -}}
{% endif %}
{% if "deprecated" in found_columns %}
| {{ item.deprecated | default }} {# trimnewline #}
|
{%- if "deprecated" in found_columns %}
{% if item.deprecated is defined %}
{% set deprecated = [item.deprecated] if item.deprecated is string else item.deprecated %}
{% set deprecated_string = deprecated | map("replace", "\n", "<br />") | safe_join("<br />") %}
{% if deprecated_string -%}
{{ deprecated_string }}
{%- else -%}
True
{%- endif %}
{%- else -%}
False
{%- endif %}
{% endif %}
{% endif %}
{% if "example" in found_columns %}
| {{ item.example | default([]) | safe_join("<br>") | replace("\n", "<br>") | replace("|", "\|") }} {# trimnewline #}
|{{ item.example | default([]) | safe_join("<br />") | replace("\n", "<br />") | replace("|", "\|") -}}
{% endif %}
|
{% endfor %}
Expand Down
1 change: 0 additions & 1 deletion example/demo-role/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ demo_role_unset: some_value

## Dependencies

- role1
- role2

## License
Expand Down
Loading

0 comments on commit ab0372b

Please sign in to comment.