This commit is contained in:
Sina Atalay 2024-02-24 16:17:36 +01:00
parent 1e03cef907
commit cdbbc46b5c
2 changed files with 19 additions and 12 deletions

View File

@ -403,7 +403,7 @@ class LiveProgressReporter(rich.live.Live):
def cli_command_render( def cli_command_render(
input_file_path: Annotated[ input_file_path: Annotated[
str, str,
typer.Argument(help="Name of the YAML input file"), typer.Argument(help="Path to the YAML input file as a string"),
], ],
use_local_latex: bool = typer.Option( use_local_latex: bool = typer.Option(
False, False,
@ -414,7 +414,7 @@ def cli_command_render(
"""Generate a LaTeX CV from a YAML input file. """Generate a LaTeX CV from a YAML input file.
Args: Args:
input_file (str): Name of the YAML input file input_file_path (str): Path to the YAML input file as a string.
""" """
welcome() welcome()
@ -467,8 +467,8 @@ def cli_command_new(full_name: Annotated[str, typer.Argument(help="Your full nam
) )
data_model_as_dictionary = json.loads(data_model_as_json) data_model_as_dictionary = json.loads(data_model_as_json)
yaml = ruamel.yaml.YAML() yaml_object = ruamel.yaml.YAML()
yaml.indent(mapping=2, sequence=4, offset=2) yaml_object.indent(mapping=2, sequence=4, offset=2)
yaml.dump(data_model_as_dictionary, file_path) yaml_object.dump(data_model_as_dictionary, file_path)
information(f"Your RenderCV input file has been created: {file_path}!") information(f"Your RenderCV input file has been created: {file_path}!")

View File

@ -225,12 +225,13 @@ class LaTeXFile(TemplatedFile):
str: The $\\LaTeX$ code. str: The $\\LaTeX$ code.
""" """
preamble, header, sections = self.render_templates() preamble, header, sections = self.render_templates()
return self.get_full_code( latex_code: str = self.get_full_code(
"main.j2.tex", "main.j2.tex",
preamble=preamble, preamble=preamble,
header=header, header=header,
sections=sections, sections=sections,
) )
return latex_code
def generate_latex_file(self, file_path: pathlib.Path): def generate_latex_file(self, file_path: pathlib.Path):
"""Write the $\\LaTeX$ code to a file.""" """Write the $\\LaTeX$ code to a file."""
@ -248,16 +249,16 @@ class MarkdownFile(TemplatedFile):
"""Render and return all the templates for the Markdown file. """Render and return all the templates for the Markdown file.
Returns: Returns:
Tuple[str, List[Tuple[str, List[str]]]]: The header and sections of the Markdown file. tuple[str, List[Tuple[str, List[str]]]]: The header and sections of the Markdown file.
""" """
# Template the header and sections: # Template the header and sections:
header = self.template("Header") header = self.template("Header")
sections = [] sections: list[tuple[str, list[str]]] = []
for section in self.cv.sections: for section in self.cv.sections:
section_beginning = self.template( section_beginning = self.template(
"SectionBeginning", section_title=section.title "SectionBeginning", section_title=section.title
) )
entries = [] entries: list[str] = []
for i, entry in enumerate(section.entries): for i, entry in enumerate(section.entries):
if i == 0: if i == 0:
is_first_entry = True is_first_entry = True
@ -273,7 +274,8 @@ class MarkdownFile(TemplatedFile):
) )
sections.append((section_beginning, entries)) sections.append((section_beginning, entries))
return header, sections result: tuple[str, list[tuple[str, list[str]]]] = (header, sections)
return result
def template( def template(
self, self,
@ -322,13 +324,18 @@ class MarkdownFile(TemplatedFile):
return result return result
def get_markdown_code(self): def get_markdown_code(self):
"""Get the Markdown code of the file.""" """Get the Markdown code of the file.
Returns:
str: The Markdown code.
"""
header, sections = self.render_templates() header, sections = self.render_templates()
return self.get_full_code( markdown_code: str = self.get_full_code(
"main.j2.md", "main.j2.md",
header=header, header=header,
sections=sections, sections=sections,
) )
return markdown_code
def generate_markdown_file(self, file_path: pathlib.Path): def generate_markdown_file(self, file_path: pathlib.Path):
"""Write the Markdown code to a file.""" """Write the Markdown code to a file."""