Skip to content

Commit

Permalink
reposition last updated text
Browse files Browse the repository at this point in the history
  • Loading branch information
sinaatalay committed Oct 8, 2023
1 parent b69c907 commit e4f6cce
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
29 changes: 23 additions & 6 deletions rendercv/rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,19 @@ def make_it_italic(value: str, match_str: str) -> str:
return value


def print_today() -> str:
def divide_length_by(length: str, divider: float) -> str:
# r"""Divide a length by a number.

# Length is a string with the following regex pattern: `\d+\.?\d* *(cm|in|pt|mm|ex|em)`
# """
# Get the value as a float and the unit as a string:
value = re.search(r"\d+\.?\d*", length).group()
unit = re.findall(r"[^\d\.\s]+", length)[0]

return str(float(value) / divider) + " " + unit


def get_today() -> str:
"""Return today's date.
Returns:
Expand Down Expand Up @@ -240,22 +252,23 @@ def render_template(data):
environment.comment_start_string = "((#"
environment.comment_end_string = "#))"

# load the template:
theme = data.design.theme
template = environment.get_template(f"{theme}.tex.j2")

# add custom filters:
environment.filters["markdown_to_latex"] = markdown_to_latex
environment.filters["markdown_url_to_url"] = markdown_url_to_url
environment.filters["make_it_bold"] = make_it_bold
environment.filters["make_it_underlined"] = make_it_underlined
environment.filters["make_it_italic"] = make_it_italic
environment.filters["divide_length_by"] = divide_length_by

# load the template:
theme = data.design.theme
template = environment.get_template(f"{theme}.tex.j2")

output_latex_file = template.render(
cv=data.cv,
design=data.design,
theme_options=data.design.options,
today=print_today(),
today=get_today(),
)

# Create an output file and write the rendered LaTeX code to it:
Expand All @@ -265,6 +278,10 @@ def render_template(data):
file.write(output_latex_file)

# Copy the fonts directory to the output directory:
# Remove the old fonts directory if it exists:
if os.path.exists(os.path.join(os.path.dirname(output_file_path), "fonts")):
shutil.rmtree(os.path.join(os.path.dirname(output_file_path), "fonts"))

font_directory = get_path_to_font_directory(data.design.font)
output_fonts_directory = os.path.join(os.path.dirname(output_file_path), "fonts")
shutil.copytree(
Expand Down
8 changes: 6 additions & 2 deletions rendercv/templates/classic.tex.j2
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@
\newcommand{\placelastupdatedtext}{% \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>}
\AddToShipoutPictureFG*{% Add <stuff> 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 <<today>>} \hspace{\widthof{Last updated on <<today>>}}}}}%
\put(
\LenToUnit{\paperwidth-<<theme_options.margins.page.right>>},
\LenToUnit{\paperheight-<<theme_options.margins.page.top|divide_length_by(2)>>}
){\vtop{{\null}\makebox[0pt][c]{
\small\color{gray}\emph{Last updated on <<today>>} \hspace{\widthof{Last updated on <<today>>}}
}}}%
}%
}%
Expand Down

0 comments on commit e4f6cce

Please sign in to comment.