Jinja
sereto.jinja
¶
get_generic_jinja_env(templates)
¶
Creates a generic Jinja2 environment object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
templates
|
DirectoryPath | Sequence[DirectoryPath]
|
The directory/directories containing template files. |
required |
Returns:
Type | Description |
---|---|
Environment
|
A Jinja2 environment object. |
Source code in sereto/jinja.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
get_tex_jinja_env(templates)
¶
Creates a Jinja2 environment object for rendering TeX templates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
templates
|
DirectoryPath | Sequence[DirectoryPath]
|
The directory/directories containing the TeX template files. |
required |
Returns:
Type | Description |
---|---|
Environment
|
A Jinja2 environment object that is configured for rendering TeX templates. |
Source code in sereto/jinja.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
render_jinja2(file, templates, vars)
¶
Renders a Jinja2 template.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
FilePath
|
The path to the template file to be rendered. |
required |
templates
|
DirectoryPath | Sequence[DirectoryPath]
|
The directory/directories containing the template files. |
required |
vars
|
dict[str, Any]
|
A dictionary of variables to be passed to the Jinja2 template engine. |
required |
Returns:
Type | Description |
---|---|
Iterator[str]
|
A generator that yields the rendered template as a string. |
Source code in sereto/jinja.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
tex_escape_filter(text, default='n/a')
¶
Escape special characters in text for use in TeX.
This function serves as a Jinja2 filter to escape special characters in text
for use in TeX. It replaces each
special character with its corresponding TeX escape sequence. The default
argument can be used to specify a
default value to return if text
is undefined or empty.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
Any
|
The text to be escaped. |
required |
default
|
str
|
The default value to return if |
'n/a'
|
Returns:
Type | Description |
---|---|
str
|
The escaped text. |
Source code in sereto/jinja.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
yesno_filter(value, arg='yes,no,maybe')
¶
Tex filter for converting boolean values to strings.
Given a string mapping values for true, false, and (optionally) None,
return one of those strings according to the value:
========== ====================== ==================================
Value Argument Outputs
========== ====================== ==================================
True
"yeah,no,maybe"
yeah
False
"yeah,no,maybe"
no
None
"yeah,no,maybe"
maybe
None
"yeah,no"
"no"
(converts None to False
if no mapping for None is given.
========== ====================== ==================================
Source code in sereto/jinja.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|