diff --git a/docs/tutorial/calculation.rst b/docs/tutorial/calculation.rst index 8c850addf..0c816c005 100644 --- a/docs/tutorial/calculation.rst +++ b/docs/tutorial/calculation.rst @@ -153,7 +153,6 @@ The default values can be calculated too. .. todo:: montrer aussi ici des exemples de calculs de valeurs variables, ce qui est un des usages principaux de jinja - Using jinja in a dynamic family declaration ----------------------------------------------- @@ -173,10 +172,11 @@ the identifier's variable is named "identifier" by default. Sounds logical: - HTTPS - SOCKS - Here the identifer's variable takes the value of the `dynamic` family parameter. -We have another possibility: +.. type-along:: Using a jinja calculation with a parameter + +We have the possibility to use a given variable variable inside a jinja calculation: .. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_050/firefox/20-manual.yml :language: yaml @@ -225,7 +225,9 @@ We have another possibility: type: identifier when: 'HTTPS' -Here in the `hidden` property we have the possibility to name an identifier: +This can be done by defining a `my_identifier` variable. + +This jinja variable comes from the `params` parameter of the `hidden` property. .. code-block:: yaml @@ -233,7 +235,8 @@ Here in the `hidden` property we have the possibility to name an identifier: my_identifier: type: identifier -Here, the identifer is named `my_identifier`, in a jinja calculation: +Here the `hidden` property's value is defined by a jinja calculation. +In this jinja calculation we have a `my_identifier` jinja variable. .. code-block:: yaml @@ -248,11 +251,60 @@ Here, the identifer is named `my_identifier`, in a jinja calculation: description: | in HTTPS case if "manual.use_for_https" is set to True +.. type-along:: The `when` and `when_not` parameter notation + +Handling the SOCKS version +---------------------------- + +Now we need to handle the SOKS version as show in the firefox configuration screenshot: + +.. image:: images/firefox_soks_version.png + + +We'll just add a choice variable with a default value and a disabled property: + +.. code-block:: yaml + + version: + description: SOCKS host version used by proxy + choices: + - v4 + - v5 + default: v5 + disabled: + type: identifier + when: 'HTTPS' + +There is still something new about this YAML, though. It is the `when` parameter +of the `disabled` property. You have two possible notations: `when` or `when_not`. +These two notations are just a short hand of what we could express in jinja as +this code: + +.. code-block:: jinja + + {% if identifier == 'HTTPS' %} + when the identifer equals 'HTTPS' then the SOCKS version is disabled + {% endif %} + +And the `when_not` parameter is just the logical opposite. + +Here is the final version of our YAML dynamic family: + +.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_050/firefox/20-manual.yml + :language: yaml + :caption: firefox/20-proxy.yml .. keypoints:: Key points + **keywords** + + - calculation with a jinja type calculation + - calculation with a `when` or `when_not` parameter + - defining a jinja internal variable in a jinja calculation + + **progress** + Here we have come to the possibility of making any kind of calculations based on the state of the :term:`configuration`. This is an important feature to manage the stateful aspect of a configuration. - diff --git a/docs/tutorial/images/firefox_soks_version.png b/docs/tutorial/images/firefox_soks_version.png new file mode 100644 index 000000000..b7ca7aa08 Binary files /dev/null and b/docs/tutorial/images/firefox_soks_version.png differ