Files
rendercv/docs/update_examples.py
Sina Atalay 4331110c55 Upgrade to v2 (#271)
* prepare the base for typst

* rename theme folders

* rename themes

* rename themes

* update testdata with new theme names

* rename themes

* fix docs issues

* fundamentals

* fundamental renames

* generalize `create_a_latex_file`

* generalize render_a_pdf_from_latex

* make latex optional dependency, and add typst as dependency

* first tests with typst

* finish `markdown_to_typst`

* fix `markdown_to_latex`

* finish `markdown_to_typst`

* first steps towards Typst RenderCV themes

* first draft of classic theme

* start working on new design options

* work on new design options

* make default theme: "classic"

* start integrating design options with templates

* rename typst variables

* start working on connections integration

* polish connections

* polish design options and themes

* fix spelling mistakes and improve typst themes

* use ms instead of s in printer

* improve templates

* fix typos

* use ms instead of s in printer

* improve typst templates

* improve

* improve

* improve

* improve

* make PyMuPDF optional

* rename last_updated_date_style to last_updated_date_template

* revert changelog

* progress

* improve

* exclude gifs from sdist

* update tests

* improve templates

* improve templater

* data: update `sample_content.yaml`

* improve

* remove latex support

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* remove testdata

* remove latex

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* rename `locale_catalog` to `locale`

* docs: update developer guide faq

* add new input, rendercv_settings.date

* add show_time_span_in

* create a new function, parse_validation_errors

* improve templates

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* improve

* update templates

* fix experience entry

* improve

* finish templates

* update tests

* update testdata

* remove time_machine

* update sample content

* improve

* add sb2nov theme

* update options

* update theme.options

* update theme.options

* update theme options

* create engineeringresumes templates

* add engineering resumes

* format

* update templates

* add new theme

* fix a typo in sample content

* update templating system

* update options

* add photo support

* update workflows

* improve templates

* improve parse_validation_errors

* create a new interface for web

* fix summary

* improve

* resolve typing issues

* update mkdocs.yaml

* update pyproject.toml

* update docs scripts

* update testdata

* update tests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* rename column template fields

* update

* update test data

* add moderncv

* fix problems

* moderncv

* create moderncv

* fix tests

* update

* update

* update templates

* update

* use optional dependencies

* fix

* improve

* aa

* a

* update

* update

* update

* update

* rename

* update

* update

* update

* improve

* update

* update

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* update

* update

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* format

* update changelog

* update examples

* update entry figures

* update schema

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-01-07 01:30:40 +03:00

87 lines
2.8 KiB
Python

"""This script generates the `examples` folder in the repository root."""
import os
import pathlib
import shutil
import rendercv.cli as cli
import rendercv.data as data
import rendercv.renderer as renderer
repository_root = pathlib.Path(__file__).parent.parent
rendercv_path = repository_root / "rendercv"
image_assets_directory = pathlib.Path(__file__).parent / "assets" / "images"
def generate_examples():
"""Generate example YAML and PDF files."""
examples_directory_path = pathlib.Path(__file__).parent.parent / "examples"
# Check if examples directory exists. If not, create it
if not examples_directory_path.exists():
examples_directory_path.mkdir()
os.chdir(examples_directory_path)
themes = data.available_themes
for theme in themes:
cli.cli_command_new(
"John Doe",
theme,
dont_create_theme_source_files=True,
dont_create_markdown_source_files=True,
)
yaml_file_path = examples_directory_path / "John_Doe_CV.yaml"
# Rename John_Doe_CV.yaml
proper_theme_name = theme.capitalize() + "Theme"
new_yaml_file_path = (
examples_directory_path / f"John_Doe_{proper_theme_name}_CV.yaml"
)
if new_yaml_file_path.exists():
new_yaml_file_path.unlink()
yaml_file_path.rename(new_yaml_file_path)
yaml_file_path = new_yaml_file_path
# Generate PDF file
cli.cli_command_render(yaml_file_path)
output_pdf_file = (
examples_directory_path / "rendercv_output" / "John_Doe_CV.pdf"
)
output_typst_file = (
examples_directory_path / "rendercv_output" / "John_Doe_CV.typ"
)
# Move PDF file to examples directory
new_pdf_file_path = examples_directory_path / f"{yaml_file_path.stem}.pdf"
if new_pdf_file_path.exists():
new_pdf_file_path.unlink()
output_pdf_file.rename(new_pdf_file_path)
# Convert first page of PDF to image
png_file_paths = renderer.render_pngs_from_typst(output_typst_file)
firt_page_png_file_path = png_file_paths[0]
if len(png_file_paths) > 1:
# Remove other pages
for png_file_path in png_file_paths[1:]:
png_file_path.unlink()
desired_png_file_path = image_assets_directory / f"{theme}.png"
# If image exists, remove it
if desired_png_file_path.exists():
desired_png_file_path.unlink()
# Move image to desired location
firt_page_png_file_path.rename(desired_png_file_path)
# Remove rendercv_output directory
rendercv_output_directory = examples_directory_path / "rendercv_output"
shutil.rmtree(rendercv_output_directory)
if __name__ == "__main__":
generate_examples()
print("Examples generated successfully.") # NOQA: T201