48 lines
2 KiB
ReStructuredText
48 lines
2 KiB
ReStructuredText
|
|
Validators
|
|||
|
|
=============
|
|||
|
|
|
|||
|
|
.. objectives:: Objectives
|
|||
|
|
|
|||
|
|
We will see how to create strong validations for the values of our variables,
|
|||
|
|
that is, validations that go beyond those inherent in the initial type definition.
|
|||
|
|
|
|||
|
|
.. prerequisites:: Prerequisites
|
|||
|
|
|
|||
|
|
- We assume that Rougail's library is :ref:`installed <installation>` on your computer.
|
|||
|
|
|
|||
|
|
- It is possible to retrieve the current state of the various Rougail files manipulated in this tutorial step
|
|||
|
|
by checking out the corresponding tag of the `rougail-tutorials` git repository.
|
|||
|
|
Each tag corresponds to a stage of progress in the tutorial.
|
|||
|
|
Of course, you can also decide to copy/paste or download the tutorial files contents while following the tutorial steps.
|
|||
|
|
|
|||
|
|
If you want to follow this tutorial with the help of the corresponding :tutorial:`rougail-tutorials git repository <src/branch/v1.1>`,
|
|||
|
|
this workshop page corresponds to the tag :tutorial:`v1.1_170 <src/tag/v1.1_170/README.md>`
|
|||
|
|
in the repository.
|
|||
|
|
|
|||
|
|
::
|
|||
|
|
|
|||
|
|
git clone https://forge.cloud.silique.fr/stove/rougail-tutorials.git
|
|||
|
|
git switch --detach v1.1_170
|
|||
|
|
|
|||
|
|
A variable with custom validation
|
|||
|
|
-----------------------------------
|
|||
|
|
|
|||
|
|
Now, we would like the :term:`operator` to remember not to forget the http protocol, that is to put `http://` at the beginning of our `web_address` variable's value. What if he has forgotten the http protocol? We can add a reminder in case he has forgotten.
|
|||
|
|
|
|||
|
|
We call it a validator.
|
|||
|
|
|
|||
|
|
.. glossary::
|
|||
|
|
|
|||
|
|
validator
|
|||
|
|
|
|||
|
|
A validator is a jinja code that parses a variable's value and checks
|
|||
|
|
that this value corresponds to some stated criteria.
|
|||
|
|
This is a `validator` parameter of our variable, and another `jinja` sub-parameter
|
|||
|
|
contains validation code for the variable's value.
|
|||
|
|
|
|||
|
|
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_170/firefox/60-dns_over_https.yml
|
|||
|
|
:language: yaml
|
|||
|
|
:caption: The :file:`firefox/60-dns_over_https.yml` with the jinja validator
|
|||
|
|
|
|||
|
|
|