Skip to content

Commit

Permalink
improve publications section
Browse files Browse the repository at this point in the history
  • Loading branch information
sinaatalay committed Oct 1, 2023
1 parent 74f5116 commit c0b43ff
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 7 deletions.
17 changes: 17 additions & 0 deletions rendercv/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,23 @@ def markdown_url(self) -> Optional[str]:

return markdown_url

@computed_field
@cached_property
def month_and_year(self) -> Optional[str]:
if self.date is not None:
# Then it means start_date and end_date are not provided.
try:
# If this runs, it means the date is an ISO format string, and it can be
# parsed
month_and_year = format_date(Date.fromisoformat(self.date))
except:
month_and_year = self.date
else:
# Then it means start_date and end_date are provided and month_and_year
# doesn't make sense.
month_and_year = None

return month_and_year

class OneLineEntry(Event):
"""This class stores [OneLineEntry](../index.md#onelineentry) information."""
Expand Down
61 changes: 61 additions & 0 deletions rendercv/rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,65 @@ 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.
This function is used as a Jinja2 filter.
Example:
```python
make_it_underlined_if("Hello World!", "Hello")
```
will return:
`#!python "\\underline{Hello} World!"`
Args:
value (str): The string to make underlined.
match_str (str): The string to match.
"""
if not isinstance(value, str):
raise ValueError("make_it_underlined_if should only be used on strings!")

if not isinstance(match_str, str):
raise ValueError("The string to match should be a string!")

if match_str in value:
value = value.replace(match_str, "\\underline{" + match_str + "}")
return value
else:
return value

def make_it_italic(value: str, match_str: str) -> str:
"""Make the matched parts of the string italic.
This function is used as a Jinja2 filter.
Example:
```python
make_it_italic_if("Hello World!", "Hello")
```
will return:
`#!python "\\textit{Hello} World!"`
Args:
value (str): The string to make italic.
match_str (str): The string to match.
"""
if not isinstance(value, str):
raise ValueError("make_it_italic_if should only be used on strings!")

if not isinstance(match_str, str):
raise ValueError("The string to match should be a string!")

if match_str in value:
value = value.replace(match_str, "\\textit{" + match_str + "}")
return value
else:
return value

def render_template(data):
"""Render the template using the given data.
Expand Down Expand Up @@ -164,6 +223,8 @@ def render_template(data):
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

output_latex_file = template.render(design=data.design.options, cv=data.cv)

Expand Down
2 changes: 1 addition & 1 deletion rendercv/templates/classic.tex.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
bottom=<<design.margins.page.bottom>>, % seperation between body and page edge from the bottom
left=<<design.margins.page.left>>, % seperation between body and page edge from the left
right=<<design.margins.page.right>>, % seperation between body and page edge from the right
showframe % for debugging
% showframe % for debugging
]{geometry} % for adjusting page geometry
\usepackage{fontspec} % for loading fonts
\usepackage[explicit]{titlesec} % for customizing section titles
Expand Down
8 changes: 3 additions & 5 deletions rendercv/templates/components/classic/entry.tex.j2
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
\end{tabularx}
((* endmacro *))

((* macro publication(title, authors, journal, year, doi, doi_url)*))
((* macro publication(title, authors, journal, date, doi, doi_url)*))
((# \begin{tabularx}{⟨width⟩}[⟨pos⟩]{⟨preamble⟩} #))
((# width: \textwidth #))
((# preamble: first column, second column #))
Expand All @@ -64,13 +64,11 @@
\begin{tabularx}{\textwidth}{K{<<design.margins.entry_area.left>>} R{2 cm}}
\textbf{<<title>>}

<<authors|join(", ")|make_it_bold("Cetin Yilmaz")>>
<<authors|join(", ")|make_it_italic(cv.name)>>

DOI: \hrefExternal{<<doi_url>>}{<<doi>>}

<<journal>>
&
<<year>>
<<date>>
\end{tabularx}
((* endmacro *))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
title=value.title,
authors=value.authors,
journal=value.journal,
year=value.date,
date=value.month_and_year,
doi=value.doi,
doi_url=value.doi_url,
)|indent(4)>>
Expand Down

0 comments on commit c0b43ff

Please sign in to comment.