From 9607f15751b279f82037c7f8669c8a0bbaa87d7c Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Sat, 7 Oct 2023 17:59:53 +0200 Subject: [PATCH] compute last updated date on python side --- rendercv/__init__.py | 2 +- rendercv/rendering.py | 19 ++++++++++++++++++- rendercv/templates/classic.tex.j2 | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/rendercv/__init__.py b/rendercv/__init__.py index 480bd13..2cbc3a7 100644 --- a/rendercv/__init__.py +++ b/rendercv/__init__.py @@ -1,4 +1,4 @@ -"""RenderCV package. +r"""RenderCV package. It parses the user input YAML/JSON file and validates the data (checks spelling mistakes, checks if the dates are consistent, etc.). Then, with the data, it creates a $\LaTeX$ file and renders it with [TinyTeX](https://yihui.org/tinytex/). """ diff --git a/rendercv/rendering.py b/rendercv/rendering.py index 471e2a7..79f5c48 100644 --- a/rendercv/rendering.py +++ b/rendercv/rendering.py @@ -126,6 +126,7 @@ def make_it_bold(value: str, match_str: str) -> str: else: return value + def make_it_underlined(value: str, match_str: str) -> str: """Make the matched parts of the string underlined. @@ -156,6 +157,7 @@ def make_it_underlined(value: str, match_str: str) -> str: else: return value + def make_it_italic(value: str, match_str: str) -> str: """Make the matched parts of the string italic. @@ -186,6 +188,19 @@ def make_it_italic(value: str, match_str: str) -> str: else: return value + +def print_today() -> str: + """Return today's date. + + Returns: + str: Today's date. + """ + from datetime import date + + today = date.today() + return today.strftime("%B %d, %Y") + + def render_template(data): """Render the template using the given data. @@ -226,7 +241,9 @@ def render_template(data): environment.filters["make_it_underlined"] = make_it_underlined environment.filters["make_it_italic"] = make_it_italic - output_latex_file = template.render(design=data.design.options, cv=data.cv) + output_latex_file = template.render( + design=data.design.options, cv=data.cv, today=print_today() + ) # Create an output file and write the rendered LaTeX code to it: output_file_path = os.path.join(os.getcwd(), "tests", "outputs", "test.tex") diff --git a/rendercv/templates/classic.tex.j2 b/rendercv/templates/classic.tex.j2 index d15567c..ba358e1 100644 --- a/rendercv/templates/classic.tex.j2 +++ b/rendercv/templates/classic.tex.j2 @@ -99,7 +99,7 @@ \newcommand{\placelastupdatedtext}{% \placetextbox{}{}{} \AddToShipoutPictureFG*{% Add to current page foreground \put(\LenToUnit{\paperwidth-0.5cm},\LenToUnit{\paperheight-0.5cm}){\vtop{{\null}\makebox[0pt][c]{ - \small\color{gray}\emph{Last updated on \printdayon\today} \hspace{\widthof{Last updated on \printdayon\today}}}}}% + \small\color{gray}\emph{Last updated on <>} \hspace{\widthof{Last updated on <>}}}}}% }% }%