docs: add rougail path in the lipogram doc sample

This commit is contained in:
gwen 2024-01-29 00:59:11 +01:00
parent 4770eb0d0e
commit d2f140c295

View file

@ -31,16 +31,16 @@ Here is a first :file:`dict/00-base.yml` dictionary:
Then, let's create the :term:`Tiramisu` objects via the following script: Then, let's create the :term:`Tiramisu` objects via the following script:
.. code-block:: python .. code-block:: python
:caption: the `script.py` file content :caption: the `script.py` file content
from rougail import Rougail, RougailConfig from rougail import Rougail, RougailConfig
RougailConfig['dictionaries_dir'] = ['dict'] RougailConfig['dictionaries_dir'] = ['dict']
rougail = Rougail() rougail = Rougail()
config = rougail.get_config() config = rougail.get_config()
print(config.value.get()) print(config.value.get())
Let's execute `script.py`: Let's execute `script.py`:
.. code-block:: bash .. code-block:: bash
@ -76,9 +76,9 @@ Then let's create an extra :term:`dictionary` :file:`extras/00-base.yml`:
Then, let's create the :term:`Tiramisu` objects via the following :file:`script.py` script: Then, let's create the :term:`Tiramisu` objects via the following :file:`script.py` script:
.. code-block:: python .. code-block:: python
:caption: the :file:`script.py` file content :caption: the :file:`script.py` file content
from rougail import Rougail, RougailConfig from rougail import Rougail, RougailConfig
RougailConfig['dictionaries_dir'] = ['dict'] RougailConfig['dictionaries_dir'] = ['dict']
@ -105,21 +105,21 @@ We create the complementary :term:`dictionary` named :file:`dict/01-function.yml
version: '1.0' version: '1.0'
my_variable_jinja: my_variable_jinja:
type: "string" type: "string"
default: default:
type: jinja type: jinja
jinja: "{{ return_no() }}" jinja: "{{ return_no() }}"
Then let's define the :func:`return_no` function in :file:`functions.py`: Then let's define the :func:`return_no` function in :file:`functions.py`:
.. code-block:: python .. code-block:: python
:caption: the :file:`functions.py` content :caption: the :file:`functions.py` content
def return_no(): def return_no():
return 'no' return 'no'
Then, let's create the :term:`Tiramisu` objects via the following script: Then, let's create the :term:`Tiramisu` objects via the following script:
.. code-block:: python .. code-block:: python
:caption: the `script.py` file content :caption: the `script.py` file content
from rougail import Rougail, RougailConfig from rougail import Rougail, RougailConfig
@ -152,15 +152,15 @@ It's possible to create your own type.
Here an example to a lipogram option (in a string, we cannot use "e" character): Here an example to a lipogram option (in a string, we cannot use "e" character):
.. code-block:: python .. code-block:: python
:caption: the `lipogram.py` file content :caption: the `lipogram.py` file content
from tiramisu import StrOption from tiramisu import StrOption
class LipogramOption(StrOption): class LipogramOption(StrOption):
__slots__ = tuple() __slots__ = tuple()
_type = 'lipogram' _type = 'lipogram'
def validate(self, def validate(self,
value): value):
super().validate(value) super().validate(value)
# verify that there is any 'e' in the sentense # verify that there is any 'e' in the sentense
@ -169,7 +169,7 @@ Here an example to a lipogram option (in a string, we cannot use "e" character):
To add the new lipogram type in Rougail: To add the new lipogram type in Rougail:
.. code-block:: python .. code-block:: python
>>> from rougail import Rougail, RougailConfig >>> from rougail import Rougail, RougailConfig
>>> RougailConfig['dictionaries_dir'] = ['dict'] >>> RougailConfig['dictionaries_dir'] = ['dict']
>>> RougailConfig['custom_types']['lipogram'] = LipogramOption >>> RougailConfig['custom_types']['lipogram'] = LipogramOption
@ -183,10 +183,10 @@ Here is a :file:`dict/00-base.yml` dictionary:
var: var:
type: lipogram type: lipogram
.. code-block:: python .. code-block:: python
>>> rougail = Rougail() >>> rougail = Rougail()
>>> config = rougail.get_config() >>> config = rougail.get_config()
>>> config.option('var').value.set('blah') >>> config.option('rougail.var').value.set('blah')
>>> config.option('var').value.set('I just want to add a quality string that has no bad characters') >>> config.option('rougail.var').value.set('I just want to add a quality string that has no bad characters')
[...] [...]
tiramisu.error.ValueOptionError: "I just want to add a quality string that has no bad characters" is an invalid lipogram for "var", Perec wrote a book without any "e", you could not do it in a simple sentence? tiramisu.error.ValueOptionError: "I just want to add a quality string that has no bad characters" is an invalid lipogram for "var", Perec wrote a book without any "e", you could not do it in a simple sentence?