rendercv.renderer.templater
¶
The rendercv.renderer.templater
module contains all the necessary classes and
functions for templating the $\LaTeX$ and Markdown files from the RenderCVDataModel
object.
TemplatedFile
¶
This class is a base class for LaTeXFile
and MarkdownFile
classes. It
contains the common methods and attributes for both classes. These classes are used
to generate the $\LaTeX$ 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
(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
LaTeXFile
¶
Bases: TemplatedFile
This class represents a $\LaTeX$ file. It generates the $\LaTeX$ code with the
data model and Jinja2 templates. It inherits from the TemplatedFile
class.
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 |
|
render_templates()
¶
Render and return all the templates for the $\LaTeX$ file.
Returns:
-
tuple[str, str, list[tuple[str, list[str], str]]]
–Tuple[str, str, List[Tuple[str, List[str], str]]]: The preamble, header, and sections of the $\LaTeX$ 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
(str
) –The templated file.
Source code in rendercv/renderer/templater.py
get_full_code()
¶
Get the $\LaTeX$ code of the file.
Returns:
-
str
(str
) –The $\LaTeX$ 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. It inherits from the TemplatedFile
class.
Markdown files are generated to produce an HTML which can be copy-pasted to
Grammarly for proofreading.
Source code in rendercv/renderer/templater.py
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 271 272 273 274 275 276 277 278 279 280 281 282 |
|
render_templates()
¶
Render and return all the templates for the Markdown file.
Returns:
-
tuple[str, list[tuple[str, list[str]]]]
–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
(str
) –The templated file.
Source code in rendercv/renderer/templater.py
get_full_code()
¶
Get the Markdown code of the file.
Returns:
-
str
(str
) –The Markdown code.
Source code in rendercv/renderer/templater.py
revert_nested_latex_style_commands(latex_string)
¶
Revert the nested $\LaTeX$ style commands to allow users to unbold or unitalicize a bold or italicized text.
Parameters:
-
latex_string
(str
) –The string to revert the nested $\LaTeX$ style commands.
Returns:
-
str
(str
) –The string with the reverted nested $\LaTeX$ style commands.
Source code in rendercv/renderer/templater.py
escape_latex_characters(latex_string, strict=True)
¶
Escape $\LaTeX$ characters in a string by adding a backslash before them.
Parameters:
-
latex_string
(str
) –The string to escape.
-
strict
(bool
, default:True
) –Whether to escape all the special $\LaTeX$ characters or not. If you want to allow math input, set it to False.
Returns:
-
str
(str
) –The escaped string.
Source code in rendercv/renderer/templater.py
markdown_to_latex(markdown_string)
¶
Convert a Markdown string to $\LaTeX$.
This function is called during the reading of the input file. Before the validation process, each input field is converted from Markdown to $\LaTeX$.
Example
returns
"This is a \textbf{bold} text with a \href{https://google.com}{\textit{link}}."
Parameters:
-
markdown_string
(str
) –The Markdown string to convert.
Returns:
-
str
(str
) –The $\LaTeX$ string.
Source code in rendercv/renderer/templater.py
transform_markdown_sections_to_latex_sections(sections)
¶
Recursively loop through sections and convert all the Markdown strings (user input is in Markdown format) to $\LaTeX$ strings. Also, escape special $\LaTeX$ characters.
Parameters:
-
sections
(Optional[dict[str, SectionInput]]
) –Sections with Markdown strings.
Returns:
-
Optional[dict[str, SectionContents]]
–Optional[dict[str, dm.SectionInput]]: Sections with $\LaTeX$ 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, str]
) –The placeholders and their values.
Returns:
-
str
(str
) –The string with actual values.
Source code in rendercv/renderer/templater.py
make_matched_part_something(value, something, match_str=None)
¶
Make the matched parts of the string something. If the match_str is None, the whole string will be made something.
Warning
This function shouldn't be used directly. Use make_matched_part_bold
,
make_matched_part_underlined
, make_matched_part_italic
, or
`make_matched_part_non_line_breakable instead.
Args: value (str): The string to make something. something (str): The $\LaTeX$ command to use. match_str (str): The string to match.
Returns:
-
str
(str
) –The string with the matched part something.
Source code in rendercv/renderer/templater.py
make_matched_part_bold(value, match_str=None)
¶
Make the matched parts of the string bold. If the match_str is None, the whole string will be made bold.
This function can be used as a Jinja2 filter in templates.
Parameters:
-
value
(str
) –The string to make bold.
-
match_str
(str
, default:None
) –The string to match.
Returns:
-
str
(str
) –The string with the matched part bold.
Source code in rendercv/renderer/templater.py
make_matched_part_underlined(value, match_str=None)
¶
Make the matched parts of the string underlined. If the match_str is None, the whole string will be made underlined.
This function can be used as a Jinja2 filter in templates.
Parameters:
-
value
(str
) –The string to make underlined.
-
match_str
(str
, default:None
) –The string to match.
Returns:
-
str
(str
) –The string with the matched part underlined.
Source code in rendercv/renderer/templater.py
make_matched_part_italic(value, match_str=None)
¶
Make the matched parts of the string italic. If the match_str is None, the whole string will be made italic.
This function can be used as a Jinja2 filter in templates.
Parameters:
-
value
(str
) –The string to make italic.
-
match_str
(str
, default:None
) –The string to match.
Returns:
-
str
(str
) –The string with the matched part italic.
Source code in rendercv/renderer/templater.py
make_matched_part_non_line_breakable(value, match_str=None)
¶
Make the matched parts of the string non line breakable. If the match_str is None, the whole string will be made nonbreakable.
This function can be used as a Jinja2 filter in templates.
Parameters:
-
value
(str
) –The string to disable line breaks.
-
match_str
(str
, default:None
) –The string to match.
Returns:
-
str
(str
) –The string with the matched part non line breakable.
Source code in rendercv/renderer/templater.py
abbreviate_name(name)
¶
Abbreviate a name by keeping the first letters of the first names.
This function can be used as a Jinja2 filter in templates.
Parameters:
-
name
(str
) –The name to abbreviate.
Returns:
-
str
(str
) –The abbreviated name.
Source code in rendercv/renderer/templater.py
divide_length_by(length, divider)
¶
Divide a length by a number. Length is a string with the following regex
pattern: \d+\.?\d* *(cm|in|pt|mm|ex|em)
This function can be used as a Jinja2 filter in templates.
Parameters:
-
length
(str
) –The length to divide.
-
divider
(float
) –The number to divide the length by.
Returns:
-
str
(str
) –The divided length.
Source code in rendercv/renderer/templater.py
get_an_item_with_a_specific_attribute_value(items, attribute, value)
¶
Get an item from a list of items with a specific attribute value.
Example
get_an_item_with_a_specific_attribute_value(
[item1, item2], # where item1.name = "John" and item2.name = "Jane"
"name",
"Jane"
)
item2
This function can be used as a Jinja2 filter in templates.
Parameters:
-
items
(list[Any]
) –The list of items.
-
attribute
(str
) –The attribute to check.
-
value
(Any
) –The value of the attribute.
Returns:
-
Any
(Any
) –The item with the specific attribute value.
Source code in rendercv/renderer/templater.py
setup_jinja2_environment()
¶
Setup and return the Jinja2 environment for templating the $\LaTeX$ files.
Returns:
-
Environment
–jinja2.Environment: The theme environment.