environment (4)
evaluate¶
evaluate(self, code: str, context: dict[str, typing.Any] | None = None) -> str
Evaluate python code and return the caught stdout + return value of last line.
DocStrings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
The code to execute |
required |
context
|
dict[str, Any] | None
|
Globals for the execution environment |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The combined standard output and return value of the last |
str
|
line of code. |
Source code in src/jinjarope/environment.py
render_file¶
render_file(self, file: str | os.PathLike[str], variables: dict[str, typing.Any] | None = None, **kwargs: Any) -> str
Helper to directly render a template from filesystem.
Example
Jinja call:
Result:"""Tests suite forjinjarope`."""
from pathlib import Path
TESTS_DIR = Path(file).parent TMP_DIR = TESTS_DIR / "tmp" FIXTURES_DIR = TESTS_DIR / "fixtures"`
DocStrings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str | PathLike[str]
|
Template file to load |
required |
variables
|
dict[str, Any] | None
|
Extra variables for the rendering |
None
|
kwargs
|
Any
|
Further extra variables for rendering |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The rendered string. |
Source code in src/jinjarope/environment.py
render_string¶
render_string(self, string: str, variables: dict[str, typing.Any] | None = None, **kwargs: Any) -> str
Render a template string.
DocStrings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
string
|
str
|
String to render |
required |
variables
|
dict[str, Any] | None
|
Extra variables for the rendering |
None
|
kwargs
|
Any
|
Further extra variables for rendering |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The rendered string. |
Source code in src/jinjarope/environment.py
render_template¶
render_template(self, template_name: str, variables: dict[str, typing.Any] | None = None, block_name: str | None = None, parent_template: str | None = None, **kwargs: Any) -> str
Render a loaded template (or a block of a template).
DocStrings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template_name
|
str
|
Template name |
required |
variables
|
dict[str, Any] | None
|
Extra variables for rendering |
None
|
block_name
|
str | None
|
Render specific block from the template |
None
|
parent_template
|
str | None
|
The name of the parent template importing this template |
None
|
kwargs
|
Any
|
Further extra variables for rendering |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The rendered string. |
Raises:
| Type | Description |
|---|---|
BlockNotFoundError
|
If the specified block is not found in the |