mirror of https://github.com/eyhc1/rendercv.git
prepare the code base for multiple themes
This commit is contained in:
parent
ad45a94e86
commit
6d57b0942d
|
@ -29,9 +29,7 @@ def main(args=sys.argv[1:]):
|
||||||
file_path = os.path.join(os.getcwd(), input_file_path)
|
file_path = os.path.join(os.getcwd(), input_file_path)
|
||||||
data = read_input_file(file_path)
|
data = read_input_file(file_path)
|
||||||
output_latex_file = render_template(data)
|
output_latex_file = render_template(data)
|
||||||
output_pdf_file = run_latex(output_latex_file)
|
run_latex(output_latex_file)
|
||||||
logger.info(f"RenderCV: PDF file generated at {output_pdf_file}")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main(args=["tests/inputs/personal.yaml"])
|
main(args=["tests/inputs/personal.yaml"])
|
||||||
|
|
|
@ -403,7 +403,7 @@ class ClassicThemeOptions(BaseModel):
|
||||||
class Design(BaseModel):
|
class Design(BaseModel):
|
||||||
"""This class stores the theme name of the CV and the theme's options."""
|
"""This class stores the theme name of the CV and the theme's options."""
|
||||||
|
|
||||||
theme: Literal["classic", "awesome-cv"] = Field(
|
theme: Literal["classic"] = Field(
|
||||||
default="classic",
|
default="classic",
|
||||||
title="Theme name",
|
title="Theme name",
|
||||||
description='The only option is "Classic" for now.',
|
description='The only option is "Classic" for now.',
|
||||||
|
@ -426,12 +426,31 @@ class Design(BaseModel):
|
||||||
description="The page size of the CV. It can be a4paper or letterpaper.",
|
description="The page size of the CV. It can be a4paper or letterpaper.",
|
||||||
examples=["a4paper", "letterpaper"],
|
examples=["a4paper", "letterpaper"],
|
||||||
)
|
)
|
||||||
options: ClassicThemeOptions = Field(
|
options: Optional[ClassicThemeOptions] = Field(
|
||||||
default=ClassicThemeOptions(),
|
default=None,
|
||||||
title="Theme Options",
|
title="Theme Options",
|
||||||
description="The options of the theme.",
|
description="The options of the theme.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@model_validator(mode="after")
|
||||||
|
@classmethod
|
||||||
|
def check_theme_options(cls, model):
|
||||||
|
if model.options is None:
|
||||||
|
if model.theme == "classic":
|
||||||
|
model.options = ClassicThemeOptions()
|
||||||
|
else:
|
||||||
|
raise RuntimeError("Unknown theme!")
|
||||||
|
else:
|
||||||
|
if model.theme == "classic":
|
||||||
|
if not isinstance(model.options, ClassicThemeOptions):
|
||||||
|
raise ValueError(
|
||||||
|
"Theme is classic but options is not classic theme options!"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise RuntimeError("Theme is neither classic nor awesome-cv!")
|
||||||
|
|
||||||
|
return model
|
||||||
|
|
||||||
@field_validator("font")
|
@field_validator("font")
|
||||||
@classmethod
|
@classmethod
|
||||||
def check_font(cls, font: str) -> str:
|
def check_font(cls, font: str) -> str:
|
||||||
|
|
|
@ -331,8 +331,8 @@ def render_template(data: RenderCVDataModel, output_path: Optional[str] = None)
|
||||||
file_name = data.cv.name.replace(" ", "_") + "_CV.tex"
|
file_name = data.cv.name.replace(" ", "_") + "_CV.tex"
|
||||||
output_file_path = os.path.join(output_folder, file_name)
|
output_file_path = os.path.join(output_folder, file_name)
|
||||||
os.makedirs(os.path.dirname(output_file_path), exist_ok=True)
|
os.makedirs(os.path.dirname(output_file_path), exist_ok=True)
|
||||||
with open(output_file_path, "w") as file:
|
with open(output_file_path, "wb") as file:
|
||||||
file.write(output_latex_file)
|
file.write(output_latex_file.encode("utf-8"))
|
||||||
|
|
||||||
# Copy the fonts directory to the output directory:
|
# Copy the fonts directory to the output directory:
|
||||||
# Remove the old fonts directory if it exists:
|
# Remove the old fonts directory if it exists:
|
||||||
|
@ -347,6 +347,16 @@ def render_template(data: RenderCVDataModel, output_path: Optional[str] = None)
|
||||||
dirs_exist_ok=True,
|
dirs_exist_ok=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Copy auxiliary files to the output directory (if there is any):
|
||||||
|
output_directory = os.path.dirname(output_file_path)
|
||||||
|
theme_directory = os.path.join(os.path.dirname(__file__), "templates", theme)
|
||||||
|
for file_name in os.listdir(theme_directory):
|
||||||
|
if file_name.endswith(".cls"):
|
||||||
|
shutil.copy(
|
||||||
|
os.path.join(theme_directory, file_name),
|
||||||
|
output_directory,
|
||||||
|
)
|
||||||
|
|
||||||
end_time = time.time()
|
end_time = time.time()
|
||||||
time_taken = end_time - start_time
|
time_taken = end_time - start_time
|
||||||
logger.info(
|
logger.info(
|
||||||
|
|
Loading…
Reference in New Issue