Skip to content

Commit

Permalink
feat: additional template examples for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
micha91 committed Jun 26, 2024
1 parent 6e19b6b commit 062c80a
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 86 deletions.
68 changes: 0 additions & 68 deletions tests/data/jinja_templates/classes.html.j2

This file was deleted.

87 changes: 70 additions & 17 deletions tests/data/jinja_templates/common_macros.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
SPDX-License-Identifier: Apache-2.0
#}

{% macro first_upper(text) %}
{{ text[0] | upper}}{{text[1:] }}
{% endmacro %}

{% macro show_compliance_to_modeling_rules(object) %}
{% if "validation" in object.__dir__() %}
<h2>Compliance to modeling rules</h2>
Expand Down Expand Up @@ -79,8 +83,7 @@
{% for rel in rels %}
<li>
<a href="{{ rel.type | make_href }}">{{rel.type.long_name }}</a>
{{ rel.target.__class__.__name__ }}
<a href="{{ rel.target | make_href }}">{{ rel.target.name }}</a>
{{ rel.target.__class__.__name__ }} {{ linked_name_with_icon(rel.target) | safe}}</a>
</li>
{% endfor %}
</ul>
Expand All @@ -90,13 +93,22 @@
{% endmacro %}

{% macro render_requirements_table(reqs) %}
<table>
{% for req in reqs %}
<div style="margin-top: 1em; margin-bottom: 1em;">
<div><b>ID:</b> <a href="{{ req | make_href }}">{{ req.uuid }}</a></div>
<div>{{ req.text if req.text else req.long_name }}</div>
<div>{{req_rels(req.relations) | safe}}</div>
<tr>
<td>
<a href="{{ req | make_href }}">
{{ req.identifier if req.identifier else "REQ-"+req.uuid[-5:] | upper }}
</a>
</td>
<td>
{{ req.text if req.text else req.long_name }}
{{req_rels(req.relations) | safe}}
</td>
</div>
{% endfor %}
</tr>
{% endfor %}
</table>
{% endmacro %}

{% macro render_reqs_by_type(reqs, types) %}
Expand All @@ -121,6 +133,19 @@

{%- macro linked_name(object) -%}<a href="{{ object | make_href }}">{{ object.name | trim }}</a>{%- endmacro -%}

{% macro draw_icon(obj, size) %}
{% set icon = obj._get_icon("datauri_svg", size=size) %}
{% if icon %}
<img src="{{ icon | safe }}" height="{{size}}" width="{{size}}" style="display:inline-block"/>
{% endif %}
{% endmacro %}

{% macro linked_name_with_icon(obj) %}
<a href="hlink://{{obj.uuid}}">
{{ obj.name }}
</a>
{% endmacro %}

{%- macro display_traceability(object, complain=False) -%}
{%- set realized_attrs = [] -%}
{%- set realizing_attrs = [] -%}
Expand All @@ -135,35 +160,37 @@
{%- set realizing_objects = object[realizing_attrsfirst] if realizing_attrs else None -%}

<h2>Traceability</h2>
<p>The figure below provides an overview of objects that "{{ object.name}}" realizes but also those that realize "{{ object.name }}"</p>
{{ object.realization_view.as_svg | safe }}
{% if realized_objects %}
<p>{{ object.name }} realizes the following objects:<p>
<ul>
{%- for obj in realized_objects -%}<li>{{ typed_name(obj) | safe}}</li>{%- endfor -%}
{%- for obj in realized_objects -%}<li>{{ linked_name_with_icon(obj) | safe}}</li>{%- endfor -%}
</ul>
{%- elif complain -%}
<p style="color: red;">{{ object.name }} doesn't seem to realize any object</p>
{%- else -%}
<p style="color: red;">{{ first_upper(object.name) }} doesn't seem to realize any object</p>
{%- endif -%}
{% if realizing_objects %}
<p>{{ object.name }} is realized by the following objects:</p>
<ul>
{%- for obj in realizing_objects -%}<li>{{ typed_name(obj) | safe}}</li>{%- endfor -%}
{%- for obj in realizing_objects -%}<li>{{ linked_name_with_icon(obj) | safe}}</li>{%- endfor -%}
</ul>
{%- elif complain -%}
<p style="color: red;">{{ object.name }} doesn't seem to be realized by any object</p>
{%- else -%}
<p style="color: red;">{{ first_upper(object.name) }} doesn't seem to be realized by any object</p>
{% endif %}
{%- endmacro -%}

{% macro display_property_values(object) %}
{% if object.property_value_groups %}
<h2>Other properties</h2>
<p>The following properties were additionally assigned to {{ object.name }}</p>
<h2>Other properties (PVMT)</h2>
<p>The following properties were additionally assigned to {{ object.name }} via PVMT extension</p>
{% for group in object.property_value_groups %}
<p><b>{{ group.name | safe}}</b></p>
<table>
<thead>
<tr>
<td>Property</td>
<td>Value</td>
<th><b>Property</b></th>
<th><b>Value</b></th>
</tr>
</thead>
<tbody>
Expand All @@ -178,3 +205,29 @@
{% endfor %}
{% endif %}
{% endmacro %}

{% macro display_property_label(object, property) %}
<p>
<b>{{ property.name }}</b> :
{% set type = None %}
{% if "type" in property.__dir__() %}
{% set type = property.type %}
{% elif "abstract_type" in property.__dir__() %}
{% set type = property.abstract_type %}
{% endif %}
{% if type %}
{{ linked_name_with_icon(type) | safe }}
{% else %}
<span style="color:red">No type defined</span>
{% endif %}
{% if property.min_card.value == property.max_card.value and property.max_card.value == "1" %}
{% elif property.min_card.value == property.max_card.value %}
[ {{ property.min_card.value }} ]
{% else %}
[ {{ property.min_card.value }} .. {{ property.max_card.value }} ]
{% endif %}
{% if property.parent != object %}
(inherited from {{ linked_name_with_icon(property.parent) | safe }})
{% endif %}
</p>
{% endmacro %}
2 changes: 1 addition & 1 deletion tests/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,7 @@ def test_add_jinja_to_description(self, model: capellambse.MelodyModel):
{
"jinja_as_description": {
"template_folder": "tests/data/jinja_templates",
"template_path": "classes.html.j2",
"template_path": "class.html.j2",
}
},
[],
Expand Down

0 comments on commit 062c80a

Please sign in to comment.