docs: restructure context vars, add undocumented ones (#1856)

This commit is contained in:
jeanluc 2024-11-12 20:54:40 +00:00 committed by GitHub
parent 19156ee3be
commit 2e7629e3d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 53 additions and 21 deletions

View File

@ -75,27 +75,58 @@ their usage.
In addition to In addition to
[all the features Jinja supports](https://jinja.palletsprojects.com/en/3.1.x/templates/), [all the features Jinja supports](https://jinja.palletsprojects.com/en/3.1.x/templates/),
Copier includes: Copier provides all functions and filters from
[jinja2-ansible-filters](https://gitlab.com/dreamer-labs/libraries/jinja2-ansible-filters/).
This includes the `to_nice_yaml` filter, which is used extensively in our context.
- All functions and filters from ## Variables (global)
[jinja2-ansible-filters](https://gitlab.com/dreamer-labs/libraries/jinja2-ansible-filters/).
- This includes the `to_nice_yaml` filter, which is used extensively in our The following variables are always available in Jinja templates:
context.
- `_copier_answers` includes the current answers dict, but slightly modified to make ### `_copier_answers`
it suitable to [autoupdate your project safely][the-copier-answersyml-file]:
- It doesn't contain secret answers. `_copier_answers` includes the current answers dict, but slightly modified to make it
- It doesn't contain any data that is not easy to render to JSON or YAML. suitable to [autoupdate your project safely][the-copier-answersyml-file]:
- It contains special keys like `_commit` and `_src_path`, indicating how the last
template update was done. - It doesn't contain secret answers.
- `_copier_conf` includes a representation of the current Copier - It doesn't contain any data that is not easy to render to JSON or YAML.
<!-- prettier-ignore --> - It contains special keys like `_commit` and `_src_path`, indicating how the last
[Worker][copier.main.Worker] object, also slightly modified: template update was done.
- It only contains JSON-serializable data.
- You can serialize it with `{{ _copier_conf|to_json }}`. ### `_copier_conf`
- ⚠️ It contains secret answers inside its `.data` key.
- Modifying it doesn't alter the current rendering configuration. `_copier_conf` includes a representation of the current Copier
- It contains the current commit hash from the template in [Worker][copier.main.Worker] object, also slightly modified:
`{{ _copier_conf.vcs_ref_hash }}`.
- Contains Operating System-specific directory separator under `sep` key. - It only contains JSON-serializable data.
- You can serialize it with `{{ _copier_conf|to_json }}`.
- ⚠️ It contains secret answers inside its `.data` key.
- Modifying it doesn't alter the current rendering configuration.
Furthermore, the following keys are added:
#### `os` { #\_copier_conf.os }
The detected operating system, either `"linux"`, `"macos"`, `"windows"` or `None`.
#### `sep` { #\_copier_conf.sep }
The operating system-specific directory separator.
#### `vcs_ref_hash` { #\_copier_conf.vcs_ref_hash }
The current commit hash from the template.
### `_copier_python`
The absolute path of the Python interpreter running Copier.
### `_folder_name`
The name of the project root directory.
## Variables (context-specific)
Some rendering contexts provide variables unique to them:
- [`migrations`](configuring.md#migrations)

View File

@ -57,6 +57,7 @@ extra_css:
markdown_extensions: markdown_extensions:
- admonition - admonition
- attr_list
- pymdownx.highlight: - pymdownx.highlight:
use_pygments: true use_pygments: true
- pymdownx.superfences: - pymdownx.superfences: