fix small bugs in renderer.py

This commit is contained in:
Sina Atalay 2024-02-06 21:17:51 +01:00
parent d30534bf2a
commit b71eb431c0
1 changed files with 11 additions and 8 deletions

View File

@ -172,14 +172,11 @@ def make_matched_part_something(
str: The string with the matched part something. str: The string with the matched part something.
""" """
if match_str is None: if match_str is None:
return f"\\{something}{{{value}}}" value = f"\\{something}{{{value}}}"
elif match_str in value and match_str != "":
elif match_str in value:
value = value.replace(match_str, f"\\{something}{{{match_str}}}") value = value.replace(match_str, f"\\{something}{{{match_str}}}")
return value
else: return value
return value
def make_matched_part_bold(value: str, match_str: Optional[str] = None) -> str: def make_matched_part_bold(value: str, match_str: Optional[str] = None) -> str:
@ -299,6 +296,11 @@ def abbreviate_name(name: str) -> str:
Returns: Returns:
str: The abbreviated name. str: The abbreviated name.
""" """
number_of_words = len(name.split(" "))
if number_of_words == 1:
return name
first_names = name.split(" ")[:-1] first_names = name.split(" ")[:-1]
first_names_initials = [first_name[0] + "." for first_name in first_names] first_names_initials = [first_name[0] + "." for first_name in first_names]
last_name = name.split(" ")[-1] last_name = name.split(" ")[-1]
@ -336,6 +338,9 @@ def divide_length_by(length: str, divider: float) -> str:
else: else:
value = value.group() value = value.group()
if divider <= 0:
raise ValueError(f"The divider must be greater than 0, but got {divider}!")
unit = re.findall(r"[^\d\.\s]+", length)[0] unit = re.findall(r"[^\d\.\s]+", length)[0]
return str(float(value) / divider) + " " + unit return str(float(value) / divider) + " " + unit
@ -375,7 +380,6 @@ def setup_jinja2_environment() -> jinja2.Environment:
return environment return environment
# @time_the_event_below("Generating the LaTeX file")
def generate_latex_file( def generate_latex_file(
rendercv_data_model: dm.RenderCVDataModel, output_directory: pathlib.Path rendercv_data_model: dm.RenderCVDataModel, output_directory: pathlib.Path
) -> pathlib.Path: ) -> pathlib.Path:
@ -421,7 +425,6 @@ def generate_latex_file(
return latex_file_path return latex_file_path
# @time_the_event_below("Generating the PDF file")
def latex_to_pdf(latex_file_path: pathlib.Path) -> pathlib.Path: def latex_to_pdf(latex_file_path: pathlib.Path) -> pathlib.Path:
"""Run TinyTeX with the given $\\LaTeX$ file to generate the PDF. """Run TinyTeX with the given $\\LaTeX$ file to generate the PDF.