diff --git a/docs/tutorial/index.rst b/docs/tutorial/index.rst index 403e1f3fb..bed815fdc 100644 --- a/docs/tutorial/index.rst +++ b/docs/tutorial/index.rst @@ -61,5 +61,6 @@ Let's dive into this **configuration options validation** use case. multiple examples practice1 + validators underscore_parameter whatsnext diff --git a/docs/tutorial/validators.rst b/docs/tutorial/validators.rst new file mode 100644 index 000000000..22fe966a9 --- /dev/null +++ b/docs/tutorial/validators.rst @@ -0,0 +1,47 @@ +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 ` 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 `, + this workshop page corresponds to the tag :tutorial:`v1.1_170 ` + 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 + +