Files
rendercv/docs/docs_templating.py
Sina Atalay 5cc5fbdf9e Massive Refactor: Architecture Redesign and Technical Debt Cleanup (#528)
* Rename `data` folder with schema

* Start refactoring data models

* Work on entry models

* Keep working on entries

* Keep working on data models

* Push old data files

* Keep working on data models

* First draft of schema.cv

* Keep working on schema

* Keep working on schema

* Improve schema.models

* Keep working on rendercv.schema

* Work on schema.design

* Keep working on rendercv.schema

* Complete variant_class_generator

* Keep working rendercv.schema

* Keep working on rendercv.schema

* Final touches to rendercv.schema

* Improve json schema descriptions in rendercv.schema

* Start working on rendercv.schema tests

* Keep implementing rendercv.schema tests

* Add more tests for rendercv.schema

* Improve rendercv.schema

* Improve docstrings and comments in rendercv.schema

* Implement better pydantic error handling in `rendercv.schema`

* Improve variant class system

* Fix rendercv.schema tests

* Start working on rendercv.templater

* Update template names

* Switching to new rendercv typst template soon

* Work on new templater

* Rename renderer with renderer_old

* Don't use utils in rendercv.schema

* Complete connections

* Update renderer folder structure

* Work on new renderer

* Work on new renderer

* Date processing on new renderer

* Improve date processing, support multiple emails, phones, and websites

* Improve markdown to Typst

* Complete entry template processing

* Time span computation in new renderer

* Better entry templates

* Setup new templates

* Improve rendercv.schema

* Start adding tests for rendercv.renderer

* New markdown parser!

* Improve markdown to typst conversion

* Finalize markdown parser

* Add new test files for rendercv.renderer

* Fix cv and connections

* Add connections test

* Improve connection tests

* Improve entry templates

* Add model processor tests

* Improve templater

* Rename old folders

* Improve schema

* Add file generation logic to renderer

* Fix naming issues

* Fix schema tests

* Add path type tests

* Add font family and typst dimension type tests

* Rename old tests

* Fix design tests

* Start integration testing of renderer

* Improve entry tempates

* Handle nested highlights properly

* Finalize Typst preamble template

* Start working on new CLI

* Remove old test files

* Implement override dictionary in new schema

* Start working on new CLI

* Better prints on render command

* New structure

* New render printer

* Add all the commands to new CLI

* Work on new command in new cli

* Improve new command

* Add error handler to new cli

* Work on create theme command

* Complete create theme command

* Remove old source files

* Improve exceptions

* Create new docs

* Add writing tests guide

* Fix cli printer and write tests

* Test copy templates

* Add app tests

* Bring back accidentally removed files

* Imporve cli and tests

* Fix path issues

* Improve

* Improve

* Add reference file comparison tests

* Fix path resolver

* Start working on test_pdf_png

* Implement comparison of multiple files (png)

* Start testing typst

* Fix templating issues

* Fix header and entry templates issues

* Implement short second rows

* Fix date issues

* Fix nested bullets and add summary

* Update testdata

* Implement footer

* Update testdata

* Reimagined design and locale schema, first iteration

* Reimagined design and locale second iteration

* Update design and locale schemas

* Adapt templater to the new design and locale

* Fix tests

* Update lib.typ and testdata for the new locale and design

* Implement proper tests with all combinations of entries

* Remove some docstrings

* fix connections logic

* Improve

* Start working on examples

* Update testdata

* Fix long second row issue

* fix templating issues

* Fix lib.typ issues

* Update testdata

* Fix clean_trailing_parts

* Update test cv

* update test cv

* Update theme defaults

* update schema and fix moderncv

* Fix moderncv issues

* Update testdata

* Update testdata and examples

* Fix issues about photo

* Fix typst photo path issues

* improve entry templates from yaml

* add new locale

* Rename writing tests doc

* Update writing tests

* Improve tests

* Add more cli tests

* Increase test coverage

* Rename variant pydantic model generator

* Improve tests

* Update testdata and improve tests

* Format, fix pre-commit errors

* Fix scripts and update entry figures

* Improve tests

* Write docstrings of schema

* Write schema docstrings

* Setup api reference

* Start working on new docs

* Work on docs

* Improve progress panel of render command

* Finalize new docs index

* Complete CLI docs

* Work on YAML input structure page

* Finalize user guide

* Start working on developer guide

* Improve api reference

* Improve developer guide

* Improve developer guide

* Improve developer gide

* Improve developer guide

* Improve developer guide

* Update developer guide

* Improve developer guide

* Improve developer guide

* Improve developer guide

* Developer guide first draft

* update developer guide

* Update examples

* Update testdata

* Handle wrong installation (rendercv instead of rendercv[full])

* Remove unnecessary files

* Write set up vs code page

* Update README.md

* Change docs description

* Compress design options gif

* minor updates

* Polish all the json schema descriptions

* Update testdata and examples

* Remove some emdashed from docs

* Add whatsapp support

* Add TestEscapeTypstCharacters to tests

* Implement custom connections

* Add page break before sections feature

* Revert page break before sections feature

* Rebase to main

* Fix social network tests, update schema
2025-12-09 17:03:56 +03:00

143 lines
4.9 KiB
Python

"""This script generates the example entry figures and creates an environment for
documentation templates using `mkdocs-macros-plugin`. For example, the content of the
example entries found in
"[Structure of the YAML Input File](https://docs.rendercv.com/user_guide/structure_of_the_yaml_input_file/)"
are coming from this script.
"""
import io
import pathlib
from typing import get_args
import pydantic
import ruamel.yaml
from rendercv.schema.models.cv.section import (
BulletEntry,
EducationEntry,
ExperienceEntry,
NormalEntry,
NumberedEntry,
OneLineEntry,
PublicationEntry,
ReversedNumberedEntry,
)
from rendercv.schema.models.cv.social_network import available_social_networks
from rendercv.schema.models.design.built_in_design import available_themes
from rendercv.schema.models.design.classic_theme import (
Alignment,
BodyAlignment,
Bullet,
PageSize,
PhoneNumberFormatType,
SectionTitleType,
)
from rendercv.schema.models.design.font_family import available_font_families
from rendercv.schema.models.locale.locale import available_locales
from rendercv.schema.yaml_reader import read_yaml
repository_root = pathlib.Path(__file__).parent.parent
rendercv_path = repository_root / "src" / "rendercv"
image_assets_directory = pathlib.Path(__file__).parent / "assets" / "images"
class SampleEntries(pydantic.BaseModel):
education_entry: EducationEntry
experience_entry: ExperienceEntry
normal_entry: NormalEntry
publication_entry: PublicationEntry
one_line_entry: OneLineEntry
bullet_entry: BulletEntry
numbered_entry: NumberedEntry
reversed_numbered_entry: ReversedNumberedEntry
text_entry: str
def dictionary_to_yaml(dictionary: dict):
"""Converts a dictionary to a YAML string.
Args:
dictionary: The dictionary to be converted to YAML.
Returns:
The YAML string.
"""
yaml_object = ruamel.yaml.YAML()
yaml_object.width = 60
yaml_object.indent(mapping=2, sequence=4, offset=2)
with io.StringIO() as string_stream:
yaml_object.dump(dictionary, string_stream)
return string_stream.getvalue()
def define_env(env):
# See https://mkdocs-macros-plugin.readthedocs.io/en/latest/macros/
sample_entries = read_yaml(
repository_root / "docs" / "user_guide" / "sample_entries.yaml"
)
# validate the parsed dictionary by creating an instance of SampleEntries:
sample_entries = SampleEntries(**sample_entries).model_dump()
entries_showcase = {}
for entry_name, entry in sample_entries.items():
proper_entry_name = entry_name.replace("_", " ").title().replace(" ", "")
entries_showcase[proper_entry_name] = {
"yaml": dictionary_to_yaml(entry),
"figures": [
{
"path": f"../assets/images/{theme}/{entry_name}.png",
"alt_text": f"{proper_entry_name} in {theme}",
"theme": theme,
}
for theme in available_themes
],
}
env.variables["sample_entries"] = entries_showcase
env.variables["entry_count"] = len(sample_entries)
env.variables["entry_names"] = [
f"[{entry_name}](#{entry_name.lower()})" for entry_name in entries_showcase
]
# Available themes strings (put available themes between ``)
themes = [f"`{theme}`" for theme in available_themes]
env.variables["available_themes"] = ", ".join(themes)
# Available locales string
locales = [f"`{locale}`" for locale in available_locales]
env.variables["available_locales"] = ", ".join(locales)
# Available social networks strings (put available social networks between ``)
social_networks = [
f"`{social_network}`" for social_network in available_social_networks
]
env.variables["available_social_networks"] = ", ".join(social_networks)
# Others:
env.variables["available_page_sizes"] = ", ".join(
[f"`{page_size}`" for page_size in get_args(PageSize.__value__)]
)
env.variables["available_font_families"] = ", ".join(
[f"`{font_family}`" for font_family in available_font_families]
)
env.variables["available_body_alignments"] = ", ".join(
[f"`{text_alignment}`" for text_alignment in get_args(BodyAlignment.__value__)]
)
env.variables["available_phone_number_formats"] = ", ".join(
[
f"`{phone_number_format}`"
for phone_number_format in get_args(PhoneNumberFormatType.__value__)
]
)
env.variables["available_alignments"] = ", ".join(
[f"`{alignment}`" for alignment in get_args(Alignment.__value__)]
)
env.variables["available_section_title_types"] = ", ".join(
[
f"`{section_title_type}`"
for section_title_type in get_args(SectionTitleType.__value__)
]
)
env.variables["available_bullets"] = ", ".join(
[f"`{bullet}`" for bullet in get_args(Bullet.__value__)]
)