Skip to content

Commit

Permalink
📚 DOCS remove jinja templating (#1079)
Browse files Browse the repository at this point in the history
It has no benefit and causes issues with raw jinja and latex builds
  • Loading branch information
chrisjsewell authored Feb 12, 2024
1 parent 6abd389 commit d74f4de
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 74 deletions.
23 changes: 1 addition & 22 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
from typing import Any, Dict, List

from sphinx.application import Sphinx
from typing import Any, Dict

from sphinx_needs import __version__

Expand Down Expand Up @@ -510,25 +508,6 @@ def custom_defined_func():
html_context = {}


def rstjinja(app: Sphinx, _docname: str, source: List[str]) -> None:
"""
Render our pages as a jinja template for fancy templating goodness.
"""
# Make sure we're outputting HTML
if app.builder.format != "html" and app.builder.name != "linkcheck":
return
src = source[0]
from jinja2 import Template

template = Template(src, autoescape=True)
rendered = template.render(**app.config.html_context)
source[0] = rendered


def setup(app: Sphinx) -> None:
app.connect("source-read", rstjinja)


# LINKCHECK config
# https://www.sphinx-doc.org/en/master/usage/configuration.html?highlight=linkcheck#options-for-the-linkcheck-builder
linkcheck_ignore = [
Expand Down
35 changes: 12 additions & 23 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,6 @@ If you do not set ``needs_report_template``, the default template used is:
.. code-block:: jinja
{% raw -%}
{# Output for needs_types #}
{% if types|length != 0 %}
.. dropdown:: Need Types
Expand Down Expand Up @@ -739,7 +737,7 @@ If you do not set ``needs_report_template``, the default template used is:
{% endif %}
{# Output for needs metrics #}
{% endraw %}
The plugin provides the following variables which you can use in your custom Jinja template:
Expand Down Expand Up @@ -770,13 +768,12 @@ By default the following template is used:
.. code-block:: jinja
{% raw -%}
{%- if is_need -%}
<size:12>{{type_name}}</size>\\n**{{title|wordwrap(15, wrapstring='**\\\\n**')}}**\\n<size:10>{{id}}</size>
{%- else -%}
<size:12>{{type_name}} (part)</size>\\n**{{content|wordwrap(15, wrapstring='**\\\\n**')}}**\\n<size:10>{{id_parent}}.**{{id}}**</size>
{%- endif -%}
{% endraw %}
.. _needs_id_required:
Expand Down Expand Up @@ -1550,7 +1547,7 @@ Default: ``False``.
needs_service_all_data = True
{% raw %}
.. _needs_external_needs:
Expand Down Expand Up @@ -1626,7 +1623,7 @@ keys:
The related CSS class definition must be done by the user, e.g. by :ref:`own_css`.
(*optional*) (*default*: ``external_link``)
{% endraw %}
.. _needs_needextend_strict:
Expand Down Expand Up @@ -1718,7 +1715,7 @@ All named capture group values get injected, so that parts of the option-value c
link name and url.
**Example**:
{% raw %}
.. code-block:: python
Expand All @@ -1740,7 +1737,7 @@ link name and url.
'options': ['github']
}
}
{% endraw %}
|ex|
Expand Down Expand Up @@ -1955,7 +1952,7 @@ constraints_results is a dictionary similar in structure to needs_constraints ab
"critical": {
"check_0": "'critical' in tags",
"severity": "CRITICAL",
"error_message": "need {% raw %}{{id}}{% endraw %} does not fulfill CRITICAL constraint, because tags are {% raw %}{{tags}}{% endraw %}"
"error_message": "need {{id}} does not fulfill CRITICAL constraint, because tags are {{tags}}"
}
}
Expand Down Expand Up @@ -2137,8 +2134,6 @@ You can use the data passed via needs_render_context as shown below:
.. code-block:: jinja
{% raw -%}
.. req:: Need with jinja_content enabled
:id: JINJA1D8913
:jinja_content: true
Expand All @@ -2153,9 +2148,7 @@ You can use the data passed via needs_render_context as shown below:
+ author[1]
{% endfor %}
{% endraw %}
{% raw -%}
.. req:: Need with jinja_content enabled
:id: JINJA1D8913
Expand All @@ -2168,7 +2161,7 @@ You can use the data passed via needs_render_context as shown below:
* {{ author[0] }} --> ID-{{ author[1] }}
{% endfor %}
{% endraw %}
.. _needs_debug_measurement:
Expand Down Expand Up @@ -2205,8 +2198,6 @@ If nothing is set, the following default template is used:
.. code-block:: jinja
{% raw -%}
.. _{{id}}:
{% if hide == false -%}
Expand Down Expand Up @@ -2236,7 +2227,7 @@ If nothing is set, the following default template is used:
{% endif -%}
{% endraw %}
Available jinja variables are:
Expand All @@ -2254,7 +2245,7 @@ Available jinja variables are:
.. warning::
You must add a reference like `.. _{{ '{{id}}' }}:` to the template. Otherwise linking will not work!
You must add a reference like `.. _{{id}}:` to the template. Otherwise linking will not work!
.. _needs_template_collapse:
Expand All @@ -2268,8 +2259,6 @@ Default value:
.. code-block:: jinja
{% raw -%}
.. _{{id}}:
{% if hide == false -%}
Expand Down Expand Up @@ -2298,7 +2287,7 @@ Default value:
{{content|indent(4) }}
{% endif -%}
{% endraw %}
For more details please see :ref:`needs_template`.
Expand Down
11 changes: 4 additions & 7 deletions docs/directives/need.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ and stores its PlantUML code under given key from :ref:`needuml` directive under

This diagram data can then be used in other :ref:`needuml` calls to combine and reuse PlantUML elements.

{% raw %}


|ex|

Expand Down Expand Up @@ -251,7 +251,7 @@ Reuse of :need:`SP_INT` inside a :ref:`needuml`:

system => int_a

{% endraw %}


This simple mechanism is really powerful to design reusable and configurable SW architecture diagrams.
For more examples and details, please read :ref:`needuml`.
Expand Down Expand Up @@ -553,7 +553,6 @@ Default: False

.. code-block:: jinja
{% raw -%}
.. req:: First Req Need
:id: JINJAID123
:jinja_content: false
Expand Down Expand Up @@ -584,12 +583,10 @@ Default: False
Need with ``:jinja_content:`` equal to ``true``.
This requirement has status: **{{ status }}**.
{% endraw %}
|out|

{% raw -%}

.. req:: First Req Need
:id: JINJAID123
:jinja_content: false
Expand Down Expand Up @@ -620,7 +617,7 @@ Default: False
Need with ``:jinja_content:`` equal to ``true``.
This requirement has status: **{{ status }}**.

{% endraw %}


.. _title_from_content:

Expand Down
4 changes: 2 additions & 2 deletions docs/directives/needarch.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% raw %}


.. _needarch:

Expand Down Expand Up @@ -256,4 +256,4 @@ does detect different parameter sets and does import `uml()` calls with differen
{{uml('COMP_T_002')}}
{% endif %}

{% endraw %}

4 changes: 2 additions & 2 deletions docs/directives/needuml.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% raw %}


.. _needuml:

Expand Down Expand Up @@ -741,4 +741,4 @@ NeedUml Examples

class_x o-- class_y

{% endraw %}

6 changes: 3 additions & 3 deletions docs/layout_styles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,13 @@ The head-line for the default Sphinx-Needs layout ``clean`` looks like this::
You are free to surround a layout function with a rst role. Like ``**<<meta("title")>>**`` to get a bold printed title.

Sometimes an argument for a layout function shall be based on a given need option. In this cases the option name
can be surrounded by ``{%raw%}{{ .. }}{%endraw%}``.
can be surrounded by ``{{ .. }}``.
As example, there may be an ``author`` option in a bug-need and you want to show a picture of the author in the grid
``simple_side_right_partial``.

The line for the ``side`` area could look like::

'<<image("_images/{%raw%}{{author}}{%endraw%}.png", align="center")>>'
'<<image("_images/{{author}}.png", align="center")>>'

.. spec:: My test spec
:author: daniel
Expand Down Expand Up @@ -326,7 +326,7 @@ Here is the complete used code::
'head': ['**<<meta("title")>>** for *<<meta("author")>>*'],
'meta': ['**status**: <<meta("status")>>',
'**author**: <<meta("author")>>'],
'side': ['<<image("_images/{%raw%}{{author}}{%endraw%}.png", align="center")>>']
'side': ['<<image("_images/{{author}}.png", align="center")>>']
}
}
}
Expand Down
12 changes: 0 additions & 12 deletions docs/roles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -202,21 +202,9 @@ They are also getting the part_id as link description.
|out|

{% if READTHEDOCS %}
..
.. image:: _static/need_part_as_flow.png
:align: center

{% else %}

.. needflow::
:filter: id in ["my_car_1","impl_my_car_1"]

{% endif %}



**Presentation in needtable**

Please see :ref:`needtable_show_parts` of :ref:`needtable` configuration documentation.
Expand Down
6 changes: 3 additions & 3 deletions docs/services/open_needs.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. _open_needs_service:

{% raw %}


Open-Needs services
===================
Expand Down Expand Up @@ -199,7 +199,7 @@ The logic and syntax is the same as used by `mapping <#mapping>`_.
:language: python
:lines: 329-346

{% endraw %}


Examples
--------
Expand All @@ -226,4 +226,4 @@ Examples

.. image:: /_images/ons_table.png
:align: center
:width: 60%
:width: 60%

0 comments on commit d74f4de

Please sign in to comment.