diff --git a/tests/data/jinja_templates/class.html.j2 b/tests/data/jinja_templates/class.html.j2 new file mode 100644 index 00000000..0b8ac1e8 --- /dev/null +++ b/tests/data/jinja_templates/class.html.j2 @@ -0,0 +1,41 @@ +{# + Copyright DB InfraGO AG and contributors + SPDX-License-Identifier: Apache-2.0 +#} + +{% from 'common_macros.html.j2' import show_other_attributes, linked_name, linked_name_with_icon, description, display_property_label %} + +{% macro properties_table(props, obj) %} + {% for property in props %} + {{ display_property_label(obj, property) | safe }} +
+ {% if property.kind != "UNSET" %} +

KIND: {{ property.kind }}

+ {% endif %} + {{ description(property) | safe}} +
+
+ {% endfor %} +{% endmacro %} + +

Parent: {{ object.parent.name }}

+{% if object.description %} +

{{ object.description }}

+{% else %} +

No description available.

+{% endif %} + +{% set props = [] %} +{% if object.super %} + {% set props = props | list + object.super.properties | list %} +{% endif %} +{% set props = props + object.owned_properties | list %} + +Properties +
+{% if props %} +

The object owns the properties listed below; We use the following format to describe property: name : type [min .. max (instances of type)] or [ fixed number]; if no multiplicity is shown assume its 1 (single instance).

+ {{ properties_table(props, object) | safe }} +{% else %} +

No properties are owned by this object.

+{% endif %} diff --git a/tests/data/jinja_templates/classes.html.j2 b/tests/data/jinja_templates/classes.html.j2 deleted file mode 100644 index 323872fb..00000000 --- a/tests/data/jinja_templates/classes.html.j2 +++ /dev/null @@ -1,68 +0,0 @@ -{# - Copyright DB InfraGO AG and contributors - SPDX-License-Identifier: Apache-2.0 -#} - -{% macro properties_table(props, obj) %} - - - - - - - - - - - - {% for property in props %} - - - - - - - - {% endfor %} - -
Property NameTypeKindMultiplicityDescription
{{ property.name }} - {% if property.type.__class__ == obj.__class__ %} - {{ property.type.name }} - {% else %} - {{ property.type.name }} - {% endif %} - {{ property.kind }}{{ property.min_card.value }} .. {{ property.max_card.value }}{% if property.description %} - {{ property.description }} - {% else %} -

No description available.

- {% endif %} -
-{% endmacro %} - -{{ object.__class__.__name__ }} {{ object.name }} -
-

Parent: {{ object.parent.name }}


-{% if object.description %} -

{{ object.description }}

-{% else %} -

No description available.

-{% endif %} - -Owned Properties -
-{% if object.owned_properties %} -

The object owns the following properties:


- {{ properties_table(object.owned_properties, object) |safe }} -{% else %} -

No properties are owned by this object.

-{% endif %} - -{% if object.generalizations %} -Inherited Properties -{% for gen in object.generalizations %} - {% set sup = gen.super %} - From {{sup.name}} -

Object {{object.name}} inherits the following properties from {{ sup.name }}

- {{ properties_table(sup.owned_properties, sup) |safe }} -{% endfor%} -{% endif %} diff --git a/tests/data/jinja_templates/common_macros.html.j2 b/tests/data/jinja_templates/common_macros.html.j2 index 82c9581f..e543746e 100644 --- a/tests/data/jinja_templates/common_macros.html.j2 +++ b/tests/data/jinja_templates/common_macros.html.j2 @@ -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__() %}

Compliance to modeling rules

@@ -79,8 +83,7 @@ {% for rel in rels %}
  • {{rel.type.long_name }} - {{ rel.target.__class__.__name__ }} - {{ rel.target.name }} + {{ rel.target.__class__.__name__ }} {{ linked_name_with_icon(rel.target) | safe}}
  • {% endfor %} @@ -90,13 +93,22 @@ {% endmacro %} {% macro render_requirements_table(reqs) %} + {% for req in reqs %} -
    -
    ID: {{ req.uuid }}
    -
    {{ req.text if req.text else req.long_name }}
    -
    {{req_rels(req.relations) | safe}}
    +
    + + - {% endfor %} + + {% endfor %} +
    + + {{ req.identifier if req.identifier else "REQ-"+req.uuid[-5:] | upper }} + + + {{ req.text if req.text else req.long_name }} + {{req_rels(req.relations) | safe}} +
    {% endmacro %} {% macro render_reqs_by_type(reqs, types) %} @@ -121,6 +133,19 @@ {%- macro linked_name(object) -%}{{ object.name | trim }}{%- endmacro -%} +{% macro draw_icon(obj, size) %} +{% set icon = obj._get_icon("datauri_svg", size=size) %} +{% if icon %} + +{% endif %} +{% endmacro %} + +{% macro linked_name_with_icon(obj) %} + + {{ obj.name }} + +{% endmacro %} + {%- macro display_traceability(object, complain=False) -%} {%- set realized_attrs = [] -%} {%- set realizing_attrs = [] -%} @@ -135,35 +160,37 @@ {%- set realizing_objects = object[realizing_attrs | first] if realizing_attrs else None -%}

    Traceability

    +

    The figure below provides an overview of objects that "{{ object.name}}" realizes but also those that realize "{{ object.name }}"

    + {{ object.realization_view.as_svg | safe }} {% if realized_objects %}

    {{ object.name }} realizes the following objects:

    - {%- elif complain -%} -

    {{ object.name }} doesn't seem to realize any object

    + {%- else -%} +

    {{ first_upper(object.name) }} doesn't seem to realize any object

    {%- endif -%} {% if realizing_objects %}

    {{ object.name }} is realized by the following objects:

    - {%- elif complain -%} -

    {{ object.name }} doesn't seem to be realized by any object

    + {%- else -%} +

    {{ first_upper(object.name) }} doesn't seem to be realized by any object

    {% endif %} {%- endmacro -%} {% macro display_property_values(object) %} {% if object.property_value_groups %} -

    Other properties

    -

    The following properties were additionally assigned to {{ object.name }}

    +

    Other properties (PVMT)

    +

    The following properties were additionally assigned to {{ object.name }} via PVMT extension

    {% for group in object.property_value_groups %}

    {{ group.name | safe}}

    - - + + @@ -178,3 +205,29 @@ {% endfor %} {% endif %} {% endmacro %} + +{% macro display_property_label(object, property) %} +

    + {{ property.name }} : + {% 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 %} + No type defined + {% 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 %} +

    +{% endmacro %} diff --git a/tests/data/jinja_templates/exchange_item.html.j2 b/tests/data/jinja_templates/exchange_item.html.j2 new file mode 100644 index 00000000..3cb8fc8b --- /dev/null +++ b/tests/data/jinja_templates/exchange_item.html.j2 @@ -0,0 +1,37 @@ +{# + Copyright DB InfraGO AG and contributors + SPDX-License-Identifier: Apache-2.0 +#} + +{% from 'common_macros.html.j2' import show_other_attributes, description, typed_name, linked_name, linked_name_with_icon, display_property_label %} + +{% macro render_usage(object) %} +Usage +{% if object.exchanges %} +

    The exchange item "{{ object.name }}" is produced and used across the model in the following cases:

    + +{% else %} +

    The exchange item "{{ object.name }}" is not used in any exchanges.

    +{% endif %} +{% endmacro %} + +{{ description(object) | safe }} + +{% if object.elements %} +Composition +

    The exchange item "{{ object.name }}" is composed of the following elements:

    + +{% endif %} diff --git a/tests/data/jinja_templates/functional_exchange.html.j2 b/tests/data/jinja_templates/functional_exchange.html.j2 new file mode 100644 index 00000000..82e91cb6 --- /dev/null +++ b/tests/data/jinja_templates/functional_exchange.html.j2 @@ -0,0 +1,24 @@ +{# + Copyright DB InfraGO AG and contributors + SPDX-License-Identifier: Apache-2.0 +#} + +{% from 'common_macros.html.j2' import show_other_attributes, description, typed_name, linked_name, linked_name_with_icon, display_property_label %} + +{%- set source_function = object.source.owner -%} +{%- set target_function = object.target.owner -%} +{%- set source = source_function.owner -%} +{%- set target = target_function.owner -%} +The {{ linked_name(source) | safe }} shall provide {{ linked_name_with_icon(object) | safe }} to {{ linked_name_with_icon(target) | safe }} so that the {{ linked_name_with_icon(target) | safe }} could {{ linked_name_with_icon(target_function)|safe }}. +{% if object.exchange_items %} +{% if object.exchange_items | length > 1 %} +

    {{ object.name }} is further specified via the following Exchange Items:

    + +{% else %} +

    This interaction is further specified via {{ linked_name_with_icon(object.exchange_items[0]) | safe}} Exchange Item

    +{% endif %} +{% endif %} diff --git a/tests/test_documents.py b/tests/test_documents.py new file mode 100644 index 00000000..dd5d085d --- /dev/null +++ b/tests/test_documents.py @@ -0,0 +1,2 @@ +# Copyright DB InfraGO AG and contributors +# SPDX-License-Identifier: Apache-2.0 diff --git a/tests/test_elements.py b/tests/test_elements.py index 576a1300..c0f1c067 100644 --- a/tests/test_elements.py +++ b/tests/test_elements.py @@ -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", } }, [],
    PropertyValuePropertyValue