rendercv.renderer.templater
¶
The rendercv.renderer.templater
module contains all the necessary classes and
functions for templating the Typst and Markdown files from the RenderCVDataModel
object.
TemplatedFile
¶
This class is a base class for TypstFile
, and MarkdownFile
classes. It
contains the common methods and attributes for both classes. These classes are used
to generate the Typst and Markdown files with the data model and Jinja2
templates.
Parameters:
-
data_model
(RenderCVDataModel
) –The data model.
-
environment
(Environment
) –The Jinja2 environment.
Source code in rendercv/renderer/templater.py
template(theme_name, template_name, extension, entry=None, **kwargs)
¶
Template one of the files in the themes
directory.
Parameters:
-
template_name
(str
) –The name of the template file.
-
entry
(Optional[Entry]
, default:None
) –The title of the section.
Returns:
-
str
–The templated file.
Source code in rendercv/renderer/templater.py
get_full_code(main_template_name, **kwargs)
¶
Combine all the templates to get the full code of the file.
Source code in rendercv/renderer/templater.py
TypstFile
¶
Bases: TemplatedFile
This class represents a Typst file. It generates the Typst code with the data model and Jinja2 templates.
Source code in rendercv/renderer/templater.py
93 94 95 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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
|
render_templates()
¶
Render and return all the templates for the Typst file.
Returns:
-
tuple[str, str, list[tuple[str, list[str], str]]]
–The preamble, header, and sections of the Typst file.
Source code in rendercv/renderer/templater.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
template(template_name, entry=None, **kwargs)
¶
Template one of the files in the themes
directory.
Parameters:
-
template_name
(str
) –The name of the template file.
-
entry
(Optional[Entry]
, default:None
) –The data model of the entry.
Returns:
-
str
–The templated file.
Source code in rendercv/renderer/templater.py
get_full_code()
¶
Get the Typst code of the file.
Returns:
-
str
–The Typst code.
Source code in rendercv/renderer/templater.py
MarkdownFile
¶
Bases: TemplatedFile
This class represents a Markdown file. It generates the Markdown code with the data model and Jinja2 templates. Markdown files are generated to produce an HTML which can be copy-pasted to Grammarly for proofreading.
Source code in rendercv/renderer/templater.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
|
render_templates()
¶
Render and return all the templates for the Markdown file.
Returns:
-
tuple[str, list[tuple[str, list[str]]]]
–The header and sections of the Markdown file.
Source code in rendercv/renderer/templater.py
template(template_name, entry=None, **kwargs)
¶
Template one of the files in the themes
directory.
Parameters:
-
template_name
(str
) –The name of the template file.
-
entry
(Optional[Entry]
, default:None
) –The data model of the entry.
Returns:
-
str
–The templated file.
Source code in rendercv/renderer/templater.py
get_full_code()
¶
Get the Markdown code of the file.
Returns:
-
str
–The Markdown code.
Source code in rendercv/renderer/templater.py
input_template_to_typst(input_template, placeholders)
¶
Convert an input template to Typst.
Parameters:
-
input_template
(Optional[str]
) –The input template.
-
placeholders
(dict[str, Optional[str]]
) –The placeholders and their values.
Returns:
-
str
–Typst string.
Source code in rendercv/renderer/templater.py
escape_characters(string, escape_dictionary)
¶
Escape characters in a string by using escape_dictionary
, where keys are
characters to escape and values are their escaped versions.
Parameters:
-
string
(str
) –The string to escape.
-
escape_dictionary
(dict[str, str]
) –The dictionary of escape characters.
Returns:
-
str
–The escaped string.
Source code in rendercv/renderer/templater.py
escape_typst_characters(string)
¶
Escape Typst characters in a string by adding a backslash before them.
Parameters:
-
string
(str
) –The string to escape.
Returns:
-
str
–The escaped string.
Source code in rendercv/renderer/templater.py
markdown_to_typst(markdown_string)
¶
Convert a Markdown string to Typst.
Example
returns
"This is a *bold* text with an #link("https://google.com")[_italic link_]."
Parameters:
-
markdown_string
(str
) –The Markdown string to convert.
Returns:
-
str
–The Typst string.
Source code in rendercv/renderer/templater.py
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 |
|
transform_markdown_sections_to_something_else_sections(sections, functions_to_apply)
¶
Recursively loop through sections and update all the strings by applying the
functions_to_apply
functions, given as an argument.
Parameters:
-
sections
(dict[str, SectionContents]
) –Sections with Markdown strings.
-
functions_to_apply
(list[Callable]
) –Functions to apply to the strings.
Returns:
-
Optional[dict[str, SectionContents]]
–Sections with updated strings.
Source code in rendercv/renderer/templater.py
transform_markdown_sections_to_typst_sections(sections)
¶
Recursively loop through sections and convert all the Markdown strings (user input is in Markdown format) to Typst strings.
Parameters:
-
sections
(dict[str, SectionContents]
) –Sections with Markdown strings.
Returns:
-
Optional[dict[str, SectionContents]]
–Sections with Typst strings.
Source code in rendercv/renderer/templater.py
replace_placeholders_with_actual_values(text, placeholders)
¶
Replace the placeholders in a string with actual values.
This function can be used as a Jinja2 filter in templates.
Parameters:
-
text
(str
) –The text with placeholders.
-
placeholders
(dict[str, Optional[str]]
) –The placeholders and their values.
Returns:
-
str
–The string with actual values.