You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enhance Template Handling with Jinja2 Support and Custom Filters (#4)
#### Overview
This PR introduces significant enhancements to the template processing
capabilities by integrating Jinja2 for more flexible and powerful
templating. Additionally, new custom filters have been added to extend
the functionality, specifically for fetching the latest GitHub release.
#### Changes
- **Jinja2 Integration**: Replaced the existing string templating
mechanism with Jinja2, allowing for more complex templating options.
- **New Template Variables**: Added support for default template
variables like `file_name` and `file_directory`.
- **Custom Filters**: Introduced a new custom Jinja2 filter
`latest_release` that fetches the latest release version from a GitHub
repository.
- **Updated Documentation**: Enhanced the README files (`README.md` and
`README.es.md`) with detailed information on how to use the new
templating features, including variables and custom filters.
- **Configuration Updates**: Extended the `generic-app.yaml` and
`structure.yaml` examples to demonstrate the use of the new templating
features.
- **Dependencies**: Added `jinja2` and `PyGithub` to `requirements.txt`
to support the new templating and GitHub API functionalities.
#### Justification
These changes provide more robust and flexible template processing,
enabling users to create more dynamic and maintainable configurations.
The new features simplify complex templating scenarios and extend the
capability to interact with external APIs, like GitHub, directly within
the templates.
#### Impact
- **Developers**: Improved ability to create and manage complex
templates with dynamic content.
- **Project Maintenance**: Enhanced documentation will make it easier
for new contributors to understand and utilize the templating system.
- **Dependencies**: Additional dependencies (`jinja2` and `PyGithub`)
will be required, which might affect environments where this project is
used.
Puedes usar variables de plantilla en tu archivo de configuración encerrándolas entre `{{@` y `@}}`. Por ejemplo, `{{@ project_name @}}` será reemplazado con el valor de la variable `project_name` en tiempo de ejecución.
161
+
162
+
Si necesitas definir bloques, puedes usar la notación de inicio de bloque `{%@` y la notación de final de bloque `%@}`.
163
+
164
+
Para definir comentarios, puedes usar la notación de inicio de comentario `{#@` y la notación de fin de comentario `@#}`.
165
+
166
+
#### Variables de plantilla predeterminadas
167
+
168
+
- `file_name`: El nombre del archivo que se está procesando.
169
+
- `file_directory`: El nombre del directorio del archivo que se está procesando.
170
+
171
+
#### Filtros personalizados de Jinja2
172
+
173
+
##### `latest_release`
174
+
175
+
Este filtro obtiene la versión más reciente de una release en un repositorio de GitHub. Toma el nombre del repositorio como argumento.
Esto utiliza PyGithub para obtener la última release del repositorio, por lo que configurar la variable de entorno `GITHUB_TOKEN` te dará acceso a repositorios privados.
186
+
187
+
Si ocurre un error en el proceso, el filtro devolverá `LATEST_RELEASE_ERROR`.
188
+
158
189
## 👩💻 Desarrollo
159
190
160
191
Para comenzar con el desarrollo, sigue estos pasos:
You can use template variables in your configuration file by enclosing them in `{{@` and `@}}`. For example, `{{@ project_name @}}` will be replaced with the value of the `project_name` variable at runtime.
166
+
167
+
If you need to define blocks you can use starting block notation `{%@` and end block notation `%@}`.
168
+
169
+
To define comments you can use the comment start notation `{#@` and end comment notation `@#}`.
170
+
171
+
#### Default template variables
172
+
173
+
- `file_name`: The name of the file being processed.
174
+
- `file_directory`: The name of the directory of file that is being processed.
175
+
176
+
#### Custom Jinja2 filters
177
+
178
+
##### `latest_release`
179
+
180
+
This filter fetches the latest release version of a GitHub repository. It takes the repository name as an argument.
This uses PyGithub to fetch the latest release of the repository so setting the `GITHUB_TOKEN` environment variable will give you access to private repositories.
191
+
192
+
If there is an error in the process, the filter will return `LATEST_RELEASE_ERROR`.
193
+
163
194
## 👩💻 Development
164
195
165
196
To get started with development, follow these steps:
0 commit comments