diff --git a/.github/workflows/deploy-docs.yaml b/.github/workflows/deploy-docs.yaml index 1b961b2..e484ecd 100644 --- a/.github/workflows/deploy-docs.yaml +++ b/.github/workflows/deploy-docs.yaml @@ -1,25 +1,38 @@ name: Deploy documentation + +# GitHub events that triggers the workflow: on: push: - branches: - - main + branches: ["main"] + pull_request: + branches: ["main"] + permissions: contents: write jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 with: - python-version: 3.11 - - run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV - - uses: actions/cache@v3 + python-version: ${{ matrix.python-version }} + + - name: Store cache ID + run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV + + - name: Create a key + uses: actions/cache@v4 with: key: mkdocs-material-${{ env.cache_id }} path: .cache restore-keys: | mkdocs-material- - - run: pip install mkdocs-material - - run: pip install mkdocstrings-python - - run: mkdocs gh-deploy --force + + - name: Deploy documentation + run: | + pip install mkdocs-material + pip install mkdocstrings-python + mkdocs gh-deploy --force diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..92128df --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,39 @@ +name: Publish to PyPI + +# GitHub events that triggers the workflow: +on: + release: + types: [released] + +jobs: + call_ci_workflow: + name: Continuous integration + uses: ./.github/workflows/ci.yaml + + publish: + name: Publish to PyPI + runs-on: ubuntu-latest + environment: release + + permissions: + id-token: write + + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.12 + uses: actions/setup-python@v4 + with: + python-version: "3.12" + + - name: Check if the release tag matches the version + uses: samuelcolvin/check-python-version@v4.1 + with: + version_file_path: rendercv/__init__.py + + - name: Build + run: | + pip install -U build + python -m build + + - name: Upload package to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/ci.yaml b/.github/workflows/test.yaml similarity index 68% rename from .github/workflows/ci.yaml rename to .github/workflows/test.yaml index bf51abe..7ce48de 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/test.yaml @@ -1,17 +1,18 @@ -name: CI +name: Test and report coverage +# GitHub events that triggers the workflow: on: push: - branches: ["main"] + branches: ["main", "dev", "v1"] pull_request: - branches: ["main"] - release: - types: ["published"] + branches: ["main", "dev", "v1"] + workflow_call: +# The workflow: jobs: lint: - runs-on: ubuntu-latest name: Lint with Ruff (Py${{ matrix.python-version }}) + runs-on: ubuntu-latest strategy: fail-fast: false matrix: @@ -42,6 +43,8 @@ jobs: runs-on: ${{ matrix.os }}-latest steps: - uses: actions/checkout@v4 + with: + submodules: recursive - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 @@ -52,15 +55,12 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install pytest - pip install . + pip install .[tests] - name: Test with pytest run: | - pip install pytest pytest-cov - touch .coveragerc - echo "[run]" > .coveragerc - echo "relative_files = True" >> .coveragerc - pytest --cov="rendercv" tests/ + pip install pytest coverage + coverage run -m pytest tests/ mv .coverage .coverage.${{ matrix.python-version }}.${{ matrix.os }} - name: Store coverage files @@ -70,8 +70,7 @@ jobs: path: .coverage.${{ matrix.python-version }}.${{ matrix.os }} report-coverage: - if: github.event_name == 'push' - name: Generate a coverage report + name: Generate the coverage report needs: [test] runs-on: ubuntu-latest @@ -92,45 +91,16 @@ jobs: - name: Combine coverage files run: | pip install coverage - ls -la coverage - touch .coveragerc - echo "[run]" > .coveragerc - echo "relative_files = True" >> .coveragerc coverage combine coverage coverage report coverage html --show-contexts --title "RenderCV coverage for ${{ github.sha }}" - - name: Upload coverage data to smokeshow + - name: Upload the coverage report to smokeshow run: | pip install smokeshow smokeshow upload ./htmlcov env: SMOKESHOW_GITHUB_STATUS_DESCRIPTION: Coverage {coverage-percentage} - SMOKESHOW_GITHUB_COVERAGE_THRESHOLD: 50 + SMOKESHOW_GITHUB_COVERAGE_THRESHOLD: 97 SMOKESHOW_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SMOKESHOW_GITHUB_PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} - - publish: - if: github.event_name == 'release' - name: Publish to PyPI - needs: [test] - runs-on: ubuntu-latest - environment: release - - permissions: - id-token: write - - steps: - - uses: actions/checkout@v4 - - name: Set up Python 3.12 - uses: actions/setup-python@v4 - with: - python-version: "3.12" - - - name: Build - run: | - pip install -U build - python -m build - - - name: Upload package to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.gitignore b/.gitignore index 1c720ed..7a171dc 100644 --- a/.gitignore +++ b/.gitignore @@ -170,25 +170,21 @@ cython_debug/ *.synctex.gz *.pdf -# TinyTeX cache -rendercv/vendor/TinyTeX/texmf-var/tex/generic/ -rendercv/vendor/TinyTeX/texmf-var/luatex-cache/ - -# RenderCV related -tests/outputs/ -tests/inputs/personal.json -tests/inputs/personal.yaml -personal.yaml -output/ - # VSCode .vscode/ # Personal CVs -Sina_Atalay_CV.yaml -run_sina_atalay_cv.py +*_CV.yaml +*_cv.py +*_CV.tex +rendercv_output/ -# Jeffrey Goldbergs local stuff -# We can remove these once work by him is finished -Jeffrey_Paul_Goldberg_CV.yaml -pyvenv.cfg +# Include reference files +!/tests/auxiliary_files/**/*.pdf +!/tests/auxiliary_files/**/*.tex +!/tests/auxiliary_files/**/*.md +!/tests/auxiliary_files/**/*.html + +# Include example files +!/examples/*.pdf +!/examples/*.yaml \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..c647d5a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "rendercv/tinytex-release"] + path = rendercv/tinytex-release + url = git@github.com:sinaatalay/tinytex-release.git diff --git a/John_Doe_CV.pdf b/John_Doe_CV.pdf deleted file mode 100644 index fb6425f..0000000 Binary files a/John_Doe_CV.pdf and /dev/null differ diff --git a/John_Doe_CV.yaml b/John_Doe_CV.yaml deleted file mode 100644 index fc409c6..0000000 --- a/John_Doe_CV.yaml +++ /dev/null @@ -1,218 +0,0 @@ -cv: - name: John Doe - label: Mechanical Engineer - location: TX, USA - email: johndoe@example.com - phone: "+33749882538" - website: https://example.com - social_networks: - - network: GitHub - username: johndoe - - network: LinkedIn - username: johndoe - summary: - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque porta - vitae dolor vel placerat. Class aptent taciti sociosqu ad litora torquent per conubia - nostra, per inceptos himenaeos. Phasellus ullamcorper, neque id varius dignissim, - tellus sem maximus risus, at lobortis nisl sem id ligula. - section_order: - - Education - - Work Experience - - Academic Projects - - Certificates - - Personal Projects - - Skills - - Test Scores - - Extracurricular Activities - - Publications - - My Custom Section - - My Other Custom Section - - My Third Custom Section - - My Final Custom Section - education: - - institution: My University - url: https://boun.edu.tr - area: Mechanical Engineering - study_type: BS - location: Ankara, Türkiye - start_date: "2017-09-01" - end_date: "2023-01-01" - transcript_url: https://example.com - gpa: 3.99/4.00 - highlights: - - "Class rank: 1 of 62" - - institution: The University of Texas at Austin - url: https://utexas.edu - area: Mechanical Engineering, Student Exchange Program - location: Austin, TX, USA - start_date: "2021-08-01" - end_date: "2022-01-15" - transcript_url: https://example.com - gpa: 4.00/4.00 - work_experience: - - company: CERN - position: Mechanical Engineer - location: Geneva, Switzerland - url: https://home.cern - start_date: "2023-02-01" - end_date: present - highlights: - - CERN is a research organization that operates the world's largest and most - powerful particle accelerator. - - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor - incididunt ut labore et dolore magna aliqua. - - Id leo in vitae turpis massa sed, posuere aliquam ultrices sagittis orci a - scelerisque, lorem ipsum dolor sit amet. - - company: AmIACompany - position: Summer Intern - location: Istanbul, Türkiye - url: https://example.com - start_date: "2022-06-15" - end_date: "2022-08-01" - highlights: - - AmIACompany is a technology company that provides web-based engineering - applications that enable the simulation and optimization of products and - manufacturing tools. - - Modeled and simulated a metal-forming process deep drawing using finite element - analysis with open-source software called CalculiX. - academic_projects: - - name: Design and Construction of a Robot - location: Istanbul, Türkiye - date: Fall 2022 - highlights: - - Designed and constructed a controllable robot that measures a car's torque and - power output at different speeds for my senior design project. - url: https://example.com - - name: Design and Construction of an Another Robot - location: Istanbul, Türkiye - date: Fall 2020 - highlights: - - Designed, built, and programmed a microcontroller-based device that plays a - guitar with DC motors as part of a mechatronics course term project. - url: https://example.com - publications: - - title: Phononic band gaps induced by inertial amplification in periodic media - authors: - - Author 1 - - John Doe - - Author 3 - journal: Physical Review B - doi: 10.1103/PhysRevB.76.054309 - date: "2007-08-01" - cited_by: 243 - certificates: - - name: Machine Learning by Stanford University - date: "2022-09-01" - url: https://example.com - skills: - - name: Programming - details: C++, C, Python, JavaScript, MATLAB, Lua, LaTeX - - name: OS - details: Windows, Ubuntu - - name: Other tools - details: Git, Premake, HTML, CSS, React - - name: Languages - details: English (Advanced), French (Lower Intermediate), Turkish (Native) - test_scores: - - name: TOEFL - date: "2022-10-01" - details: - "113/120 — Reading: 29/30, Listening: 30/30, Speaking: 27/30, Writing: - 27/30" - url: https://example.com - - name: GRE - details: "Verbal Reasoning: 160/170, Quantitative Reasoning: 170/170, Analytical - Writing: 5.5/6" - url: https://example.com - personal_projects: - - name: Ray Tracing in C++ - date: Spring 2021 - highlights: - - Coded a ray tracer in C++ that can render scenes with multiple light sources, - spheres, and planes with reflection and refraction properties. - url: https://example.com - extracurricular_activities: - - company: Dumanlikiz Skiing Club - position: Co-founder / Skiing Instructor - location: Chamonix, France - date: Summer 2017 and 2018 - highlights: - - Taught skiing during winters as a certified skiing instructor. - custom_sections: - - title: My Custom Section - entry_type: OneLineEntry - entries: - - name: Testing custom sections - details: Wohooo! - - name: This is a - details: OneLineEntry! - - title: My Other Custom Section - entry_type: EducationEntry - entries: - - institution: Hop! - area: Hop! - study_type: HA - highlights: - - "There are only five types of entries: *EducationEntry*, *ExperienceEntry*, - *NormalEntry*, *OneLineEntry*, and *PublicationEntry*." - - This is an EducationEntry! - start_date: "2022-06-15" - end_date: "2022-08-01" - - title: My Third Custom Section - entry_type: ExperienceEntry - entries: - - company: Hop! - position: Hop! - date: My Date - location: My Location - highlights: - - I think this is really working. This is an *ExperienceEntry*! - - - title: My Final Custom Section - entry_type: NormalEntry - link_text: My Link Text - entries: - - name: This is a normal entry! - url: https://example.com - highlights: - - You don't have to specify a *date* or **location** every time. - - You can use *Markdown* in the **highlights**! - - "Special characters test: üğç" - -design: - theme: classic - font: SourceSans3 - font_size: 10pt - page_size: a4paper - options: - primary_color: rgb(0,79,144) - date_and_location_width: 3.6 cm - show_timespan_in: - - Work Experience - - My Other Custom Section - show_last_updated_date: True - text_alignment: justified - header_font_size: 30 pt - - margins: - page: - top: 2 cm - bottom: 2 cm - left: 1.24 cm - right: 1.24 cm - section_title: - top: 0.2 cm - bottom: 0.2 cm - - entry_area: - left_and_right: 0.2 cm - vertical_between: 0.2 cm - - highlights_area: - top: 0.10 cm - left: 0.4 cm - vertical_between_bullet_points: 0.10 cm - - header: - vertical_between_name_and_connections: 0.2 cm - bottom: 0.2 cm \ No newline at end of file diff --git a/README.md b/README.md index 769b972..84d9d6d 100644 --- a/README.md +++ b/README.md @@ -1,92 +1,131 @@ # RenderCV -[![CI](https://github.com/sinaatalay/rendercv/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/sinaatalay/rendercv/actions/workflows/ci.yaml) + +[![test](https://github.com/sinaatalay/rendercv/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/sinaatalay/rendercv/actions/workflows/test.yaml) [![coverage](https://coverage-badge.samuelcolvin.workers.dev/sinaatalay/rendercv.svg)](https://coverage-badge.samuelcolvin.workers.dev/redirect/sinaatalay/rendercv) + [![pypi-version](https://img.shields.io/pypi/v/rendercv?label=PyPI%20version&color=rgb(0%2C79%2C144))](https://pypi.python.org/pypi/rendercv) [![pypi-downloads](https://img.shields.io/pepy/dt/rendercv?label=PyPI%20downloads&color=rgb(0%2C%2079%2C%20144))](https://pypi.python.org/pypi/rendercv) -RenderCV is a Python application that creates a $\LaTeX$ CV as a PDF from a JSON/YAML input file. Currently, it only supports one theme (*classic*). An example PDF can be seen [here](https://github.com/sinaatalay/rendercv/blob/main/John_Doe_CV.pdf?raw=true). More themes are planned to be supported in the future. +RenderCV is a $\LaTeX$ CV/resume generator from a JSON/YAML input file. It is a $\LaTeX$ framework that can be used with any $\LaTeX$ CV. The primary motivation behind the RenderCV is to allow the separation between the content and design of a CV. -**What does it do?** +Write your content, and get a high-quality, professional-looking CV as a PDF with its $\LaTeX$ source! + +It takes a YAML file that looks like this: -- It parses a YAML (or JSON) file that looks like this: ```yaml cv: name: John Doe - label: Mechanical Engineer - location: Geneva, Switzerland - email: johndoe@example.com - phone: "+33749882538" - website: https://example.com + location: Your Location + email: youremail@yourdomain.com + phone: tel:+90-541-999-99-99 + website: https://yourwebsite.com/ social_networks: - - network: GitHub - username: johndoe - network: LinkedIn - username: johndoe - education: - - institution: My University - url: https://example.com - area: Mechanical Engineering - study_type: BS - location: Geneva, Switzerland - start_date: "2017-09-01" - end_date: "2023-01-01" - transcript_url: https://example.com - gpa: 3.10/4.00 - highlights: - - "Class rank: 10 of 62" - - institution: The University of Texas at Austin - url: https://utexas.edu - area: Mechanical Engineering, Student Exchange Program - location: Austin, TX, USA - start_date: "2021-08-01" - end_date: "2022-01-15" - work_experience: - - company: AmIACompany - position: Summer Intern - location: Istanbul, Turkey - url: https://example.com - start_date: "2022-06-15" - end_date: "2022-08-01" - highlights: - - AmIACompany is a **technology** (markdown is - supported) company that provides web-based - engineering applications that enable the - simulation and optimization of products and - manufacturing tools. - - Modeled and simulated a metal-forming process deep - drawing using finite element analysis with - open-source software called CalculiX. + username: yourusername + - network: GitHub + username: yourusername + sections: + summary: + - This is an example resume to showcase the capabilities + of the open-source LaTeX CV generator, [RenderCV](https://github.com/sinaatalay/rendercv). + A substantial part of the content is taken from [here](https://www.careercup.com/resume), + where a *clean and tidy CV* pattern is proposed by **Gayle + L. McDowell**. + education: + - start_date: 2000-09 + end_date: 2005-05 + highlights: + - 'GPA: 3.9/4.0 ([Transcript](https://example.com))' + - '**Coursework:** Software Foundations, Computer Architecture, + Algorithms, Artificial Intelligence, Comparison of + Learning Algorithms, Computational Theory.' + institution: University of Pennsylvania + area: Computer Science + degree: BS + employment: + ... ``` -- Then, it validates the input, such as checking if the dates are consistent, checking if the URLs are correct, etc. -- Then, it creates a $\LaTeX$ file. -- Finally, it renders the $\LaTeX$ file to generate the PDF, and you don't need $\LaTeX$ installed on your PC because RenderCV comes with [TinyTeX](https://yihui.org/tinytex/). -![RenderCV example](docs/images/example.png) +And then produces these PDFs and their $\LaTeX$ code (click on images to preview PDFs): + +| `classic` theme | `sb2nov` theme | `moderncv` theme | +|:---------------:|----------------|------------------| +|[![Classic Theme Example of RenderCV](https://raw.githubusercontent.com/sinaatalay/rendercv/main/docs/assets/images/classic.png)](https://raw.githubusercontent.com/sinaatalay/rendercv/main/examples/John_Doe_ClassicTheme_CV.pdf)|[![Sb2nov Theme Example of RenderCV](https://raw.githubusercontent.com/sinaatalay/rendercv/main/docs/assets/images/sb2nov.png)](https://raw.githubusercontent.com/sinaatalay/rendercv/main/examples/John_Doe_Sb2novTheme_CV.pdf)|[![Moderncv Theme Example of RenderCV](https://raw.githubusercontent.com/sinaatalay/rendercv/main/docs/assets/images/moderncv.png)](https://raw.githubusercontent.com/sinaatalay/rendercv/main/examples/John_Doe_ModerncvTheme_CV.pdf)| + + +It also generates an HTML file so that the content can be pasted into Grammarly for spell-checking: + +![Grammarly for RenderCV](https://raw.githubusercontent.com/sinaatalay/rendercv/main/docs/assets/images/grammarly.gif) + +RenderCV also validates the input file, and if there are any problems, it tells users where the issues are and how they can fix them: + +![CLI of RenderCV](https://raw.githubusercontent.com/sinaatalay/rendercv/main/docs/assets/images/cli.gif) ## Quick Start Guide +> RenderCV doesn't require a $\LaTeX$ installation; it comes with it! + 1. Install [Python](https://www.python.org/downloads/) (3.10 or newer). 2. Run the command below to install RenderCV. ```bash pip install rendercv ``` -3. Run the command below to generate a sample input file (`Full_Name_CV.yaml`). The file will be generated in the current working directory. +3. Run the command below to generate a starting input file (`Full_Name_CV.yaml`). ```bash rendercv new "Full Name" ``` -4. Edit the contents of the `Full_Name_CV.yaml` file. +4. Edit the contents of `Full_Name_CV.yaml` in your favorite editor (*tip: use an editor that supports JSON Schemas*). 5. Run the command below to generate your $\LaTeX$ CV. ```bash rendercv render Full_Name_CV.yaml ``` -## Detailed User Guide and Documentation +You can find a comprehensive user guide that covers adding custom themes and the data model (YAML structure) in greater detail [here](https://sinaatalay.github.io/rendercv/user_guide). -A more detailed user guide can be found [here](https://sinaatalay.github.io/rendercv/user_guide). +## Motivation -I documented the whole code with docstrings and used comments throughout the code. The API reference can be found [here](https://sinaatalay.github.io/rendercv/api_reference/). +Writing the content of a CV and designing a CV are separate issues, and they should be treated separately. RenderCV attempts to provide this separation and encourages users not to worry too much about the appearance of their CV but to concentrate on the content. + +You can automatize your CV generation process with RenderCV and version control your CV in a well-structured manner. It will make updating your CV as simple as updating your YAML input file. + +Here are some answers to frequently asked questions about RenderCV: + +### Why should I bother using RenderCV instead of $\LaTeX$? I can version-control $\LaTeX$ code too! + +Because: + +- You might want to version control the content and design of your CV separately without mixing them into each other. You cannot achieve this with $\LaTeX$. If you have a plain $\LaTeX$ CV, changing your design will require you to do almost everything from scratch. +- If you return to your $\LaTeX$ CV code after a year, you may find yourself confused about all the commands like `\hpace{1cm}` you put in a year ago everywhere to make your CV work, and it may not be appealing to update your CV anymore. Why not separate $\LaTeX$ code from your content? +- You will have a lot of code duplication if you make your CV in $\LaTeX$ because a CV is a list of sections with lists of entries. Why not have only one $\LaTeX$ code for each entry type and let another software duplicate them for you? +- RenderCV is not a replacement for $\LaTeX$ in the context of CVs but a tool that allows you to create $\LaTeX$ CVs seamlessly. You can always move your $\LaTeX$ CV to RenderCV! +- Spell checking may be difficult to do in $\LaTeX$. You will need to copy and paste each sentence separately to some other software for spell-checking. With RenderCV, it's one copy-paste. +- It is not very easy to use $\LaTeX$ for CVs since they require a unique design. + +### Is it flexible enough? + +RenderCV gives you the flexibility required for a CV, but not more. RenderCV will force users to be strict about the content of their CVs, and that's helpful! Because CVs are strict documents, and you may not want to go in the wrong direction. You can't make design mistakes with RenderCV, but you can be flexible enough. It supports Markdown syntax, so you can put links anywhere or make your text italic or bold. Additionally, you can specify various design options in your input file's `design` section. + +### Isn't putting all of my data into a YAML file cumbersome? + +You always have to put all of your data somewhere to produce a PDF with all your data. If you do it for RenderCV once, you may not have to do it again for a long time. It will help you to avoid this process in the future. + +## Documentation + +The source code of RenderCV is well-commented and documented. Reading the source code might be fun as the software structure is explained with docstrings and comments. + +A detailed user guide can be found [here](https://sinaatalay.github.io/rendercv/user_guide). + +Reference to the code can be found [here](https://sinaatalay.github.io/rendercv/reference). + +The changelog can be found [here](https://sinaatalay.github.io/rendercv/user_guide). ## Contributing -All contributions to RenderCV are welcome, especially adding new $\LaTeX$ themes. +All contributions to RenderCV are welcome! For development, you will need to clone the repository recursively, as TinyTeX is being used as a submodule: + +```bash +git clone --recursive https://github.com/sinaatalay/rendercv.git +``` + +All code and development tool specifications are in `pyproject.toml`. \ No newline at end of file diff --git a/docs/api_reference/__main__.md b/docs/api_reference/__main__.md deleted file mode 100644 index e8073f9..0000000 --- a/docs/api_reference/__main__.md +++ /dev/null @@ -1,3 +0,0 @@ -# __main___ - -::: rendercv.__main__ \ No newline at end of file diff --git a/docs/api_reference/data_model.md b/docs/api_reference/data_model.md deleted file mode 100644 index 97a2927..0000000 --- a/docs/api_reference/data_model.md +++ /dev/null @@ -1,3 +0,0 @@ -# Data Model - -::: rendercv.data_model \ No newline at end of file diff --git a/docs/api_reference/index.md b/docs/api_reference/index.md deleted file mode 100644 index a6e1dac..0000000 --- a/docs/api_reference/index.md +++ /dev/null @@ -1,11 +0,0 @@ -# RenderCV - -::: rendercv - -In this section, you can find how RenderCV works in detail. - -Modules: - -- [\_\_main\_\_](__main__.md) – This module contains the main functions of RenderCV. -- [data_model](data_model.md) – This module contains classes and functions to parse RenderCV's specifically structured YAML or JSON to generate meaningful data for Python. -- [rendering](rendering.md) – This module implements $\LaTeX$ file generation and $\LaTeX$ runner utilities for RenderCV. \ No newline at end of file diff --git a/docs/api_reference/rendering.md b/docs/api_reference/rendering.md deleted file mode 100644 index a3e4769..0000000 --- a/docs/api_reference/rendering.md +++ /dev/null @@ -1,3 +0,0 @@ -# Rendering - -::: rendercv.rendering \ No newline at end of file diff --git a/docs/assets/images/classic.png b/docs/assets/images/classic.png new file mode 100644 index 0000000..a3db102 Binary files /dev/null and b/docs/assets/images/classic.png differ diff --git a/docs/assets/images/classic/education_entry.png b/docs/assets/images/classic/education_entry.png new file mode 100644 index 0000000..59df2aa Binary files /dev/null and b/docs/assets/images/classic/education_entry.png differ diff --git a/docs/assets/images/classic/experience_entry.png b/docs/assets/images/classic/experience_entry.png new file mode 100644 index 0000000..a3b4554 Binary files /dev/null and b/docs/assets/images/classic/experience_entry.png differ diff --git a/docs/assets/images/classic/normal_entry.png b/docs/assets/images/classic/normal_entry.png new file mode 100644 index 0000000..77e10f5 Binary files /dev/null and b/docs/assets/images/classic/normal_entry.png differ diff --git a/docs/assets/images/classic/one_line_entry.png b/docs/assets/images/classic/one_line_entry.png new file mode 100644 index 0000000..631c3ad Binary files /dev/null and b/docs/assets/images/classic/one_line_entry.png differ diff --git a/docs/assets/images/classic/publication_entry.png b/docs/assets/images/classic/publication_entry.png new file mode 100644 index 0000000..b12cc73 Binary files /dev/null and b/docs/assets/images/classic/publication_entry.png differ diff --git a/docs/assets/images/classic/text_entry.png b/docs/assets/images/classic/text_entry.png new file mode 100644 index 0000000..09314cd Binary files /dev/null and b/docs/assets/images/classic/text_entry.png differ diff --git a/docs/assets/images/moderncv.png b/docs/assets/images/moderncv.png new file mode 100644 index 0000000..4a0c731 Binary files /dev/null and b/docs/assets/images/moderncv.png differ diff --git a/docs/assets/images/moderncv/education_entry.png b/docs/assets/images/moderncv/education_entry.png new file mode 100644 index 0000000..6b56af9 Binary files /dev/null and b/docs/assets/images/moderncv/education_entry.png differ diff --git a/docs/assets/images/moderncv/experience_entry.png b/docs/assets/images/moderncv/experience_entry.png new file mode 100644 index 0000000..b3f1fee Binary files /dev/null and b/docs/assets/images/moderncv/experience_entry.png differ diff --git a/docs/assets/images/moderncv/normal_entry.png b/docs/assets/images/moderncv/normal_entry.png new file mode 100644 index 0000000..771e156 Binary files /dev/null and b/docs/assets/images/moderncv/normal_entry.png differ diff --git a/docs/assets/images/moderncv/one_line_entry.png b/docs/assets/images/moderncv/one_line_entry.png new file mode 100644 index 0000000..2f0a30d Binary files /dev/null and b/docs/assets/images/moderncv/one_line_entry.png differ diff --git a/docs/assets/images/moderncv/publication_entry.png b/docs/assets/images/moderncv/publication_entry.png new file mode 100644 index 0000000..0b991f4 Binary files /dev/null and b/docs/assets/images/moderncv/publication_entry.png differ diff --git a/docs/assets/images/moderncv/text_entry.png b/docs/assets/images/moderncv/text_entry.png new file mode 100644 index 0000000..dce6e79 Binary files /dev/null and b/docs/assets/images/moderncv/text_entry.png differ diff --git a/docs/assets/images/sb2nov.png b/docs/assets/images/sb2nov.png new file mode 100644 index 0000000..d631607 Binary files /dev/null and b/docs/assets/images/sb2nov.png differ diff --git a/docs/assets/images/sb2nov/education_entry.png b/docs/assets/images/sb2nov/education_entry.png new file mode 100644 index 0000000..944cdaa Binary files /dev/null and b/docs/assets/images/sb2nov/education_entry.png differ diff --git a/docs/assets/images/sb2nov/experience_entry.png b/docs/assets/images/sb2nov/experience_entry.png new file mode 100644 index 0000000..f2ea840 Binary files /dev/null and b/docs/assets/images/sb2nov/experience_entry.png differ diff --git a/docs/assets/images/sb2nov/normal_entry.png b/docs/assets/images/sb2nov/normal_entry.png new file mode 100644 index 0000000..129d7c9 Binary files /dev/null and b/docs/assets/images/sb2nov/normal_entry.png differ diff --git a/docs/assets/images/sb2nov/one_line_entry.png b/docs/assets/images/sb2nov/one_line_entry.png new file mode 100644 index 0000000..487629d Binary files /dev/null and b/docs/assets/images/sb2nov/one_line_entry.png differ diff --git a/docs/assets/images/sb2nov/publication_entry.png b/docs/assets/images/sb2nov/publication_entry.png new file mode 100644 index 0000000..39d9f5e Binary files /dev/null and b/docs/assets/images/sb2nov/publication_entry.png differ diff --git a/docs/assets/images/sb2nov/text_entry.png b/docs/assets/images/sb2nov/text_entry.png new file mode 100644 index 0000000..02cb742 Binary files /dev/null and b/docs/assets/images/sb2nov/text_entry.png differ diff --git a/docs/assets/javascripts/katex.js b/docs/assets/javascripts/katex.js new file mode 100644 index 0000000..baabe41 --- /dev/null +++ b/docs/assets/javascripts/katex.js @@ -0,0 +1,10 @@ +document$.subscribe(() => { + renderMathInElement(document.body, { + delimiters: [ + { left: "$$", right: "$$", display: true }, + { left: "$", right: "$", display: false }, + { left: "\\(", right: "\\)", display: false }, + { left: "\\[", right: "\\]", display: true } + ], + }) +}) \ No newline at end of file diff --git a/docs/changelog.md b/docs/changelog.md new file mode 100644 index 0000000..28f7362 --- /dev/null +++ b/docs/changelog.md @@ -0,0 +1,28 @@ +# Changelog + +All notable changes to this project after v1.0 will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). + +## [1.0] - 2024-??-?? + +### Added + +- RenderCV is now a $\LaTeX$ CV framework. Users can move their $\LaTeX$ CV themes to RenderCV to produce their CV from RenderCV's YAML input. +- RenderCV now generates Markdown and HTML versions of the CV to allow users to paste the content of the CV to another software (like [Grammarly](https://www.grammarly.com/)) for spell checking. +- A new theme has been added: `moderncv`. +- A new theme has been added: `sb2nov`. + +### Changed + +- The data model is changed to be more flexible. All the sections are now under the `sections` field. All the keys are arbitrary and rendered as section titles. The entry types can be any of the six built-in entry types, and they will be detected by RenderCV for each section. +- The templating system has been changed completely. +- The command-line interface (CLI) is improved. +- The validation error messages are improved. +- TinyTeX has been moved to [another repository](https://github.com/sinaatalay/tinytex-release), and it is being pulled as a Git submodule. It is still pushed to PyPI, but it's not a part of the repository anymore. +- Tests are improved, and it uses `pytest` instead of `unittest`. +- The documentation has been rewritten. +- The reference has been rewritten. +- The build system has been changed from `setuptools` to `hatchling`. + +[1.0]: https://github.com/sinaatalay/rendercv/releases/tag/v1.0 diff --git a/docs/contact.md b/docs/contact.md deleted file mode 100644 index a81e25d..0000000 --- a/docs/contact.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -hide: - - navigation ---- -test \ No newline at end of file diff --git a/docs/generate_entry_figures.py b/docs/generate_entry_figures.py new file mode 100644 index 0000000..3685de7 --- /dev/null +++ b/docs/generate_entry_figures.py @@ -0,0 +1,229 @@ +import tempfile +import pathlib +import importlib +import importlib.machinery +import importlib.util +import io +from typing import Any + +import pdfCropMargins +import ruamel.yaml +import pypdfium2 + +# Import rendercv. I import the data_models and renderer modules like this instead +# of using `import rendercv` because in order for that to work, the current working +# directory must be the root of the project. To make it convenient for the user, I +# import the modules using the full path of the files. +rendercv_path = pathlib.Path(__file__).parent.parent / "rendercv" + +# Import the rendercv.data_models as dm: +spec = importlib.util.spec_from_file_location( + "rendercv.data_models", rendercv_path / "data_models.py" +) +dm = importlib.util.module_from_spec(spec) # type: ignore +spec.loader.exec_module(dm) # type: ignore + +# Import the rendercv.renderer as r: +spec = importlib.util.spec_from_file_location( + "rendercv.renderer", rendercv_path / "renderer.py" +) +r = importlib.util.module_from_spec(spec) # type: ignore +spec.loader.exec_module(r) # type: ignore + + +# The entries below will be pasted into the documentation as YAML, and their +# corresponding figures will be generated with this script. +education_entry = { + "institution": "Boğaziçi University", + "location": "Istanbul, Turkey", + "degree": "BS", + "area": "Mechanical Engineering", + "start_date": "2015-09", + "end_date": "2020-06", + "highlights": [ + "GPA: 3.24/4.00 ([Transcript](https://example.com))", + "Awards: Dean's Honor List, Sportsperson of the Year", + ], +} + +experience_entry = { + "company": "Some Company", + "location": "TX, USA", + "position": "Software Engineer", + "start_date": "2020-07", + "end_date": "2021-08-12", + "highlights": [ + ( + "Developed a [IOS application](https://example.com) that has recieved" + " more than **100,000 downloads**." + ), + "Managed a team of **5** engineers.", + ], +} + +normal_entry = { + "name": "Some Project", + "location": "Remote", + "date": "2021-09", + "highlights": [ + "Developed a web application with **React** and **Django**.", + "Implemented a **RESTful API**", + ], +} + +publication_entry = { + "title": ( + "Magneto-Thermal Thin Shell Approximation for 3D Finite Element Analysis of" + " No-Insulation Coils" + ), + "authors": ["John Doe", "Harry Tom", "Sina Doe", "Anotherfirstname Andsurname"], + "date": "2023-12-08", + "journal": "IEEE Transactions on Applied Superconductivity", + "doi": "10.1109/TASC.2023.3340648", +} + +one_line_entry = { + "name": "Programming", + "details": "Python, C++, JavaScript, MATLAB", +} + +text_entry = ( + "This is a *TextEntry*. It is only a text and can be useful for sections like" + " **Summary**. To showcase the TextEntry completely, this sentence is added, but it" + " doesn't contain any information." +) + + +def dictionary_to_yaml(dictionary: dict[str, Any]): + """Converts a dictionary to a YAML string. + + Args: + dictionary (dict[str, Any]): The dictionary to be converted to YAML. + Returns: + str: 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) + yaml_string = string_stream.getvalue() + return yaml_string + + +def define_env(env): + # see https://mkdocs-macros-plugin.readthedocs.io/en/latest/macros/ + entries = [ + "education_entry", + "experience_entry", + "normal_entry", + "publication_entry", + "one_line_entry", + "text_entry", + ] + + entries_showcase = dict() + for entry in entries: + proper_entry_name = entry.replace("_", " ").title() + entries_showcase[proper_entry_name] = { + "yaml": dictionary_to_yaml(eval(entry)), + "figures": [ + { + "path": f"assets/images/{theme}/{entry}.png", + "alt_text": f"{proper_entry_name} in {theme}", + "theme": theme, + } + for theme in dm.available_themes + ], + } + + env.variables["showcase_entries"] = entries_showcase + + +if __name__ == "__main__": + # Generate PDF figures for each entry type and theme + entries = { + "education_entry": dm.EducationEntry(**education_entry), + "experience_entry": dm.ExperienceEntry(**experience_entry), + "normal_entry": dm.NormalEntry(**normal_entry), + "publication_entry": dm.PublicationEntry(**publication_entry), + "one_line_entry": dm.OneLineEntry(**one_line_entry), + "text_entry": f'"{text_entry}', + } + themes = dm.available_themes + + pdf_assets_directory = pathlib.Path(__file__).parent / "assets" / "images" + + with tempfile.TemporaryDirectory() as temporary_directory: + # create a temporary directory: + temporary_directory_path = pathlib.Path(temporary_directory) + for theme in themes: + for entry_type, entry in entries.items(): + design_dictionary = { + "theme": theme, + "disable_page_numbering": True, + "show_last_updated_date": False, + } + if theme == "moderncv": + # moderncv theme does not support these options: + del design_dictionary["disable_page_numbering"] + del design_dictionary["show_last_updated_date"] + + # Create the data model with only one section and one entry + data_model = dm.RenderCVDataModel( + **{ + "cv": dm.CurriculumVitae(sections={entry_type: [entry]}), + "design": design_dictionary, + } + ) + + # Render: + latex_file_path = r.generate_latex_file_and_copy_theme_files( + data_model, temporary_directory_path + ) + pdf_file_path = r.latex_to_pdf(latex_file_path) + + # Prepare the output directory and file path: + output_directory = pdf_assets_directory / theme + output_directory.mkdir(parents=True, exist_ok=True) + output_pdf_file_path = output_directory / f"{entry_type}.pdf" + + # Remove the file if it exists: + if output_pdf_file_path.exists(): + output_pdf_file_path.unlink() + + # Crop the margins + pdfCropMargins.crop( + argv_list=[ + "-p4", + "100", + "0", + "100", + "0", + "-a4", + "0", + "-30", + "0", + "-30", + "-o", + str(output_pdf_file_path.absolute()), + str(pdf_file_path.absolute()), + ] + ) + + # Convert pdf to an image + image_name = output_pdf_file_path.with_suffix(".png") + pdf = pypdfium2.PdfDocument(str(output_pdf_file_path.absolute())) + page = pdf[0] + image = page.render(scale=5).to_pil() + + # If the image exists, remove it + if image_name.exists(): + image_name.unlink() + + image.save(image_name) + + pdf.close() + + # Remove the pdf file + output_pdf_file_path.unlink() diff --git a/docs/images/EducationEntry.png b/docs/images/EducationEntry.png deleted file mode 100644 index 6e60bbe..0000000 Binary files a/docs/images/EducationEntry.png and /dev/null differ diff --git a/docs/images/ExperienceEntry.png b/docs/images/ExperienceEntry.png deleted file mode 100644 index eb221bd..0000000 Binary files a/docs/images/ExperienceEntry.png and /dev/null differ diff --git a/docs/images/NormalEntry.png b/docs/images/NormalEntry.png deleted file mode 100644 index 20b7cfc..0000000 Binary files a/docs/images/NormalEntry.png and /dev/null differ diff --git a/docs/images/OneLineEntry.png b/docs/images/OneLineEntry.png deleted file mode 100644 index 5b07d72..0000000 Binary files a/docs/images/OneLineEntry.png and /dev/null differ diff --git a/docs/images/PublicationEntry.png b/docs/images/PublicationEntry.png deleted file mode 100644 index 12a3c08..0000000 Binary files a/docs/images/PublicationEntry.png and /dev/null differ diff --git a/docs/images/example.png b/docs/images/example.png deleted file mode 100644 index a91b264..0000000 Binary files a/docs/images/example.png and /dev/null differ diff --git a/docs/index.md b/docs/index.md index da418f8..df04e54 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,86 +1 @@ -# RenderCV -[![CI](https://github.com/sinaatalay/rendercv/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/sinaatalay/rendercv/actions/workflows/ci.yaml) -[![coverage](https://coverage-badge.samuelcolvin.workers.dev/sinaatalay/rendercv.svg)](https://coverage-badge.samuelcolvin.workers.dev/redirect/sinaatalay/rendercv) -[![pypi-version](https://img.shields.io/pypi/v/rendercv?label=PyPI%20version&color=rgb(0%2C79%2C144))](https://pypi.python.org/pypi/rendercv) -[![pypi-downloads](https://img.shields.io/pepy/dt/rendercv?label=PyPI%20downloads&color=rgb(0%2C%2079%2C%20144))](https://pypi.python.org/pypi/rendercv) - - -RenderCV is a Python application that creates a $\LaTeX$ CV as a PDF from a JSON/YAML input file. Currently, it only supports one theme (*classic*). An example PDF can be seen [here](https://github.com/sinaatalay/rendercv/blob/main/John_Doe_CV.pdf?raw=true). More themes are planned to be supported in the future. - -**What does it do?** - -- It parses a YAML (or JSON) file that looks like this: -```yaml -cv: - name: John Doe - label: Mechanical Engineer - location: Geneva, Switzerland - email: johndoe@example.com - phone: "+33749882538" - website: https://example.com - social_networks: - - network: GitHub - username: johndoe - - network: LinkedIn - username: johndoe - education: - - institution: My University - url: https://example.com - area: Mechanical Engineering - study_type: BS - location: Geneva, Switzerland - start_date: "2017-09-01" - end_date: "2023-01-01" - transcript_url: https://example.com - gpa: 3.10/4.00 - highlights: - - "Class rank: 10 of 62" - - institution: The University of Texas at Austin - url: https://utexas.edu - area: Mechanical Engineering, Student Exchange Program - location: Austin, TX, USA - start_date: "2021-08-01" - end_date: "2022-01-15" - work_experience: - - company: AmIACompany - position: Summer Intern - location: Istanbul, Turkey - url: https://example.com - start_date: "2022-06-15" - end_date: "2022-08-01" - highlights: - - AmIACompany is a **technology** (markdown is - supported) company that provides web-based - engineering applications that enable the - simulation and optimization of products and - manufacturing tools. - - Modeled and simulated a metal-forming process deep - drawing using finite element analysis with - open-source software called CalculiX. -``` -- Then, it validates the input, such as checking if the dates are consistent, checking if the URLs are correct, etc. -- Then, it creates a $\LaTeX$ file. -- Finally, it renders the $\LaTeX$ file to generate the PDF, and you don't need $\LaTeX$ installed on your PC because RenderCV comes with [TinyTeX](https://yihui.org/tinytex/). - -![RenderCV example](images/example.png) - -## Quick Start Guide - -1. Install [Python](https://www.python.org/downloads/) (3.10 or newer). -2. Run the command below to install RenderCV. - ```bash - pip install rendercv - ``` -3. Run the command below to generate a sample input file (`Full_Name_CV.yaml`). The file will be generated in the current working directory. - ```bash - rendercv new "Full Name" - ``` -4. Edit the contents of the `Full_Name_CV.yaml` file. -5. Run the command below to generate your $\LaTeX$ CV. - ```bash - rendercv render Full_Name_CV.yaml - ``` - -## Contributing - -All contributions to RenderCV are welcome, especially adding new $\LaTeX$ themes. +gest \ No newline at end of file diff --git a/docs/javascripts/katex.js b/docs/javascripts/katex.js deleted file mode 100644 index 8debf9f..0000000 --- a/docs/javascripts/katex.js +++ /dev/null @@ -1,11 +0,0 @@ -document$.subscribe(({ body }) => { - renderMathInElement(body, { - delimiters: [ - { left: "$$", right: "$$", display: true }, - { left: "$", right: "$", display: false }, - { left: "\\(", right: "\\)", display: false }, - { left: "\\[", right: "\\]", display: true } - ], - }) - }) - \ No newline at end of file diff --git a/docs/reference/cli.md b/docs/reference/cli.md new file mode 100644 index 0000000..28681d4 --- /dev/null +++ b/docs/reference/cli.md @@ -0,0 +1,3 @@ +# CLI + +::: rendercv.cli \ No newline at end of file diff --git a/docs/reference/data_models.md b/docs/reference/data_models.md new file mode 100644 index 0000000..d7af685 --- /dev/null +++ b/docs/reference/data_models.md @@ -0,0 +1,3 @@ +# Data Models + +::: rendercv.data_models \ No newline at end of file diff --git a/docs/reference/index.md b/docs/reference/index.md new file mode 100644 index 0000000..80e745d --- /dev/null +++ b/docs/reference/index.md @@ -0,0 +1,10 @@ +# RenderCV + +::: rendercv + +In this section, you can find how RenderCV's components are structured and how they interact with each other. + +- [cli.py](cli.md) – This module contains all the command-line interface (CLI) related code for RenderCV. +- [data_models.py](data_models.md) – This module contains classes and functions to parse and validate RenderCV's input YAML. +- [renderer.py](renderer.md) – This module implements $\LaTeX$ file generation and $\LaTeX$ runner utilities for RenderCV. +- [themes](themes.md) – This package contains all the built-in themes of RenderCV. diff --git a/docs/reference/renderer.md b/docs/reference/renderer.md new file mode 100644 index 0000000..f93bbf1 --- /dev/null +++ b/docs/reference/renderer.md @@ -0,0 +1,3 @@ +# Renderer + +::: rendercv.renderer \ No newline at end of file diff --git a/docs/reference/themes.md b/docs/reference/themes.md new file mode 100644 index 0000000..a33f9ab --- /dev/null +++ b/docs/reference/themes.md @@ -0,0 +1,15 @@ +# Themes + +::: rendercv.themes + +## Classic Theme + +::: rendercv.themes.classic + +## Modercv Theme + +::: rendercv.themes.moderncv + +## Sb2nov Theme + +::: rendercv.themes.sb2nov \ No newline at end of file diff --git a/docs/user_guide.md b/docs/user_guide.md index a579a4c..895f8f6 100644 --- a/docs/user_guide.md +++ b/docs/user_guide.md @@ -1,20 +1,40 @@ # RenderCV: User Guide -After you've installed RenderCV with +This document provides everything you need to know about the usage of RenderCV. + +## Installation + +> RenderCV doesn't require a $\LaTeX$ installation; it comes with it! + +1. Install [Python](https://www.python.org/downloads/) (3.10 or newer). + +2. Run the command below to install RenderCV. ```bash pip install rendercv ``` -you can start rendering your CV. +or -Firstly, go to the directory where you want your CV files located and run: +```bash +python -m pip install rendercv +``` + +## Generating the input file + +To get started, navigate to the directory where you want to create your CV and run the command below to create the input file. ```bash rendercv new "Your Full Name" ``` -This will create a YAML input file for RenderCV called `Your_Name_CV.yaml`. Open this generated file in your favorite IDE and start editing. It governs all the features of RenderCV. +or + +```bash +python -m rendercv new "Your Full Name" +``` + +This will create a YAML input file for RenderCV called `Your_Name_CV.yaml`. Open this file in your favorite IDE and start editing. !!! tip @@ -27,189 +47,229 @@ This will create a YAML input file for RenderCV called `Your_Name_CV.yaml`. Open === "Other" - 1. Ensure your editor of choice has support for YAML schema validation. + 1. Ensure your editor of choice has support for JSON Schema. 2. Add the following line at the top of `Your_Name_CV.yaml`: ``` yaml # yaml-language-server: $schema=https://github.com/sinaatalay/rendercv/blob/main/schema.json?raw=true ``` -After you're done editing your input file, run the command below to render your CV: -```bash -rendercv render Your_Name_CV.yaml -``` +## The YAML structure of the input file -## Entry Types - -There are five entry types in RenderCV: - -1. *EducationEntry* -2. *ExperienceEntry* -3. *NormalEntry* -4. *OneLineEntry* -5. *PublicationEntry* - -The whole CV consists of these entries. The table below shows what sections of the input file use which entry type. - -| YAML section | Entry Type | -| ------------------------------ | -------------------------------- | -| `education` | *EducationEntry* | -| `work_experience` | *ExperienceEntry* | -| `academic_projects` | *NormalEntry* | -| `publications` | *PublicationEntry* | -| `certificates` | *NormalEntry* | -| `skills` | *OneLineEntry* | -| `test_scores` | *OneLineEntry* | -| `personal_projects` | *NormalEntry* | -| `extracurricular_activities` | *ExperienceEntry* | -| `custom_sections` | **They can be any of the five!** | - -!!! info - Note that *EducationEntry* is not necessarily for education entries only. It's one of the five entry designs that RenderCV offers, and it could be used for anything (see [custom sections](http://user_guide.md#custom-sections)). *EducationEntry* just happens to be its name. The same goes for other entries, too. - -### *EducationEntry* +RenderCV's input file consists of two parts: `cv` and `design`. ```yaml -institution: Boğaziçi University -url: https://boun.edu.tr -area: Mechanical Engineering -study_type: BS -location: Istanbul, Turkey -start_date: "2017-09-01" -end_date: "2023-01-01" -transcript_url: https://example.com -gpa: 3.10/4.00 -highlights: -- "Class rank: 10 of 62" - +cv: + ... + YOUR CONTENT + ... +design: + ... + YOUR DESIGN + ... ``` -which renders into +The `cv` part contains only the **content of the CV**, and the `design` part contains only the **design options of the CV**. That's how the design and content are separated. -![EducationEntry](images/EducationEntry.png) +### "`cv`" section of the YAML input -### *ExperienceEntry* +The `cv` section of the YAML input starts with generic information, as shown below: ```yaml -company: AmIACompany -position: Summer Intern -location: Istanbul, Turkey -url: https://example.com -start_date: "2022-06-15" -end_date: "2022-08-01" -highlights: -- AmIACompany is a technology company that provides web-based engineering - applications that enable the simulation and optimization of products and - manufacturing tools. -- Modeled and simulated a metal-forming process deep drawing using finite element - analysis with open-source software called CalculiX. +cv: + name: John Doe + email: johndoe@example.com + phone: "+905555555555" + website: https://example.com + label: Mechanical Engineer + location: Istanbul, Türkiye + ... ``` -which renders into +None of the values above are required. You can omit any or all of them, and RenderCV will adapt to your input. -![ExperienceEntry](images/ExperienceEntry.png) - -### *NormalEntry* +The real content of your CV is stored in a field called sections. ```yaml -name: Design and Construction of a Dynamometer -location: Istanbul, Turkey -date: Fall 2022 -highlights: -- Designed and constructed a controllable dynamometer that measures an electric - motor's torque and power output at different speeds for my senior design project. -url: https://example.com - +cv: + name: John Doe + email: johndoe@example.com + phone: "+905555555555" + website: https://example.com + label: Mechanical Engineer + location: Istanbul, Türkiye + sections: + ... + YOUR CONTENT + ... ``` -which renders into +The `sections` field is a dictionary where the keys are the section titles, and the values are lists. Each item of the list is an entry for that section. -![NormalEntry](images/NormalEntry.png) - -### *OneLineEntry* -```yaml -name: Programming -details: C++, C, Python, JavaScript, MATLAB, Lua, LaTeX -``` - -which renders into - -![OneLineEntry](images/OneLineEntry.png) - -### *PublicationEntry* +Here is an example: ```yaml -title: Phononic band gaps induced by inertial amplification in periodic media -authors: -- Author 1 -- John Doe -- Author 3 -journal: Physical Review B -doi: 10.1103/PhysRevB.76.054309 -date: "2007-08-01" -cited_by: 243 +cv: + sections: + this_is_a_section_title: + - This is a TextEntry. + - This is another TextEntry under the same section. + - This is another another TextEntry under the same section. + this_is_another_section_title: + - company: This time it's an ExperienceEntry. + position: Your position + start_date: 2019-01-01 + end_date: 2020-01 + location: TX, USA + highlights: + - This is a highlight (bullet point). + - This is another highlight. + - company: Another ExperienceEntry. + position: Your position + start_date: 2019-01-01 + end_date: 2020-01-10 + location: TX, USA + highlights: + - This is a highlight (bullet point). + - This is another highlight. ``` -which renders into +There are six different entry types in RenderCV. Different types of entries cannot be mixed under the same section, so for each section, you can only use one type of entry. -![PublicationEntry](images/PublicationEntry.png) +The available entry types are: `EducationEntry`, `ExperienceEntry`, `PublicationEntry`, `NormalEntry`, `OneLineEntry`, and `TextEntry`. +Each entry type is a different object (a dictionary). All of the entry types and their corresponding look in each built-in theme are shown below: -## Custom Sections +{% for entry_name, entry in showcase_entries.items() %} +#### {{ entry_name }} +```yaml +{{ entry["yaml"] }} +``` + {% for figure in entry["figures"] %} +`{{ figure["theme"] }}` theme: +![figure["alt_text"]]({{ figure["path"] }}) + {% endfor %} +{% endfor %} -Custom sections with custom titles can be created. Each custom section will be an object that looks like this: +### "`design`" section of the YAML input + +The `cv` part of the input contains your content, and the `design` part contains your design. The `design` part starts with a theme name. Currently, there are three built-in themes (`classic`, `sb2nov`, and `moderncv`), but custom themes can also be used (see [below](#using-custom-themes).) ```yaml -title: My Custom Section -entry_type: OneLineEntry -entries: -- name: Testing custom sections - details: Wohooo! -- name: This is a - details: OneLineEntry! +design: + theme: classic + ... ``` -And `custom_sections` part of the data model will be a list of customs section objects that look like this: +Each theme has different options for design. `classic` and `sb2nov` almost use identical options, but `moderncv` is slightly different. Please use an IDE that supports JSON schema to avoid missing any available options for the theme (see [above](#generating-the-input-file)). + +An example `design` part for a `classic` theme is shown below: + ```yaml -custom_sections: -- title: My Custom Section - entry_type: OneLineEntry - entries: - - name: Testing custom sections - details: Wohooo! - - name: This is a - details: OneLineEntry! -- title: My Other Custom Section - entry_type: EducationEntry - entries: - - institution: Hop! - area: Hop! - study_type: HA - highlights: - - "There are only five types of entries: *EducationEntry*, *ExperienceEntry*, - *NormalEntry*, *OneLineEntry*, and *PublicationEntry*." - - This is an EducationEntry! - start_date: "2022-06-15" - end_date: "2022-08-01" +design: + theme: classic + color: rgb(0,79,144) + disable_page_numbering: false + font_size: 10pt + header_font_size: 30 pt + page_numbering_style: NAME - Page PAGE_NUMBER of TOTAL_PAGES + page_size: a4paper + show_last_updated_date: true + text_alignment: justified + margins: + page: + bottom: 2 cm + left: 1.24 cm + right: 1.24 cm + top: 2 cm + section_title: + bottom: 0.2 cm + top: 0.2 cm + entry_area: + date_and_location_width: 4.1 cm + left_and_right: 0.2 cm + vertical_between: 0.12 cm + highlights_area: + left: 0.4 cm + top: 0.10 cm + vertical_between_bullet_points: 0.10 cm + header: + bottom: 0.2 cm + horizontal_between_connections: 1.5 cm + vertical_between_name_and_connections: 0.2 cm ``` -Each custom section needs to have an entry type, and entries should be adjusted according to the entry type selection. +## Using custom themes -!!! note +RenderCV allows you to move your $\LaTeX$ CV code to RenderCV. To do this, you will need to create some files: - Some entry types use links, and all the links have a text placeholder. That placeholder can be changed with `link_text` setting as shown below: - ```yaml - title: My Third Custom Section - entry_type: ExperienceEntry - link_text: My Link Text - entries: - - company: Hop! - position: Hop! - date: My Date - location: My Location - url: https://example.com - highlights: - - I think this is really working. This is an *ExperienceEntry*! - ``` +``` { .sh .no-copy } +├── yourcustomtheme +│ ├── Preamble.j2.tex +│ ├── Header.j2.tex +│ ├── EducationEntry.j2.tex +│ ├── ExperienceEntry.j2.tex +│ ├── NormalEntry.j2.tex +│ ├── OneLineEntry.j2.tex +│ ├── PublicationEntry.j2.tex +│ ├── TextEntry.j2.tex +│ ├── SectionBeginning.j2.tex +│ └── SectionEnding.j2.tex +└── Your_Full_Name_CV.yaml +``` +Each of these `*.j2.tex` files is $\LaTeX$ code with some Python in it. These files allow RenderCV to create your CV out of the YAML input. +The best way to understand how they work is to look at the source code of built-in themes. For example, the content of `ExperienceEntry.j2.tex` for the `moderncv` theme is shown below: + +```latex +\cventry{ + ((* if design.show_only_years *)) + <> + ((* else *)) + <> + ((* endif *)) +}{ + <> +}{ + <> +}{ + <> +}{}{} +((* for item in entry.highlights *)) +\cvline{}{\small <>} +((* endfor *)) +``` + +The values between `<<` and `>>` are the names of Python variables, allowing you to write a $\\LaTeX$ CV without writing any content. Those will be replaced with the values found in the YAML input. Also, the values between `((*` and `*))` are Python blocks, allowing you to use loops and conditional statements. + +The process of generating $\\LaTeX$ files like this is called "templating," and it's achieved with a Python package called [Jinja](https://jinja.palletsprojects.com/en/3.1.x/). + +### Creating custom theme options + +If you want to have some `design` options under your YAML input file's `design` section for your custom theme, you can create a `__init__.py` file inside your theme directory. + +For example, the `moderncv` theme's `__init__.py` file is shown below: + +```python +from typing import Literal + +import pydantic + +class YourcustomthemeThemeOptions(pydantic.BaseModel): + theme: Literal["yourcustomtheme"] + option1: str + option2: str + option3: int + option4: bool +``` + +Then, RenderCV will parse your custom design options, and you can use these variables inside your `*.j2.tex` as shown below: + +```latex +<> +<> +((* if design.option4 *)) + <> +((* endif *)) +``` \ No newline at end of file diff --git a/examples/John_Doe_ClassicTheme_CV.pdf b/examples/John_Doe_ClassicTheme_CV.pdf new file mode 100644 index 0000000..5a56473 Binary files /dev/null and b/examples/John_Doe_ClassicTheme_CV.pdf differ diff --git a/examples/John_Doe_ClassicTheme_CV.yaml b/examples/John_Doe_ClassicTheme_CV.yaml new file mode 100644 index 0000000..f93139d --- /dev/null +++ b/examples/John_Doe_ClassicTheme_CV.yaml @@ -0,0 +1,151 @@ +cv: + name: John Doe + location: Your Location + email: youremail@yourdomain.com + phone: tel:+90-541-999-99-99 + website: https://yourwebsite.com/ + social_networks: + - network: LinkedIn + username: yourusername + - network: GitHub + username: yourusername + sections: + summary: + - This is an example resume to showcase the capabilities of the open-source + LaTeX CV generator, [RenderCV](https://github.com/sinaatalay/rendercv). A + substantial part of the content is taken from [here](https://www.careercup.com/resume), + where a *clean and tidy CV* pattern is proposed by **Gayle L. McDowell**. + education: + - start_date: 2000-09 + end_date: 2005-05 + highlights: + - 'GPA: 3.9/4.0 ([Transcript](https://example.com))' + - '**Coursework:** Software Foundations, Computer Architecture, Algorithms, + Artificial Intelligence, Comparison of Learning Algorithms, Computational + Theory.' + institution: University of Pennsylvania + area: Computer Science + degree: BS + employment: + - start_date: 2004-06 + end_date: 2004-08 + highlights: + - Reduced time to render the user's buddy list by 75% by implementing prediction + algorithm. + - Implemented iChat integration with OS X Spotlight Search by creating tool + which extracts metadata from saved chat transcripts and provides metadata + to a system-wide search database. + - Redesigned chat file format and implemented backwards compatibility for + search. + location: CA, USA + company: Apple Computer + position: Software Engineer, Intern + - start_date: 2003-09 + end_date: 2005-04 + highlights: + - Promoted to Lead Student Ambassador in Fall 2004, supervised 10 - 15 Student + Ambassadors. + - 'Created and taught Computer Science course, CSE 099: Software Design + and Development.' + location: WA, USA + company: Microsoft Corporation + position: Lead Student Ambassador + - start_date: 2001-10 + end_date: 2005-05 + highlights: + - Implemented a user interface for the VS open file switcher (ctrl-tab) + and extended it to tool windows. + - Created service to provide gradient across VS and VS add-ins. Optimized + service via caching. + - Programmer Productivity Research Center (Summers 2001, 2002) + - 'Built app to compute similarity of all methods in a code base, reduced + time from $\mathcal{O}(n^2)$ to $\mathcal{O}(n \log n)$. ' + - Created test case generation tool which creates random XML docs from XML + Schema. + location: PA, USA + company: University of Pennsylvania + position: Head Teaching Assistant + - start_date: 2003-06 + end_date: 2003-08 + highlights: + - Promoted to Lead Student Ambassador in Fall 2004, supervised 10 - 15 Student + Ambassadors. + - 'Created and taught Computer Science course, CSE 099: Software Design + and Development.' + location: WA, USA + company: Microsoft Corporation + position: Software Design Engineer, Intern + publications: + - title: Magneto-Thermal Thin Shell Approximation for 3D Finite Element Analysis + of No-Insulation Coils + authors: + - Albert Smith + - John Doe + - Jane Derry + - Harry Tom + - Anotherfirstname Andsurname + doi: 10.1109/TASC.2023.3340648 + date: 2004-01 + projects: + - date: '2004' + highlights: + - Developed an electronic classroom where multiple users can view and simultaneously + draw on a "chalkboard" with each person's edits synchronized. + - Used C++ and MFC. + name: Multi-User Drawing Tool + - start_date: 2003 + end_date: 2004 + highlights: + - Developed a desktop calendar with globally shared and synchronized calendars, + allowing users to schedule meetings with other users. + - Used C#.NET, SQL and XML. + name: Synchronized Calendar + - date: '2002' + highlights: + - Developed a UNIX-style OS with scheduler, file system, text editor and + calculator. + - Used C. + name: Operating System + additional_experience_and_awards: + - name: Instructor (2003 - 2005) + details: Taught two full-credit Computer Science courses. + - name: Third Prize, Senior Design Projects + details: Awarded 3rd prize for Synchronized Calendar project, out of 100 projects. + technologies: + - name: Languages + details: C++, C, Java, Objective-C, C#.NET, SQL, JavaScript + - name: Software + details: Visual Studio, Microsoft SQL Server, Eclipse, XCode, Interface Builder +design: + font_size: 10pt + page_size: letterpaper + color: '#004f90' + disable_page_numbering: false + page_numbering_style: NAME - Page PAGE_NUMBER of TOTAL_PAGES + show_last_updated_date: true + header_font_size: 30 pt + text_alignment: justified + margins: + page: + top: 2 cm + bottom: 2 cm + left: 2 cm + right: 2 cm + section_title: + top: 0.3 cm + bottom: 0.2 cm + entry_area: + left_and_right: 0.2 cm + vertical_between: 0.2 cm + date_and_location_width: 4.1 cm + highlights_area: + top: 0.10 cm + left: 0.4 cm + vertical_between_bullet_points: 0.10 cm + header: + vertical_between_name_and_connections: 0.3 cm + bottom: 0.3 cm + horizontal_between_connections: 0.5 cm + theme: classic + show_timespan_in: + - Employment diff --git a/examples/John_Doe_ModerncvTheme_CV.pdf b/examples/John_Doe_ModerncvTheme_CV.pdf new file mode 100644 index 0000000..6c246ad Binary files /dev/null and b/examples/John_Doe_ModerncvTheme_CV.pdf differ diff --git a/examples/John_Doe_ModerncvTheme_CV.yaml b/examples/John_Doe_ModerncvTheme_CV.yaml new file mode 100644 index 0000000..dd8dc91 --- /dev/null +++ b/examples/John_Doe_ModerncvTheme_CV.yaml @@ -0,0 +1,127 @@ +cv: + name: John Doe + location: Your Location + email: youremail@yourdomain.com + phone: tel:+90-541-999-99-99 + website: https://yourwebsite.com/ + social_networks: + - network: LinkedIn + username: yourusername + - network: GitHub + username: yourusername + sections: + summary: + - This is an example resume to showcase the capabilities of the open-source + LaTeX CV generator, [RenderCV](https://github.com/sinaatalay/rendercv). A + substantial part of the content is taken from [here](https://www.careercup.com/resume), + where a *clean and tidy CV* pattern is proposed by **Gayle L. McDowell**. + education: + - start_date: 2000-09 + end_date: 2005-05 + highlights: + - 'GPA: 3.9/4.0 ([Transcript](https://example.com))' + - '**Coursework:** Software Foundations, Computer Architecture, Algorithms, + Artificial Intelligence, Comparison of Learning Algorithms, Computational + Theory.' + institution: University of Pennsylvania + area: Computer Science + degree: BS + employment: + - start_date: 2004-06 + end_date: 2004-08 + highlights: + - Reduced time to render the user's buddy list by 75% by implementing prediction + algorithm. + - Implemented iChat integration with OS X Spotlight Search by creating tool + which extracts metadata from saved chat transcripts and provides metadata + to a system-wide search database. + - Redesigned chat file format and implemented backwards compatibility for + search. + location: CA, USA + company: Apple Computer + position: Software Engineer, Intern + - start_date: 2003-09 + end_date: 2005-04 + highlights: + - Promoted to Lead Student Ambassador in Fall 2004, supervised 10 - 15 Student + Ambassadors. + - 'Created and taught Computer Science course, CSE 099: Software Design + and Development.' + location: WA, USA + company: Microsoft Corporation + position: Lead Student Ambassador + - start_date: 2001-10 + end_date: 2005-05 + highlights: + - Implemented a user interface for the VS open file switcher (ctrl-tab) + and extended it to tool windows. + - Created service to provide gradient across VS and VS add-ins. Optimized + service via caching. + - Programmer Productivity Research Center (Summers 2001, 2002) + - 'Built app to compute similarity of all methods in a code base, reduced + time from $\mathcal{O}(n^2)$ to $\mathcal{O}(n \log n)$. ' + - Created test case generation tool which creates random XML docs from XML + Schema. + location: PA, USA + company: University of Pennsylvania + position: Head Teaching Assistant + - start_date: 2003-06 + end_date: 2003-08 + highlights: + - Promoted to Lead Student Ambassador in Fall 2004, supervised 10 - 15 Student + Ambassadors. + - 'Created and taught Computer Science course, CSE 099: Software Design + and Development.' + location: WA, USA + company: Microsoft Corporation + position: Software Design Engineer, Intern + publications: + - title: Magneto-Thermal Thin Shell Approximation for 3D Finite Element Analysis + of No-Insulation Coils + authors: + - Albert Smith + - John Doe + - Jane Derry + - Harry Tom + - Anotherfirstname Andsurname + doi: 10.1109/TASC.2023.3340648 + date: 2004-01 + projects: + - date: '2004' + highlights: + - Developed an electronic classroom where multiple users can view and simultaneously + draw on a "chalkboard" with each person's edits synchronized. + - Used C++ and MFC. + name: Multi-User Drawing Tool + - start_date: 2003 + end_date: 2004 + highlights: + - Developed a desktop calendar with globally shared and synchronized calendars, + allowing users to schedule meetings with other users. + - Used C#.NET, SQL and XML. + name: Synchronized Calendar + - date: '2002' + highlights: + - Developed a UNIX-style OS with scheduler, file system, text editor and + calculator. + - Used C. + name: Operating System + additional_experience_and_awards: + - name: Instructor (2003 - 2005) + details: Taught two full-credit Computer Science courses. + - name: Third Prize, Senior Design Projects + details: Awarded 3rd prize for Synchronized Calendar project, out of 100 projects. + technologies: + - name: Languages + details: C++, C, Java, Objective-C, C#.NET, SQL, JavaScript + - name: Software + details: Visual Studio, Microsoft SQL Server, Eclipse, XCode, Interface Builder +design: + theme: moderncv + font_size: 10pt + page_size: letterpaper + color: blue + date_width: 3.8 cm + content_scale: 0.75 + show_only_years: false + disable_page_numbers: false diff --git a/examples/John_Doe_Sb2novTheme_CV.pdf b/examples/John_Doe_Sb2novTheme_CV.pdf new file mode 100644 index 0000000..6c2498f Binary files /dev/null and b/examples/John_Doe_Sb2novTheme_CV.pdf differ diff --git a/examples/John_Doe_Sb2novTheme_CV.yaml b/examples/John_Doe_Sb2novTheme_CV.yaml new file mode 100644 index 0000000..582eb36 --- /dev/null +++ b/examples/John_Doe_Sb2novTheme_CV.yaml @@ -0,0 +1,149 @@ +cv: + name: John Doe + location: Your Location + email: youremail@yourdomain.com + phone: tel:+90-541-999-99-99 + website: https://yourwebsite.com/ + social_networks: + - network: LinkedIn + username: yourusername + - network: GitHub + username: yourusername + sections: + summary: + - This is an example resume to showcase the capabilities of the open-source + LaTeX CV generator, [RenderCV](https://github.com/sinaatalay/rendercv). A + substantial part of the content is taken from [here](https://www.careercup.com/resume), + where a *clean and tidy CV* pattern is proposed by **Gayle L. McDowell**. + education: + - start_date: 2000-09 + end_date: 2005-05 + highlights: + - 'GPA: 3.9/4.0 ([Transcript](https://example.com))' + - '**Coursework:** Software Foundations, Computer Architecture, Algorithms, + Artificial Intelligence, Comparison of Learning Algorithms, Computational + Theory.' + institution: University of Pennsylvania + area: Computer Science + degree: BS + employment: + - start_date: 2004-06 + end_date: 2004-08 + highlights: + - Reduced time to render the user's buddy list by 75% by implementing prediction + algorithm. + - Implemented iChat integration with OS X Spotlight Search by creating tool + which extracts metadata from saved chat transcripts and provides metadata + to a system-wide search database. + - Redesigned chat file format and implemented backwards compatibility for + search. + location: CA, USA + company: Apple Computer + position: Software Engineer, Intern + - start_date: 2003-09 + end_date: 2005-04 + highlights: + - Promoted to Lead Student Ambassador in Fall 2004, supervised 10 - 15 Student + Ambassadors. + - 'Created and taught Computer Science course, CSE 099: Software Design + and Development.' + location: WA, USA + company: Microsoft Corporation + position: Lead Student Ambassador + - start_date: 2001-10 + end_date: 2005-05 + highlights: + - Implemented a user interface for the VS open file switcher (ctrl-tab) + and extended it to tool windows. + - Created service to provide gradient across VS and VS add-ins. Optimized + service via caching. + - Programmer Productivity Research Center (Summers 2001, 2002) + - 'Built app to compute similarity of all methods in a code base, reduced + time from $\mathcal{O}(n^2)$ to $\mathcal{O}(n \log n)$. ' + - Created test case generation tool which creates random XML docs from XML + Schema. + location: PA, USA + company: University of Pennsylvania + position: Head Teaching Assistant + - start_date: 2003-06 + end_date: 2003-08 + highlights: + - Promoted to Lead Student Ambassador in Fall 2004, supervised 10 - 15 Student + Ambassadors. + - 'Created and taught Computer Science course, CSE 099: Software Design + and Development.' + location: WA, USA + company: Microsoft Corporation + position: Software Design Engineer, Intern + publications: + - title: Magneto-Thermal Thin Shell Approximation for 3D Finite Element Analysis + of No-Insulation Coils + authors: + - Albert Smith + - John Doe + - Jane Derry + - Harry Tom + - Anotherfirstname Andsurname + doi: 10.1109/TASC.2023.3340648 + date: 2004-01 + projects: + - date: '2004' + highlights: + - Developed an electronic classroom where multiple users can view and simultaneously + draw on a "chalkboard" with each person's edits synchronized. + - Used C++ and MFC. + name: Multi-User Drawing Tool + - start_date: 2003 + end_date: 2004 + highlights: + - Developed a desktop calendar with globally shared and synchronized calendars, + allowing users to schedule meetings with other users. + - Used C#.NET, SQL and XML. + name: Synchronized Calendar + - date: '2002' + highlights: + - Developed a UNIX-style OS with scheduler, file system, text editor and + calculator. + - Used C. + name: Operating System + additional_experience_and_awards: + - name: Instructor (2003 - 2005) + details: Taught two full-credit Computer Science courses. + - name: Third Prize, Senior Design Projects + details: Awarded 3rd prize for Synchronized Calendar project, out of 100 projects. + technologies: + - name: Languages + details: C++, C, Java, Objective-C, C#.NET, SQL, JavaScript + - name: Software + details: Visual Studio, Microsoft SQL Server, Eclipse, XCode, Interface Builder +design: + font_size: 10pt + page_size: letterpaper + color: '#004f90' + disable_page_numbering: false + page_numbering_style: NAME - Page PAGE_NUMBER of TOTAL_PAGES + show_last_updated_date: true + header_font_size: 24 pt + text_alignment: justified + margins: + page: + top: 2 cm + bottom: 2 cm + left: 2 cm + right: 2 cm + section_title: + top: 0.3 cm + bottom: 0.2 cm + entry_area: + left_and_right: 0.2 cm + vertical_between: 0.2 cm + date_and_location_width: 4.1 cm + highlights_area: + top: 0.10 cm + left: 0.4 cm + vertical_between_bullet_points: 0.10 cm + header: + vertical_between_name_and_connections: 0.3 cm + bottom: 0.3 cm + horizontal_between_connections: 0.5 cm + theme: sb2nov diff --git a/mkdocs.yaml b/mkdocs.yaml index ef1d423..7618d52 100644 --- a/mkdocs.yaml +++ b/mkdocs.yaml @@ -1,5 +1,5 @@ -site_name: "RenderCV" -site_description: A Python application that creates a CV in PDF from a YAML/JSON input file. +site_name: RenderCV +site_description: LaTeX CV generator engine from a YAML input file. site_author: Sina Atalay copyright: Copyright © 2023 Sina Atalay site_url: https://sinaatalay.github.io/rendercv/ @@ -46,11 +46,13 @@ theme: nav: - Overview: index.md - User Guide: user_guide.md - - API Reference: - - API Reference: api_reference/index.md - - __main__.py: api_reference/__main__.md - - data_model.py: api_reference/data_model.md - - rendering.py: api_reference/rendering.md + - Reference: + - Reference: reference/index.md + - cli.py: reference/cli.md + - data_models.py: reference/data_models.md + - renderer.py: reference/renderer.md + - themes: reference/themes.md + - Changelog: changelog.md markdown_extensions: # see https://facelessuser.github.io/pymdown-extensions/extensions/inlinehilite/ for more pymdownx info @@ -69,6 +71,8 @@ markdown_extensions: plugins: - search + - macros: # mkdocs-macros-plugin + module_name: docs/generate_entry_figures - mkdocstrings: handlers: python: @@ -78,14 +82,14 @@ plugins: members_order: source show_bases: true docstring_section_style: list - # merge_init_into_class: true + merge_init_into_class: true show_docstring_attributes: true docstring_style: google extra_javascript: - - javascripts/katex.js - - https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.7/katex.min.js - - https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.7/contrib/auto-render.min.js + - assets/javascripts/katex.js + - https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/katex.min.js + - https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/contrib/auto-render.min.js extra_css: - - https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.7/katex.min.css + - https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/katex.min.css diff --git a/pyproject.toml b/pyproject.toml index d52cb68..69f07fb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,21 +1,69 @@ +# Every modern Python package today has a `pyproject.toml` file. It is a Python +# standard. `pyproject.toml` file contains all the metadata about the package. It also +# includes the dependencies and required information for building the package. For more +# details, see https://pip.pypa.io/en/stable/reference/build-system/pyproject-toml/. + +[build-system] +# If a code needs to be distributed, it might need to be compiled, or it might need to +# be bundled with other files. This process of making a code ready for distribution is +# called building. + +# Python packages need to be built too, even though they are not compiled (mostly). At +# the end of the building process, a source Distribution Package, `sdist`, is created. +# This sdist is a compressed archive of the source code, and it is ready to be uploaded +# to PyPI. See https://packaging.python.org/en/latest/tutorials/packaging-projects/ + +# To build RenderCV, we need to specify which build package we want to use. There are +# many build packages like `setuptools`, `flit`, `poetry`, `hatchling`, etc. We will use +# `hatchling`. +requires = ["hatchling==1.21.1"] # Our dependency to build RenderCV + +# Python has a standard object format called build-backend object. Python standard asks +# this object to have some specific methods that do a specific job. For example, it +# should have a method called `build_wheel` that builds a wheel file. We use hatchling +# to build RenderCV, and hatchling's build-backend object is `hatchling.build`. +# See https://peps.python.org/pep-0517/ +build-backend = "hatchling.build" # A build-backend object for building RenderCV + +[tool.hatch.version] +# We will use hatchling to generate the version number of RenderCV. It will go to the +# `path` below and get the version number from there. +# See https://hatch.pypa.io/latest/version/ +path = "rendercv/__init__.py" + +[tool.hatch.build] +# In the sdist package, what do we want to include and exclude? For example, we don't +# want to include `docs` and `tests` because they are not needed to run RenderCV. +include = ["/README.md", "/rendercv"] + +# We use tinytex-release as a git submodule, so it's a seperate repository. We don't +# want to ship all the files from that repository with RenderCV. +exclude = [ + "/rendercv/tinytex-release/minimize_tinytex_for_rendercv.py", + "/rendercv/tinytex-release/.gitignore", +] + [project] +# Under the `project` section, we specify the metadata about RenderCV. name = 'rendercv' -description = 'LaTeX CV generator from a YAML/JSON file' -version = '0.10' +description = 'LaTeX CV generator engine from a YAML input file' +dynamic = [ + "version", +] # We will use hatchling to generate the version number authors = [{ name = 'Sina Atalay' }] requires-python = '>=3.10' readme = "README.md" +# RenderCV depends on these packages. They will be installed automatically when RenderCV +# is installed: dependencies = [ - 'annotated-types==0.6.0', - 'Jinja2==3.1.2', - 'phonenumbers==8.13.22', - 'pydantic==2.4.2', - 'pydantic-extra-types==2.1.0', - 'pydantic_core==2.10.1', - 'typing_extensions==4.8.0', - 'ruamel.yaml==0.17.35', - 'email-validator==2.0.0.post2', - 'typer[all]==0.9.0', + 'Jinja2==3.1.3', # to generate LaTeX and Markdown files + 'phonenumbers==8.13.30', # to validate phone numbers + 'email-validator==2.1.0.post1', # to validate email addresses + 'pydantic==2.6.1', # to validate and parse the input file + 'pydantic-extra-types==2.5.0', # to validate some extra types + 'ruamel.yaml==0.18.6', # to parse YAML files + 'typer[all]==0.9.0', # to create the command-line interface + "markdown==3.5.2", # to convert Markdown to HTML ] classifiers = [ "Intended Audience :: Science/Research", @@ -28,50 +76,67 @@ classifiers = [ "Programming Language :: Python :: 3.12", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", -] +] # go to https://pypi.org/classifiers/ to see all classifiers [project.urls] +# Here, we can specify the URLs related to RenderCV. They will be listed under the +# "Project links" section in PyPI. See https://pypi.org/project/rendercv/ Documentation = 'https://sinaatalay.github.io/rendercv/' Source = 'https://github.com/sinaatalay/rendercv' [project.scripts] -rendercv = 'rendercv.__main__:cli' +# Here, we specify the entry points of RenderCV. +# See https://packaging.python.org/en/latest/specifications/entry-points/#entry-points +# See https://hatch.pypa.io/latest/config/metadata/#cli + +# The key and value below mean this: If someone installs RenderCV, then running +# `rendercv` in the terminal will run the function `app` in the module `__main__` in the +# package `rendercv`. +rendercv = 'rendercv.__main__:app' [project.optional-dependencies] -docs = ["mkdocs", "mkdocs-material", "mkdocstrings-python"] -testing = ["coverage", "pytest", "pytest-cov"] -linting = ["black", "ruff"] +# RenderCV depends on other packages. However, some of these packages are not required +# to run RenderCV, but they are required to develop RenderCV. For example, to build the +# documentation of RenderCV, we need to install some packages. However, not all the +# users of RenderCV will build the documentation, so these are optional dependencies. -[build-system] -# Use setuptools-scm to be able to include TinyTeX in the package -requires = ['setuptools>=68.2.2', "setuptools-scm>=8.0.4"] -build-backend = 'setuptools.build_meta' +docs = [ + "mkdocs-material==9.5.9", # to build docs + "mkdocstrings-python==1.8.0", # to build reference documentation from docstrings + "pdfCropMargins==2.0.3", # to generate entry figures for the documentation + "pypdfium2==4.27.0", # to convert entry figure PDF files to images + "mkdocs-macros-plugin==1.0.5", # to be able to have dynamic content in the documentation +] +tests = [ + "pytest==8.0.1", # to run the tests + "coverage==7.4.1", # to generate coverage reports + "time-machine==2.13.0", # to select an arbitrary date and time for testing + "pypdf==4.0.2", # to read PDF files +] +dev = [ + "ruff==0.2.2", # to lint the code + "black==24.2.0", # to format the code +] -[tool.setuptools] -packages = ["rendercv"] -[tool.ruff] -line-length = 88 +# RenderCV uses different tools to check the code quality, format the code, build the +# documentation, build the package, etc. We can specify the settings for these tools in +# `pyproject.toml` file under `[tool.name_of_the_tool]` so that new contributors can use +# these tools easily. Generally, popular IDEs grab these settings from `pyproject.toml` +# file automatically. + +[tool.black] +line-length = 88 # maximum line length +preview = true # to allow enable-unstable-feature +enable-unstable-feature = [ + "string_processing", +] # breaking strings into multiple lines [tool.coverage.run] source = ['rendercv'] +# use relative paths instead of absolute paths, this is useful for combining coverage +# reports from different OSes: relative_files = true -# [tool.coverage.report] -# precision = 2 -# exclude_lines = [ -# 'pragma: no cover', -# 'raise NotImplementedError', -# 'if TYPE_CHECKING:', -# 'if typing.TYPE_CHECKING:', -# '@overload', -# '@typing.overload', -# '\(Protocol\):$', -# 'typing.assert_never', -# 'assert_never', -# ] - -[tool.black] -color = true -line-length = 88 -experimental-string-processing = true +# don't include jinja templates in the coverage report: +omit = ["*.j2.*"] diff --git a/rendercv/__init__.py b/rendercv/__init__.py index 690490c..28cbf52 100644 --- a/rendercv/__init__.py +++ b/rendercv/__init__.py @@ -1,43 +1,11 @@ """RenderCV package. -It parses the user input YAML/JSON file and validates the data (checks if the -dates are consistent, if the URLs are valid, etc.). Then, with the data, it creates a -$\\LaTeX$ file and renders it with [TinyTeX](https://yihui.org/tinytex/). +RenderCV is a $\\LaTeX$ CV generator from a JSON/YAML input file. It is a $\\LaTeX$ framework, +and users can use RenderCV with their custom $\\LaTeX$ CVs. It allows you to separate your +CV's content from its design. + +Write your content, and get a high-quality, professional-looking CV as a PDF with its +LaTeX source! """ -import logging -import os -import sys - -class LoggingFormatter(logging.Formatter): - grey = "\x1b[38;20m" # debug level - white = "\x1b[37;20m" # info level - yellow = "\x1b[33;20m" # warning level - red = "\x1b[31;20m" # error level - bold_red = "\x1b[31;1m" # critical level - - reset = "\x1b[0m" - format = "%(levelname)s | %(message)s" # type: ignore - - FORMATS = { - logging.DEBUG: grey + format + reset, # type: ignore - logging.INFO: white + format + reset, # type: ignore - logging.WARNING: yellow + format + reset, # type: ignore - logging.ERROR: red + format + reset, # type: ignore - logging.CRITICAL: bold_red + format + reset, # type: ignore - } - - def format(self, record): - log_fmt = self.FORMATS.get(record.levelno) - formatter = logging.Formatter(log_fmt) - return formatter.format(record) - - -# Initialize logger with colors -if sys.platform == "win32": - os.system("COLOR 0") # enable colors in Windows terminal -logger = logging.getLogger() -logger.setLevel(logging.DEBUG) -stdout_handler = logging.StreamHandler() -stdout_handler.setFormatter(LoggingFormatter()) -logger.addHandler(stdout_handler) +__version__ = "1.0" diff --git a/rendercv/__main__.py b/rendercv/__main__.py index f659494..adf9093 100644 --- a/rendercv/__main__.py +++ b/rendercv/__main__.py @@ -1,188 +1,10 @@ -import os -import logging -from typing import Annotated, Callable -from functools import wraps - -from .data_model import read_input_file -from .rendering import render_template, run_latex - -import typer -from jinja2 import Environment, PackageLoader -from pydantic import ValidationError -from pydantic_core import ErrorDetails -from ruamel.yaml.parser import ParserError - -logger = logging.getLogger(__name__) - -app = typer.Typer( - help="RenderCV - A LateX CV generator from YAML", - add_completion=False, - pretty_exceptions_enable=True, - pretty_exceptions_short=True, - pretty_exceptions_show_locals=True, -) - - -def user_friendly_errors(func: Callable) -> Callable: - """Function decorator to make RenderCV's error messages more user-friendly. - - Args: - func (Callable): Function to decorate - Returns: - Callable: Decorated function - """ - - @wraps(func) - def wrapper(*args, **kwargs): - try: - func(*args, **kwargs) - except ValidationError as e: - # It is a Pydantic error - error_messages = [] - error_messages.append("There are some problems with your input.") - - # Translate Pydantic's error messages to make them more user-friendly - custom_error_messages_by_type = { - "url_scheme": "This is not a valid URL.", - "string_type": "This is not a valid string.", - "missing": "This field is required, but it is missing.", - "literal_error": "Only the following values are allowed: {expected}.", - } - custom_error_messages_by_msg = { - "value is not a valid phone number": ( - "This is not a valid phone number." - ), - "String should match pattern '\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)'": ( - "This is not a valid length! Use a number followed by a unit " - "of length (cm, in, pt, mm, ex, em)." - ), - } - new_errors: list[ErrorDetails] = [] - for error in e.errors(): - # Modify Pydantic's error message to make it more user-friendly - - # Remove url: - error["url"] = None - - # Make sure the entries of loc (location) are strings - error["loc"] = [str(loc) for loc in error["loc"]] - - # Assign a custom error message if there is one - custom_message = None - if error["type"] in custom_error_messages_by_type: - custom_message = custom_error_messages_by_type[error["type"]] - elif error["msg"] in custom_error_messages_by_msg: - custom_message = custom_error_messages_by_msg[error["msg"]] - - if custom_message: - ctx = error.get("ctx") - ctx_error = ctx.get("error") if ctx else None - if ctx_error: - # This means that there is a custom validation error that - # comes from data_model.py - error["msg"] = ctx["error"].args[0] - elif ctx: - # Some Pydantic errors have a context, see the custom message - # for "literal_error" above - error["msg"] = custom_message.format(**ctx) - else: - # If there is no context, just use the custom message - error["msg"] = custom_message - - if error["input"] is not None: - # If the input value is a dictionary, remove it - if isinstance(error["input"], dict): - error["input"] = None - elif isinstance(error["input"], (float, int, bool, str)): - # Or if the input value is in the error message, remove it - input_value = str(error["input"]) - if input_value in error["msg"]: - error["input"] = None - - new_errors.append(error) - - # Create a custom error message for RenderCV users - for error in new_errors: - if len(error["loc"]) > 0: - location = ".".join(error["loc"]) - error_messages.append(f"{location}:\n {error['msg']}") - else: - error_messages.append(f"{error['msg']}") - - if error["input"]: - error_messages[-1] += f"\n Your input was \"{error['input']}\"" - error_message = "\n\n ".join(error_messages) - logger.error(error_message) - - except ParserError as e: - # It is a YAML parser error - new_args = list(e.args) - new_args = [str(arg).strip() for arg in new_args] - new_args[0] = "There is a problem with your input file.‍" - error_message = "\n\n ".join(new_args) - logger.error(error_message) - - except Exception as e: - # It is not a Pydantic error - new_args = list(e.args) - new_args = [str(arg).strip() for arg in new_args] - error_message = "\n\n ".join(new_args) - logger.error(error_message) - - return wrapper - - -@app.command(help="Render a YAML input file") -@user_friendly_errors -def render( - input_file: Annotated[ - str, - typer.Argument(help="Name of the YAML input file"), - ] -): - """Generate a LaTeX CV from a YAML input file. - - Args: - input_file (str): Name of the YAML input file - """ - file_path = os.path.abspath(input_file) - data = read_input_file(file_path) - output_latex_file = render_template(data) - run_latex(output_latex_file) - - -@app.command(help="Generate a YAML input file to get started") -@user_friendly_errors -def new(name: Annotated[str, typer.Argument(help="Full name")]): - """Generate a YAML input file to get started. - - Args: - name (str): Full name - """ - environment = Environment( - loader=PackageLoader("rendercv", os.path.join("templates")), - ) - environment.variable_start_string = "<<" - environment.variable_end_string = ">>" - - template = environment.get_template("new_input.yaml.j2") - new_input_file = template.render(name=name) - - name = name.replace(" ", "_") - file_name = f"{name}_CV.yaml" - with open(file_name, "w", encoding="utf-8") as file: - file.write(new_input_file) - - logger.info(f"New input file created: {file_name}") - - -def cli(): - """Start the CLI application. - - This function is the entry point for RenderCV. - """ - app() +""" +`__main__.py` file is the file that gets executed when the RenderCV package itself is +invoked directly from the command line with `python -m rendercv`. That's why we have it +here so that we can invoke the CLI from the command line with `python -m rendercv`. +""" +from .cli import app if __name__ == "__main__": - cli() + app() diff --git a/rendercv/cli.py b/rendercv/cli.py new file mode 100644 index 0000000..46bdda3 --- /dev/null +++ b/rendercv/cli.py @@ -0,0 +1,491 @@ +""" +This module contains the functions and classes that handle the command line interface +(CLI) of RenderCV. It uses [Typer](https://typer.tiangolo.com/) to create the CLI and +[Rich](https://rich.readthedocs.io/en/latest/) to provide a nice looking terminal +output. +""" + +import json +import pathlib +from typing import Annotated, Callable, Optional +import re +import functools + +from rich import print +import rich.console +import rich.panel +import rich.live +import rich.table +import rich.text +import rich.progress +import pydantic +import ruamel.yaml +import ruamel.yaml.parser + +import typer +import ruamel.yaml + + +from . import data_models as dm +from . import renderer as r + + +app = typer.Typer( + rich_markup_mode="rich", + add_completion=False, +) + + +def welcome(): + """Print a welcome message to the terminal.""" + table = rich.table.Table( + title="\nWelcome to [bold]Render[dodger_blue3]CV[/dodger_blue3][/bold]!", + title_justify="left", + ) + + table.add_column("Title", style="magenta") + table.add_column("Link", style="cyan", justify="right", no_wrap=True) + + table.add_row("Documentation", "https://sinaatalay.github.io/rendercv/") + table.add_row("Source code", "https://github.com/sinaatalay/rendercv/") + table.add_row("Bug reports", "https://github.com/sinaatalay/rendercv/issues/") + table.add_row("Feature requests", "https://github.com/sinaatalay/rendercv/issues/") + + print(table) + + +def warning(text: str): + """Print a warning message to the terminal. + + Args: + text (str): The text of the warning message. + """ + print(f"[bold yellow]{text}") + + +def error(text: str, exception: Optional[Exception] = None): + """Print an error message to the terminal. + + Args: + text (str): The text of the error message. + exception (Exception, optional): An exception object. Defaults to None. + """ + if exception is not None: + exception_messages = [str(arg) for arg in exception.args] + exception_message = "\n\n".join(exception_messages) + print( + f"\n[bold red]{text}[/bold red]\n\n[orange4]{exception_message}[/orange4]\n" + ) + else: + print(f"\n[bold red]{text}\n") + + +def information(text: str): + """Print an information message to the terminal. + + Args: + text (str): The text of the information message. + """ + print(f"[bold green]{text}") + + +def get_error_message_and_location_and_value_from_a_custom_error( + error_string: str, +) -> tuple[Optional[str], Optional[str], Optional[str]]: + """Look at a string and figure out if it's a custom error message that has been + sent from [`data_models.py`](data_models.md). If it is, then return the custom + message, location, and the input value. + + This is done because sometimes we raise an error about a specific field in the model + validation level, but Pydantic doesn't give us the exact location of the error + because it's a model-level error. So, we raise a custom error with three string + arguments: message, location, and input value. Those arguments then combined into a + string by Python. This function is used to parse that custom error message and + return the three values. + + Args: + error_string (str): The error message. + Returns: + tuple[Optional[str], Optional[str], Optional[str]]: The custom message, + location, and the input value. + """ + pattern = r"""\(['"](.*)['"], '(.*)', '(.*)'\)""" + match = re.search(pattern, error_string) + if match: + return match.group(1), match.group(2), match.group(3) + else: + return None, None, None + + +def handle_validation_error(exception: pydantic.ValidationError): + """Take a Pydantic validation error and print the error messages in a nice table. + + Pydantic's ValidationError object is a complex object that contains a lot of + information about the error. This function takes a ValidationError object and + extracts the error messages, locations, and the input values. Then, it prints them + in a nice table with [Rich](https://rich.readthedocs.io/en/latest/). + + Args: + exception (pydantic.ValidationError): The Pydantic validation error object. + """ + # This dictionary is used to convert the error messages that Pydantic returns to + # more user-friendly messages. + error_dictionary: dict[str, str] = { + "Input should be 'present'": ( + "This is not a valid date! Please use either YYYY-MM-DD, YYYY-MM, or YYYY" + ' format or "present"!' + ), + "Input should be a valid integer, unable to parse string as an integer": ( + "This is not a valid date! Please use either YYYY-MM-DD, YYYY-MM, or YYYY" + " format!" + ), + "String should match pattern '\\d{4}-\\d{2}(-\\d{2})?'": ( + "This is not a valid date! Please use either YYYY-MM-DD, YYYY-MM, or YYYY" + " format!" + ), + "URL scheme should be 'http' or 'https'": "This is not a valid URL!", + "Field required": "This field is required!", + "value is not a valid phone number": "This is not a valid phone number!", + "month must be in 1..12": "The month must be between 1 and 12!", + "Value error, day is out of range for month": ( + "The day is out of range for the month!" + ), + "Extra inputs are not permitted": ( + "This field is unknown for this object! Please remove it." + ), + "Input should be a valid string": "This field should be a string!", + "Input should be a valid list": ( + "This field should contain a list of items but it doesn't!" + ), + } + + # Check if this is a section error. If it is, we need to handle it differently. + # This is needed because how dm.validate_section_input function raises an exception. + # This is done to tell the user which which EntryType RenderCV excepts to see. + errors = exception.errors() + for error_object in errors.copy(): + if ( + "There are problems with the entries." in error_object["msg"] + and "ctx" in error_object + ): + location = error_object["loc"] + ctx_object = error_object["ctx"] + if "error" in ctx_object: + error_object = ctx_object["error"] + if hasattr(error_object, "__cause__"): + cause_object = error_object.__cause__ + cause_object_errors = cause_object.errors() + for cause_error_object in cause_object_errors: + # we use [1:] to avoid `entries` location. It is a location for + # RenderCV's own data model, not the user's data model. + cause_error_object["loc"] = tuple( + list(location) + list(cause_error_object["loc"][1:]) + ) + errors.extend(cause_object_errors) + + # some locations are not really the locations in the input file, but some + # information about the model coming from Pydantic. We need to remove them. + # (e.g. avoid stuff like .end_date.literal['present']) + unwanted_locations = ["tagged-union", "list", "literal"] + for error_object in errors: + location = error_object["loc"] + new_location = [str(location_element) for location_element in location] + for location_element in location: + location_element = str(location_element) + for unwanted_location in unwanted_locations: + if unwanted_location in location_element: + new_location.remove(location_element) + error_object["loc"] = new_location # type: ignore + + # Parse all the errors and create a new list of errors. + new_errors: list[dict[str, str]] = [] + end_date_error_is_found = False + for error_object in errors: + message = error_object["msg"] + location = ".".join(error_object["loc"]) # type: ignore + input = error_object["input"] + + # Check if this is a custom error message: + custom_message, custom_location, custom_input_value = ( + get_error_message_and_location_and_value_from_a_custom_error(message) + ) + if custom_message is not None: + message = custom_message + if custom_location != "": + # If the custom location is not empty, then add it to the location. + location = f"{location}.{custom_location}" + input = custom_input_value + + # Convert the error message to a more user-friendly message if it's in the + # error_dictionary: + if message in error_dictionary: + message = error_dictionary[message] + + # Special case for end_date because Pydantic returns multiple end_date errors + # since it has multiple valid formats: + if "end_date." in location: + if end_date_error_is_found: + continue + end_date_error_is_found = True + message = ( + "This is not a valid end date! Please use either YYYY-MM-DD, YYYY-MM," + ' or YYYY format or "present"!' + ) + + # If the input is a dictionary or a list (the model itself fails to validate), + # then don't show the input. It looks confusing and it is not helpful. + if isinstance(input, (dict, list)): + input = "" + + new_errors.append( + { + "loc": str(location), + "msg": message, + "input": str(input), + } + ) + + # Print the errors in a nice table: + table = rich.table.Table( + title="[bold red]\nThere are some errors in the input file!\n", + title_justify="left", + show_lines=True, + ) + table.add_column("Location", style="cyan", no_wrap=True) + table.add_column("Input Value", style="magenta") + table.add_column("Error Message", style="orange4") + + for error_object in new_errors: + table.add_row( + error_object["loc"], + error_object["input"], + error_object["msg"], + ) + + print(table) + print() # Add an empty line at the end to make it look better. + + +def handle_exceptions(function: Callable) -> Callable: + """Return a wrapper function that handles exceptions. + + A decorator in Python is a syntactic convenience that allows a Python to interpret + the code below: + + ```python + @handle_exceptions + def my_function(): + pass + ``` + as + ```python + handle_exceptions(my_function)() + ``` + which is step by step equivalent to + + 1. Execute `#!python handle_exceptions(my_function)` which will return the + function called `wrapper`. + 2. Execute `#!python wrapper()`. + + Args: + function (Callable): The function to be wrapped. + Returns: + Callable: The wrapped function. + """ + + @functools.wraps(function) + def wrapper(*args, **kwargs): + try: + function(*args, **kwargs) + except pydantic.ValidationError as e: + handle_validation_error(e) + except ruamel.yaml.YAMLError as e: + error("There is a YAML error in the input file!", e) + except FileNotFoundError as e: + error(e) + except UnicodeDecodeError as e: + # find the problematic character that cannot be decoded with utf-8 + bad_character = str(e.object[e.start : e.end]) + try: + bad_character_context = str(e.object[e.start - 16 : e.end + 16]) + except IndexError: + bad_character_context = "" + + error( + "The input file contains a character that cannot be decoded with" + f" UTF-8 ({bad_character}):\n {bad_character_context}", + ) + + except ValueError as e: + error(e) + except RuntimeError as e: + error("An error occurred:", e) + + return wrapper + + +class LiveProgressReporter(rich.live.Live): + """This class is a wrapper around `rich.live.Live` that provides the live progress + reporting functionality. + + Args: + number_of_steps (int): The number of steps to be finished. + """ + + def __init__(self, number_of_steps: int, end_message: str = "Your CV is rendered!"): + class TimeElapsedColumn(rich.progress.ProgressColumn): + def render(self, task: "rich.progress.Task") -> rich.text.Text: + elapsed = task.finished_time if task.finished else task.elapsed + delta = f"{elapsed:.1f} s" + return rich.text.Text(str(delta), style="progress.elapsed") + + self.step_progress = rich.progress.Progress( + TimeElapsedColumn(), rich.progress.TextColumn("{task.description}") + ) + + self.overall_progress = rich.progress.Progress( + TimeElapsedColumn(), + rich.progress.BarColumn(), + rich.progress.TextColumn("{task.description}"), + ) + + self.group = rich.console.Group( + rich.panel.Panel(rich.console.Group(self.step_progress)), + self.overall_progress, + ) + + self.overall_task_id = self.overall_progress.add_task("", total=number_of_steps) + self.number_of_steps = number_of_steps + self.end_message = end_message + self.current_step = 0 + self.overall_progress.update( + self.overall_task_id, + description=( + f"[bold #AAAAAA]({self.current_step} out of" + f" {self.number_of_steps} steps finished)" + ), + ) + super().__init__(self.group) + + def __enter__(self) -> "LiveProgressReporter": + """Overwrite the `__enter__` method for the correct return type.""" + self.start(refresh=self._renderable is not None) + return self + + def start_a_step(self, step_name: str): + """Start a step and update the progress bars.""" + self.current_step_name = step_name + self.current_step_id = self.step_progress.add_task( + f"{self.current_step_name} has started." + ) + + def finish_the_current_step(self): + """Finish the current step and update the progress bars.""" + self.step_progress.stop_task(self.current_step_id) + self.step_progress.update( + self.current_step_id, description=f"{self.current_step_name} has finished." + ) + self.current_step += 1 + self.overall_progress.update( + self.overall_task_id, + description=( + f"[bold #AAAAAA]({self.current_step} out of" + f" {self.number_of_steps} steps finished)" + ), + advance=1, + ) + if self.current_step == self.number_of_steps: + self.end() + + def end(self): + """End the live progress reporting.""" + self.overall_progress.update( + self.overall_task_id, + description=f"[bold green]{self.end_message}", + ) + + +@app.command( + name="render", + help=( + "Render a YAML input file. Example: [bold green]rendercv render" + " John_Doe_CV.yaml[/bold green]" + ), +) +@handle_exceptions +def cli_command_render( + input_file_path: Annotated[ + str, + typer.Argument(help="Path to the YAML input file as a string"), + ], + use_local_latex: Annotated[ + bool, + typer.Option( + "--use-local-latex", + help="Use the local LaTeX installation instead of the RenderCV's TinyTeX.", + ), + ] = False, +): + """Generate a $\\LaTeX$ CV from a YAML input file. + + Args: + input_file_path (str): Path to the YAML input file as a string. + use_local_latex (bool, optional): Use the local LaTeX installation instead of + the RenderCV's TinyTeX. The default is False. + """ + welcome() + + input_file_path_obj = pathlib.Path(input_file_path) + + output_directory = input_file_path_obj.parent / "rendercv_output" + + with LiveProgressReporter(number_of_steps=5) as progress: + progress.start_a_step("Reading and validating the input file") + data_model = dm.read_input_file(input_file_path_obj) + progress.finish_the_current_step() + + progress.start_a_step("Generating the LaTeX file") + latex_file_path = r.generate_latex_file_and_copy_theme_files( + data_model, output_directory + ) + progress.finish_the_current_step() + + progress.start_a_step("Generating the Markdown file") + markdown_file_path = r.generate_markdown_file(data_model, output_directory) + progress.finish_the_current_step() + + progress.start_a_step("Rendering the LaTeX file to a PDF") + r.latex_to_pdf(latex_file_path, use_local_latex) + progress.finish_the_current_step() + + progress.start_a_step("Rendering the Markdown file to a HTML (for Grammarly)") + r.markdown_to_html(markdown_file_path) + progress.finish_the_current_step() + + +@app.command( + name="new", + help=( + "Generate a YAML input file to get started. Example: [bold green]rendercv new" + ' "John Doe"[/bold green]' + ), +) +def cli_command_new(full_name: Annotated[str, typer.Argument(help="Your full name")]): + """Generate a YAML input file to get started.""" + data_model = dm.get_a_sample_data_model(full_name) + file_name = f"{full_name.replace(' ', '_')}_CV.yaml" + file_path = pathlib.Path(file_name) + + # Instead of getting the dictionary with data_model.model_dump() directly, we + # convert it to JSON and then to a dictionary. Because the YAML library we are using + # sometimes has problems with the dictionary returned by model_dump(). + data_model_as_json = data_model.model_dump_json( + exclude_none=True, by_alias=True, exclude={"cv": {"sections"}} + ) + data_model_as_dictionary = json.loads(data_model_as_json) + + yaml_object = ruamel.yaml.YAML() + yaml_object.indent(mapping=2, sequence=4, offset=2) + yaml_object.dump(data_model_as_dictionary, file_path) + + information(f"Your RenderCV input file has been created: {file_path}!") diff --git a/rendercv/data_model.py b/rendercv/data_model.py deleted file mode 100644 index aa8042a..0000000 --- a/rendercv/data_model.py +++ /dev/null @@ -1,1659 +0,0 @@ -""" -This module contains classes and functions to parse and validate YAML or JSON input -files. It uses [Pydantic](https://github.com/pydantic/pydantic) to achieve this goal. -All the data classes have `BaseModel` from Pydantic as a base class, and some data -fields have advanced types like `HttpUrl`, `EmailStr`, or `PastDate` from the Pydantic -library for validation. -""" - -from datetime import date as Date -from typing import Literal -from typing_extensions import Annotated, Optional -import re -import logging -from functools import cached_property -import urllib.request -import os -from importlib.resources import files -import json -import time - -from pydantic import ( - BaseModel, - HttpUrl, - Field, - field_validator, - model_validator, - computed_field, - EmailStr, -) -from pydantic.json_schema import GenerateJsonSchema -from pydantic.functional_validators import AfterValidator -from pydantic_extra_types.phone_numbers import PhoneNumber -from pydantic_extra_types.color import Color -from ruamel.yaml import YAML - -logger = logging.getLogger(__name__) - - -def escape_latex_characters(sentence: str) -> str: - """Escape LaTeX characters in a sentence. - - Example: - ```python - escape_latex_characters("This is a # sentence.") - ``` - will return: - `#!python "This is a \\# sentence."` - """ - - # Dictionary of escape characters: - escape_characters = { - "#": r"\#", - # "$": r"\$", # Don't escape $ as it is used for math mode - "%": r"\%", - "&": r"\&", - "~": r"\textasciitilde{}", - # "_": r"\_", # Don't escape _ as it is used for math mode - # "^": r"\textasciicircum{}", # Don't escape ^ as it is used for math mode - } - - # Don't escape links as hyperref will do it automatically: - - # Find all the links in the sentence: - links = re.findall(r"\[.*?\]\(.*?\)", sentence) - - # Replace the links with a placeholder: - for link in links: - sentence = sentence.replace(link, "!!-link-!!") - - # Handle backslash and curly braces separately because the other characters are - # escaped with backslash and curly braces: - # --don't escape curly braces as they are used heavily in LaTeX--: - # sentence = sentence.replace("{", ">>{") - # sentence = sentence.replace("}", ">>}") - # --don't escape backslash as it is used heavily in LaTeX--: - # sentence = sentence.replace("\\", "\\textbackslash{}") - # sentence = sentence.replace(">>{", "\\{") - # sentence = sentence.replace(">>}", "\\}") - - # Loop through the letters of the sentence and if you find an escape character, - # replace it with its LaTeX equivalent: - copy_of_the_sentence = sentence - for character in copy_of_the_sentence: - if character in escape_characters: - sentence = sentence.replace(character, escape_characters[character]) - - # Replace the links with the original links: - for link in links: - sentence = sentence.replace("!!-link-!!", link) - - return sentence - - -def parse_date_string(date_string: str) -> Date | int: - """Parse a date string in YYYY-MM-DD, YYYY-MM, or YYYY format and return a - datetime.date object. - - Args: - date_string (str): The date string to parse. - Returns: - datetime.date: The parsed date. - """ - if re.match(r"\d{4}-\d{2}-\d{2}", date_string): - # Then it is in YYYY-MM-DD format - date = Date.fromisoformat(date_string) - elif re.match(r"\d{4}-\d{2}", date_string): - # Then it is in YYYY-MM format - # Assign a random day since days are not rendered in the CV - date = Date.fromisoformat(f"{date_string}-01") - elif re.match(r"\d{4}", date_string): - # Then it is in YYYY format - # Then keep it as an integer - date = int(date_string) - else: - raise ValueError( - f'The date string "{date_string}" is not in YYYY-MM-DD, YYYY-MM, or YYYY' - " format." - ) - - if isinstance(date, Date): - # Then it means the date is a Date object, so check if it is a past date: - if date > Date.today(): - raise ValueError( - f'The date "{date_string}" is in the future. Please check the dates.' - ) - - return date - - -def compute_time_span_string(start_date: Date | int, end_date: Date | int) -> str: - """Compute the time span between two dates and return a string that represents it. - - Example: - ```python - compute_time_span_string(Date(2022,9,24), Date(2025,2,12)) - ``` - - will return: - - `#!python "2 years 5 months"` - - Args: - start_date (Date | int): The start date. - end_date (Date | int): The end date. - - Returns: - str: The time span string. - """ - # check if the types of start_date and end_date are correct: - if not isinstance(start_date, (Date, int)): - raise TypeError("start_date is not a Date object or an integer!") - if not isinstance(end_date, (Date, int)): - raise TypeError("end_date is not a Date object or an integer!") - - # calculate the number of days between start_date and end_date: - if isinstance(start_date, Date) and isinstance(end_date, Date): - timespan_in_days = (end_date - start_date).days - elif isinstance(start_date, Date) and isinstance(end_date, int): - timespan_in_days = (Date(end_date, 1, 1) - start_date).days - elif isinstance(start_date, int) and isinstance(end_date, Date): - timespan_in_days = (end_date - Date(start_date, 1, 1)).days - elif isinstance(start_date, int) and isinstance(end_date, int): - timespan_in_days = (end_date - start_date) * 365 - - if timespan_in_days < 0: - raise ValueError( - '"start_date" can not be after "end_date". Please check the dates.' - ) - - # calculate the number of years between start_date and end_date: - how_many_years = timespan_in_days // 365 - if how_many_years == 0: - how_many_years_string = None - elif how_many_years == 1: - how_many_years_string = "1 year" - else: - how_many_years_string = f"{how_many_years} years" - - # calculate the number of months between start_date and end_date: - how_many_months = round((timespan_in_days % 365) / 30) - if how_many_months <= 1: - how_many_months_string = "1 month" - else: - how_many_months_string = f"{how_many_months} months" - - # combine howManyYearsString and howManyMonthsString: - if how_many_years_string is None: - timespan_string = how_many_months_string - else: - timespan_string = f"{how_many_years_string} {how_many_months_string}" - - return timespan_string - - -def format_date(date: Date) -> str: - """Formats a date to a string in the following format: "Jan. 2021". - - It uses month abbreviations, taken from - [Yale University Library](https://web.library.yale.edu/cataloging/months). - - Example: - ```python - format_date(Date(2024,5,1)) - ``` - will return - - `#!python "May 2024"` - - Args: - date (Date): The date to format. - - Returns: - str: The formatted date. - """ - if not isinstance(date, (Date, int)): - raise TypeError("date is not a Date object or an integer!") - - if isinstance(date, int): - # Then it means the user only provided the year, so just return the year - return str(date) - - # Month abbreviations, - # taken from: https://web.library.yale.edu/cataloging/months - abbreviations_of_months = [ - "Jan.", - "Feb.", - "Mar.", - "Apr.", - "May", - "June", - "July", - "Aug.", - "Sept.", - "Oct.", - "Nov.", - "Dec.", - ] - - month = int(date.strftime("%m")) - monthAbbreviation = abbreviations_of_months[month - 1] - year = date.strftime("%Y") - date_string = f"{monthAbbreviation} {year}" - - return date_string - - -def generate_json_schema(output_directory: str) -> str: - """Generate the JSON schema of the data model and save it to a file. - - Args: - output_directory (str): The output directory to save the schema. - """ - - class RenderCVSchemaGenerator(GenerateJsonSchema): - def generate(self, schema, mode="validation"): - json_schema = super().generate(schema, mode=mode) - json_schema["title"] = "RenderCV Input" - - # remove the description of the class (RenderCVDataModel) - del json_schema["description"] - - # add $id - json_schema[ - "$id" - ] = "https://raw.githubusercontent.com/sinaatalay/rendercv/main/schema.json" - - # add $schema - json_schema["$schema"] = "http://json-schema.org/draft-07/schema#" - - # Loop through $defs and remove docstring descriptions and fix optional - # fields - for key, value in json_schema["$defs"].items(): - # Don't allow additional properties - value["additionalProperties"] = False - - # I don't want the docstrings in the schema, so remove them: - if "This class" in value["description"]: - del value["description"] - - # If a type is optional, then Pydantic sets the type to a list of two - # types, one of which is null. The null type can be removed since we - # already have the required field. Moreover, we would like to warn - # users if they provide null values. They can remove the fields if they - # don't want to provide them. - null_type_dict = {} - null_type_dict["type"] = "null" - for field in value["properties"].values(): - if "anyOf" in field: - if ( - len(field["anyOf"]) == 2 - and null_type_dict in field["anyOf"] - ): - field["allOf"] = [field["anyOf"][0]] - del field["anyOf"] - - # In date field, we both accept normal strings and Date objects. They - # are both strings, therefore, if user provides a Date object, then - # JSON schema will complain that it matches two different types. - # Remember that all of the anyOfs are changed to oneOfs. Only one of - # the types can be matched. Therefore, we remove the first type, which - # is the string with the YYYY-MM-DD format. - if ( - "date" in value["properties"] - and "anyOf" in value["properties"]["date"] - ): - del value["properties"]["date"]["anyOf"][0] - - return json_schema - - schema = RenderCVDataModel.model_json_schema( - schema_generator=RenderCVSchemaGenerator - ) - schema = json.dumps(schema, indent=2) - - # Change all anyOf to oneOf - schema = schema.replace('"anyOf"', '"oneOf"') - - path_to_schema = os.path.join(output_directory, "schema.json") - with open(path_to_schema, "w") as f: - f.write(schema) - - return path_to_schema - - -# ====================================================================================== -# DESIGN MODELS ======================================================================== -# ====================================================================================== - -# To understand how to create custom data types, see: -# https://docs.pydantic.dev/latest/usage/types/custom/ -LaTeXDimension = Annotated[ - str, - Field( - pattern=r"\d+\.?\d* *(cm|in|pt|mm|ex|em)", - ), -] - - -class ClassicThemePageMargins(BaseModel): - """This class stores the margins of pages for the classic theme.""" - - top: LaTeXDimension = Field( - default="2 cm", - title="Top Margin", - description="The top margin of the page with units.", - ) - bottom: LaTeXDimension = Field( - default="2 cm", - title="Bottom Margin", - description="The bottom margin of the page with units.", - ) - left: LaTeXDimension = Field( - default="1.24 cm", - title="Left Margin", - description="The left margin of the page with units.", - ) - right: LaTeXDimension = Field( - default="1.24 cm", - title="Right Margin", - description="The right margin of the page with units.", - ) - - -class ClassicThemeSectionTitleMargins(BaseModel): - """This class stores the margins of section titles for the classic theme.""" - - top: LaTeXDimension = Field( - default="0.2 cm", - title="Top Margin", - description="The top margin of section titles.", - ) - bottom: LaTeXDimension = Field( - default="0.2 cm", - title="Bottom Margin", - description="The bottom margin of section titles.", - ) - - -class ClassicThemeEntryAreaMargins(BaseModel): - """This class stores the margins of entry areas for the classic theme. - - For the classic theme, entry areas are [OneLineEntry](../user_guide.md#onelineentry), - [NormalEntry](../user_guide.md#normalentry), and - [ExperienceEntry](../user_guide.md#experienceentry). - """ - - left_and_right: LaTeXDimension = Field( - default="0.2 cm", - title="Left Margin", - description="The left margin of entry areas.", - ) - - vertical_between: LaTeXDimension = Field( - default="0.12 cm", - title="Vertical Margin Between Entry Areas", - description="The vertical margin between entry areas.", - ) - - -class ClassicThemeHighlightsAreaMargins(BaseModel): - """This class stores the margins of highlights areas for the classic theme.""" - - top: LaTeXDimension = Field( - default="0.10 cm", - title="Top Margin", - description="The top margin of highlights areas.", - ) - left: LaTeXDimension = Field( - default="0.4 cm", - title="Left Margin", - description="The left margin of highlights areas.", - ) - vertical_between_bullet_points: LaTeXDimension = Field( - default="0.10 cm", - title="Vertical Margin Between Bullet Points", - description="The vertical margin between bullet points.", - ) - - -class ClassicThemeHeaderMargins(BaseModel): - """This class stores the margins of the header for the classic theme.""" - - vertical_between_name_and_connections: LaTeXDimension = Field( - default="0.2 cm", - title="Vertical Margin Between the Name and Connections", - description=( - "The vertical margin between the name of the person and the connections." - ), - ) - bottom: LaTeXDimension = Field( - default="0.2 cm", - title="Bottom Margin", - description=( - "The bottom margin of the header, i.e., the vertical margin between the" - " connections and the first section title." - ), - ) - - -class ClassicThemeMargins(BaseModel): - """This class stores the margins for the classic theme.""" - - page: ClassicThemePageMargins = Field( - default=ClassicThemePageMargins(), - title="Page Margins", - description="Page margins for the classic theme.", - ) - section_title: ClassicThemeSectionTitleMargins = Field( - default=ClassicThemeSectionTitleMargins(), - title="Section Title Margins", - description="Section title margins for the classic theme.", - ) - entry_area: ClassicThemeEntryAreaMargins = Field( - default=ClassicThemeEntryAreaMargins(), - title="Entry Area Margins", - description="Entry area margins for the classic theme.", - ) - highlights_area: ClassicThemeHighlightsAreaMargins = Field( - default=ClassicThemeHighlightsAreaMargins(), - title="Highlights Area Margins", - description="Highlights area margins for the classic theme.", - ) - header: ClassicThemeHeaderMargins = Field( - default=ClassicThemeHeaderMargins(), - title="Header Margins", - description="Header margins for the classic theme.", - ) - - -class ClassicThemeOptions(BaseModel): - """This class stores the options for the classic theme. - - In RenderCV, each theme has its own Pydantic class so that new themes - can be implemented easily in future. - """ - - primary_color: Color = Field( - default="rgb(0,79,144)", - validate_default=True, - title="Primary Color", - description=( - "The primary color of Classic Theme. It is used for the section titles," - " heading, and the links.\nThe color can be specified either with their" - " [name](https://www.w3.org/TR/SVG11/types.html#ColorKeywords), hexadecimal" - " value, RGB value, or HSL value." - ), - examples=["Black", "7fffd4", "rgb(0,79,144)", "hsl(270, 60%, 70%)"], - ) - - date_and_location_width: LaTeXDimension = Field( - default="4.1 cm", - title="Date and Location Column Width", - description="The width of the date and location column.", - ) - - text_alignment: Literal["left-aligned", "justified"] = Field( - default="left-aligned", - title="Text Alignment", - description="The alignment of the text.", - ) - - show_timespan_in: list[str] = Field( - default=[], - title="Show Time Span in These Sections", - description=( - "The time span will be shown in the date and location column in these" - " sections. The input should be a list of strings." - ), - ) - - show_last_updated_date: bool = Field( - default=True, - title="Show Last Updated Date", - description=( - "If this option is set to true, then the last updated date will be shown" - " in the header." - ), - ) - - header_font_size: LaTeXDimension = Field( - default="30 pt", - title="Header Font Size", - description="The font size of the header (the name of the person).", - ) - - margins: ClassicThemeMargins = Field( - default=ClassicThemeMargins(), - title="Margins", - description="Page, section title, entry field, and highlights field margins.", - ) - - -class Design(BaseModel): - """This class stores the theme name of the CV and the theme's options.""" - - theme: Literal["classic"] = Field( - default="classic", - title="Theme name", - description='The only option is "Classic" for now.', - ) - font: Literal["SourceSans3", "Roboto", "EBGaramond"] = Field( - default="SourceSans3", - title="Font", - description="The font of the CV.", - ) - font_size: Literal["10pt", "11pt", "12pt"] = Field( - default="10pt", - title="Font Size", - description="The font size of the CV. It can be 10pt, 11pt, or 12pt.", - ) - page_size: Literal["a4paper", "letterpaper"] = Field( - default="a4paper", - title="Page Size", - description="The page size of the CV. It can be a4paper or letterpaper.", - ) - options: Optional[ClassicThemeOptions] = Field( - default=None, - title="Theme Options", - description="The options of the theme.", - ) - - @model_validator(mode="after") - @classmethod - def check_theme_options(cls, model): - """Check if the correct options are provided for the theme. If the theme - options are not provided, then set the default options for the theme. - """ - if model.options is None: - if model.theme == "classic": - model.options = ClassicThemeOptions() - else: - raise RuntimeError(f'The theme "{model.theme}" does not exist.') - 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(f'The theme "{model.theme}"" does not exist.') - - return model - - @field_validator("font") - @classmethod - def check_font(cls, font: str) -> str: - """Go to the fonts directory and check if the font exists. If it exists, then - check if all the required files are there. - """ - fonts_directory = str(files("rendercv").joinpath("templates", "fonts")) - if font not in os.listdir(fonts_directory): - raise ValueError( - f'The font "{font}" is not found in the "fonts" directory.' - ) - else: - font_directory = os.path.join(fonts_directory, font) - required_files = [ - f"{font}-Bold.ttf", - f"{font}-BoldItalic.ttf", - f"{font}-Italic.ttf", - f"{font}-Regular.ttf", - ] - for file in required_files: - if file not in os.listdir(font_directory): - raise ValueError(f"{file} is not found in the {font} directory.") - - return font - - @field_validator("theme") - @classmethod - def check_if_theme_exists(cls, theme: str) -> str: - """Check if the theme exists in the templates directory.""" - template_directory = str(files("rendercv").joinpath("templates", theme)) - if f"{theme}.tex.j2" not in os.listdir(template_directory): - raise ValueError( - f'The theme "{theme}" is not found in the "templates" directory.' - ) - - return theme - - -# ====================================================================================== -# ====================================================================================== -# ====================================================================================== - -# ====================================================================================== -# CONTENT MODELS ======================================================================= -# ====================================================================================== - -LaTeXString = Annotated[str, AfterValidator(escape_latex_characters)] -PastDate = Annotated[ - str, Field(pattern=r"\d{4}-?(\d{2})?-?(\d{2})?"), AfterValidator(parse_date_string) -] - - -class Event(BaseModel): - """This class is the parent class for classes like `#!python EducationEntry`, - `#!python ExperienceEntry`, `#!python NormalEntry`, and `#!python OneLineEntry`. - - It stores the common fields between these classes like dates, location, highlights, - and URL. - """ - - start_date: Optional[PastDate] = Field( - default=None, - title="Start Date", - description="The start date of the event in YYYY-MM-DD format.", - examples=["2020-09-24"], - ) - end_date: Optional[Literal["present"] | PastDate] = Field( - default=None, - title="End Date", - description=( - "The end date of the event in YYYY-MM-DD format. If the event is still" - ' ongoing, then the value should be "present".' - ), - examples=["2020-09-24", "present"], - ) - date: Optional[PastDate | LaTeXString] = Field( - default=None, - title="Date", - description=( - "If the event is a one-day event, then this field should be filled in" - " YYYY-MM-DD format. If the event is a multi-day event, then the start date" - " and end date should be provided instead. All of them can't be provided at" - " the same time." - ), - examples=["2020-09-24", "My Custom Date"], - ) - highlights: Optional[list[LaTeXString]] = Field( - default=[], - title="Highlights", - description=( - "The highlights of the event. It will be rendered as bullet points." - ), - examples=["Did this.", "Did that."], - ) - location: Optional[LaTeXString] = Field( - default=None, - title="Location", - description=( - "The location of the event. It will be shown with the date in the" - " same column." - ), - examples=["Istanbul, Turkey"], - ) - url: Optional[HttpUrl] = None - - @field_validator("date") - @classmethod - def check_date(cls, date: PastDate | LaTeXString) -> PastDate | LaTeXString: - """Check if the date is a string or a Date object and return accordingly.""" - if isinstance(date, str): - try: - # If this runs, it means the date is an ISO format string, and it can be - # parsed - date = parse_date_string(date) - except ValueError: - # Then it means it is a custom string like "Fall 2023" - date = date - - return date - - @model_validator(mode="after") - @classmethod - def check_dates(cls, model): - """Make sure that either `#!python start_date` and `#!python end_date` or only - `#!python date` is provided. - """ - date_is_provided = False - start_date_is_provided = False - end_date_is_provided = False - if model.date is not None: - date_is_provided = True - if model.start_date is not None: - start_date_is_provided = True - if model.end_date is not None: - end_date_is_provided = True - - if date_is_provided and start_date_is_provided and end_date_is_provided: - logger.warning( - '"start_date", "end_date" and "date" are all provided in of the' - " entries. Therefore, date will be ignored." - ) - model.date = None - - elif date_is_provided and start_date_is_provided and not end_date_is_provided: - logger.warning( - 'Both "date" and "start_date" is provided in of the entries.' - ' "start_date" will be ignored.' - ) - model.start_date = None - model.end_date = None - - elif date_is_provided and end_date_is_provided and not start_date_is_provided: - logger.warning( - 'Both "date" and "end_date" is provided in of the entries. "end_date"' - " will be ignored." - ) - model.start_date = None - model.end_date = None - - elif start_date_is_provided and not end_date_is_provided: - logger.warning( - '"start_date" is provided in of the entries, but "end_date" is not.' - ' "end_date" will be set to "present".' - ) - model.end_date = "present" - - if model.start_date is not None and model.end_date is not None: - if model.end_date == "present": - end_date = Date.today() - elif isinstance(model.end_date, int): - # Then it means user only provided the year, so convert it to a Date - # object with the first day of the year (just for the date comparison) - end_date = Date(model.end_date, 1, 1) - elif isinstance(model.end_date, Date): - # Then it means user provided either YYYY-MM-DD or YYYY-MM - end_date = model.end_date - else: - raise RuntimeError("end_date is neither an integer nor a Date object.") - - if isinstance(model.start_date, int): - # Then it means user only provided the year, so convert it to a Date - # object with the first day of the year (just for the date comparison) - start_date = Date(model.start_date, 1, 1) - elif isinstance(model.start_date, Date): - # Then it means user provided either YYYY-MM-DD or YYYY-MM - start_date = model.start_date - else: - raise RuntimeError( - "start_date is neither an integer nor a Date object." - ) - - if start_date > end_date: - raise ValueError( - '"start_date" can not be after "end_date". Please check the dates.' - ) - - return model - - @computed_field - @cached_property - def date_and_location_strings_with_timespan(self) -> list[LaTeXString]: - date_and_location_strings = [] - - if self.location is not None: - date_and_location_strings.append(self.location) - - if self.date is not None: - if isinstance(self.date, str): - date_and_location_strings.append(self.date) - elif isinstance(self.date, Date): - date_and_location_strings.append(format_date(self.date)) - else: - raise RuntimeError("Date is neither a string nor a Date object.") - elif self.start_date is not None and self.end_date is not None: - start_date = format_date(self.start_date) - - if self.end_date == "present": - end_date = "present" - - time_span_string = compute_time_span_string( - self.start_date, Date.today() - ) - else: - end_date = format_date(self.end_date) - - time_span_string = compute_time_span_string( - self.start_date, self.end_date - ) - - date_and_location_strings.append(f"{start_date} to {end_date}") - - date_and_location_strings.append(f"{time_span_string}") - - return date_and_location_strings - - @computed_field - @cached_property - def date_and_location_strings_without_timespan(self) -> list[LaTeXString]: - # use copy() to avoid modifying the original list - date_and_location_strings = self.date_and_location_strings_with_timespan.copy() - for string in date_and_location_strings: - if ( - "years" in string - or "months" in string - or "year" in string - or "month" in string - ): - date_and_location_strings.remove(string) - - return date_and_location_strings - - @computed_field - @cached_property - def highlight_strings(self) -> list[LaTeXString]: - highlight_strings = [] - if self.highlights is not None: - highlight_strings.extend(self.highlights) - - return highlight_strings - - @computed_field - @cached_property - def markdown_url(self) -> Optional[str]: - if self.url is None: - return None - else: - url = str(self.url) - - if "github" in url: - link_text = "view on GitHub" - elif "linkedin" in url: - link_text = "view on LinkedIn" - elif "instagram" in url: - link_text = "view on Instagram" - elif "youtube" in url: - link_text = "view on YouTube" - else: - link_text = "view on my website" - - markdown_url = f"[{link_text}]({url})" - - return markdown_url - - @computed_field - @cached_property - def month_and_year(self) -> Optional[LaTeXString]: - 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(self.date) # type: ignore - except TypeError: - month_and_year = str(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](../user_guide.md#onelineentry) information.""" - - name: LaTeXString = Field( - title="Name", - description="The name of the entry. It will be shown as bold text.", - ) - details: LaTeXString = Field( - title="Details", - description="The details of the entry. It will be shown as normal text.", - ) - - -class NormalEntry(Event): - """This class stores [NormalEntry](../user_guide.md#normalentry) information.""" - - name: LaTeXString = Field( - title="Name", - description="The name of the entry. It will be shown as bold text.", - ) - - -class ExperienceEntry(Event): - """This class stores [ExperienceEntry](../user_guide.md#experienceentry) information.""" - - company: LaTeXString = Field( - title="Company", - description="The company name. It will be shown as bold text.", - ) - position: LaTeXString = Field( - title="Position", - description="The position. It will be shown as normal text.", - ) - - -class EducationEntry(Event): - """This class stores [EducationEntry](../user_guide.md#educationentry) information.""" - - institution: LaTeXString = Field( - title="Institution", - description="The institution name. It will be shown as bold text.", - examples=["Bogazici University"], - ) - area: LaTeXString = Field( - title="Area", - description="The area of study. It will be shown as normal text.", - ) - study_type: Optional[LaTeXString] = Field( - default=None, - title="Study Type", - description="The type of the degree.", - examples=["BS", "BA", "PhD", "MS"], - ) - gpa: Optional[LaTeXString | float] = Field( - default=None, - title="GPA", - description="The GPA of the degree.", - ) - transcript_url: Optional[HttpUrl] = Field( - default=None, - title="Transcript URL", - description=( - "The URL of the transcript. It will be shown as a link next to the GPA." - ), - examples=["https://example.com/transcript.pdf"], - ) - - @computed_field - @cached_property - def highlight_strings(self) -> list[LaTeXString]: - highlight_strings = [] - - if self.gpa is not None: - gpaString = f"GPA: {self.gpa}" - if self.transcript_url is not None: - gpaString += f" ([Transcript]({self.transcript_url}))" - highlight_strings.append(gpaString) - - if self.highlights is not None: - highlight_strings.extend(self.highlights) - - return highlight_strings - - -class PublicationEntry(Event): - """This class stores [PublicationEntry](../user_guide.md#publicationentry) information.""" - - title: LaTeXString = Field( - title="Title of the Publication", - description="The title of the publication. It will be shown as bold text.", - ) - authors: list[LaTeXString] = Field( - title="Authors", - description="The authors of the publication in order as a list of strings.", - ) - doi: str = Field( - title="DOI", - description="The DOI of the publication.", - examples=["10.48550/arXiv.2310.03138"], - ) - date: LaTeXString = Field( - title="Publication Date", - description="The date of the publication.", - examples=["2021-10-31"], - ) - cited_by: Optional[int] = Field( - default=None, - title="Cited By", - description="The number of citations of the publication.", - ) - journal: Optional[LaTeXString] = Field( - default=None, - title="Journal", - description="The journal or the conference name.", - ) - - @field_validator("doi") - @classmethod - def check_doi(cls, doi: str) -> str: - """Check if the DOI exists in the DOI System.""" - doi_url = f"https://doi.org/{doi}" - - try: - urllib.request.urlopen(doi_url) - except urllib.request.HTTPError as err: - if err.code == 404: - raise ValueError(f"{doi} cannot be found in the DOI System.") - - return doi - - @computed_field - @cached_property - def doi_url(self) -> str: - return f"https://doi.org/{self.doi}" - - -class SocialNetwork(BaseModel): - """This class stores a social network information. - - Currently, only LinkedIn, Github, Mastodon, and Instagram are supported. - """ - - network: Literal["LinkedIn", "GitHub", "Instagram", "Orcid", "Mastodon"] = Field( - title="Social Network", - description="The social network name.", - ) - username: str = Field( - title="Username", - description="The username of the social network. The link will be generated.", - ) - - -class Connection(BaseModel): - """This class stores a connection/communication information. - - Warning: - This class isn't designed for users to use, but it is used by RenderCV to make - the $\\LaTeX$ templating easier. - """ - - name: Literal[ - "LinkedIn", - "GitHub", - "Instagram", - "Orcid", - "Mastodon", - "phone", - "email", - "website", - "location", - ] - value: str - - @staticmethod - def is_valid_hostname(hostname: str) -> bool: - """Is hostname a valid hostname by RFCs 952 and 1123""" - - # slightly modified from - # https://stackoverflow.com/a/33214423/1304076 - if hostname[-1] == ".": - # strip exactly one dot from the right, if present - hostname = hostname[:-1] - if len(hostname) > 253: - return False - - labels = hostname.split(".") - - # the last label must be not all-numeric - if re.match(r"[0-9]+$", labels[-1]): - return False - - # labels cannot begin with a hyphen - # labels must have at least character - # labels may not have more than 63 characters - allowed = re.compile(r"(?!-)[a-z0-9-]{1,63}(? Optional[HttpUrl]: - """returns profile url from a mastodon user address. - - Args: - address (str): A Mastodon user address. E.g., "user@social.example" - - Returns: - A pydantic HttpUrl object with the https URL for the user profile - - Example: - ``` - url = MastodonUname2Url("user@social.example") - assert(url == HttpUrl(http://social.example/@user)) - ``` - - Exceptions: - ValueError if the address is malformed. - Note that well-formed addresses should never yield - syntactically invalid URLs. - """ - - # The closest thing to a formal spec of Mastodon usernames - # where these regular expressions from a (reference?) - # implementation - # - # https://github.com/mastodon/mastodon/blob/f1657e6d6275384c199956e8872115fdcec600b0/app/models/account.rb#L68 - # - # USERNAME_RE = /[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?/i - # MENTION_RE = %r{(?[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?) # username part - @ # separator - (?P[a-z0-9]+([a-z0-9.-]+)?) # domain part - \s*$ # ignore trailing whitespace - """, - re.VERBOSE | re.IGNORECASE, - ) - - m = pattern.match(address) - if m is None: - raise ValueError("Invalid mastodon address") - uname = m.group("uname") - domain = m.group("domain") - - # the domain part of pattern allows some things that are not - # valid names. So we run a stricter check - if not Connection.is_valid_hostname(domain): - raise ValueError("Invalid hostname in mastodon address") - - url = HttpUrl(f"https://{domain}/@{uname}") - return url - - @computed_field - @cached_property - def url(self) -> Optional[HttpUrl | str]: - if self.name == "LinkedIn": - url = f"https://www.linkedin.com/in/{self.value}" - elif self.name == "GitHub": - url = f"https://www.github.com/{self.value}" - elif self.name == "Instagram": - url = f"https://www.instagram.com/{self.value}" - elif self.name == "Orcid": - url = f"https://orcid.org/{self.value}" - elif self.name == "Mastodon": - url = self.MastodonUname2Url(self.value) - elif self.name == "email": - url = f"mailto:{self.value}" - elif self.name == "website": - url = self.value - elif self.name == "phone": - url = self.value - elif self.name == "location": - url = None - else: - raise RuntimeError(f'"{self.name}" is not a valid connection.') - - return url - - -class SectionBase(BaseModel): - """This class stores a section information. - - It is the parent class of all the section classes like - `#!python SectionWithEducationEntries`, `#!python SectionWithExperienceEntries`, - `#!python SectionWithNormalEntries`, `#!python SectionWithOneLineEntries`, and - `#!python SectionWithPublicationEntries`. - """ - - title: LaTeXString = Field( - title="Section Title", - description="The title of the section.", - examples=["My Custom Section"], - ) - link_text: Optional[LaTeXString] = Field( - default=None, - title="Link Text", - description=( - "If the section has a link, then what should be the text of the link? If" - " this field is not provided, then the link text will be generated" - " automatically based on the URL." - ), - examples=["view on GitHub", "view on LinkedIn"], - ) - - @field_validator("title") - @classmethod - def make_first_letters_uppercase(cls, title: LaTeXString) -> LaTeXString: - """Capitalize the first letters of the words in the title.""" - return title.title() - - -entry_type_field = Field( - title="Entry Type", - description="The type of the entries in the section.", -) -entries_field = Field( - title="Entries", - description="The entries of the section. The format depends on the entry type.", -) - - -class SectionWithEducationEntries(SectionBase): - """This class stores a section with - [EducationEntry](../user_guide.md#educationentry)s. - """ - - entry_type: Literal["EducationEntry"] = entry_type_field - entries: list[EducationEntry] = entries_field - - -class SectionWithExperienceEntries(SectionBase): - """This class stores a section with - [ExperienceEntry](../user_guide.md#experienceentry)s. - """ - - entry_type: Literal["ExperienceEntry"] = entry_type_field - entries: list[ExperienceEntry] = entries_field - - -class SectionWithNormalEntries(SectionBase): - """This class stores a section with - [NormalEntry](../user_guide.md#normalentry)s. - """ - - entry_type: Literal["NormalEntry"] = entry_type_field - entries: list[NormalEntry] = entries_field - - -class SectionWithOneLineEntries(SectionBase): - """This class stores a section with - [OneLineEntry](../user_guide.md#onelineentry)s. - """ - - entry_type: Literal["OneLineEntry"] = entry_type_field - entries: list[OneLineEntry] = entries_field - - -class SectionWithPublicationEntries(SectionBase): - """This class stores a section with - [PublicationEntry](../user_guide.md#publicationentry)s. - """ - - entry_type: Literal["PublicationEntry"] = entry_type_field - entries: list[PublicationEntry] = entries_field - - -Section = Annotated[ - SectionWithEducationEntries - | SectionWithExperienceEntries - | SectionWithNormalEntries - | SectionWithOneLineEntries - | SectionWithPublicationEntries, - Field( - discriminator="entry_type", - ), -] - - -class CurriculumVitae(BaseModel): - """This class bindes all the information of a CV together.""" - - name: LaTeXString = Field( - title="Name", - description="The name of the person.", - ) - label: Optional[LaTeXString] = Field( - default=None, - title="Label", - description="The label of the person.", - ) - location: Optional[LaTeXString] = Field( - default=None, - title="Location", - description="The location of the person. This is not rendered currently.", - ) - email: Optional[EmailStr] = Field( - default=None, - title="Email", - description="The email of the person. It will be rendered in the heading.", - ) - phone: Optional[PhoneNumber] = None - website: Optional[HttpUrl] = None - social_networks: Optional[list[SocialNetwork]] = Field( - default=None, - title="Social Networks", - description=( - "The social networks of the person. They will be rendered in the heading." - ), - ) - summary: Optional[LaTeXString] = Field( - default=None, - title="Summary", - description="The summary of the person.", - ) - # Sections: - section_order: Optional[list[str]] = Field( - default=None, - title="Section Order", - description=( - "The order of sections in the CV. The section title should be used." - ), - ) - education: Optional[list[EducationEntry]] = Field( - default=None, - title="Education", - description="The education entries of the person.", - ) - experience: Optional[list[ExperienceEntry]] = Field( - default=None, - title="Experience", - description="The experience entries of the person.", - ) - work_experience: Optional[list[ExperienceEntry]] = Field( - default=None, - title="Work Experience", - description="The work experience entries of the person.", - ) - projects: Optional[list[NormalEntry]] = Field( - default=None, - title="Projects", - description="The project entries of the person.", - ) - academic_projects: Optional[list[NormalEntry]] = Field( - default=None, - title="Academic Projects", - description="The academic project entries of the person.", - ) - university_projects: Optional[list[NormalEntry]] = Field( - default=None, - title="University Projects", - description="The university project entries of the person.", - ) - personal_projects: Optional[list[NormalEntry]] = Field( - default=None, - title="Personal Projects", - description="The personal project entries of the person.", - ) - publications: Optional[list[PublicationEntry]] = Field( - default=None, - title="Publications", - description="The publication entries of the person.", - ) - certificates: Optional[list[NormalEntry]] = Field( - default=None, - title="Certificates", - description="The certificate entries of the person.", - ) - extracurricular_activities: Optional[list[ExperienceEntry]] = Field( - default=None, - title="Extracurricular Activities", - description="The extracurricular activity entries of the person.", - ) - test_scores: Optional[list[OneLineEntry]] = Field( - default=None, - title="Test Scores", - description="The test score entries of the person.", - ) - programming_skills: Optional[list[NormalEntry]] = Field( - default=None, - title="Programming Skills", - description="The programming skill entries of the person.", - ) - skills: Optional[list[OneLineEntry]] = Field( - default=None, - title="Skills", - description="The skill entries of the person.", - ) - other_skills: Optional[list[OneLineEntry]] = Field( - default=None, - title="Skills", - description="The skill entries of the person.", - ) - awards: Optional[list[OneLineEntry]] = Field( - default=None, - title="Awards", - description="The award entries of the person.", - ) - interests: Optional[list[OneLineEntry]] = Field( - default=None, - title="Interests", - description="The interest entries of the person.", - ) - custom_sections: Optional[list[Section]] = Field( - default=None, - title="Custom Sections", - description=( - "Custom sections with custom section titles can be rendered as well." - ), - ) - - @model_validator(mode="after") - @classmethod - def check_if_the_section_names_are_unique(cls, model): - """Check if the section names are unique.""" - pre_defined_section_names = [ - "Education", - "Work Experience", - "Academic Projects", - "Personal Projects", - "Certificates", - "Extracurricular Activities", - "Test Scores", - "Skills", - "Publications", - ] - if model.custom_sections is not None: - custom_section_names = [] - for custom_section in model.custom_sections: - custom_section_names.append(custom_section.title) - - section_names = pre_defined_section_names + custom_section_names - else: - section_names = pre_defined_section_names - - seen = set() - duplicates = {val for val in section_names if (val in seen or seen.add(val))} - if len(duplicates) > 0: - raise ValueError( - "The section names should be unique. The following section names are" - f" duplicated: {duplicates}" - ) - - return model - - @computed_field - @cached_property - def connections(self) -> list[Connection]: - connections = [] - if self.location is not None: - connections.append(Connection(name="location", value=self.location)) - if self.phone is not None: - connections.append(Connection(name="phone", value=self.phone)) - if self.email is not None: - connections.append(Connection(name="email", value=self.email)) - if self.website is not None: - connections.append(Connection(name="website", value=str(self.website))) - if self.social_networks is not None: - for social_network in self.social_networks: - connections.append( - Connection( - name=social_network.network, value=social_network.username - ) - ) - - return connections - - @computed_field - @cached_property - def sections(self) -> list[SectionBase]: - sections = [] - - # Pre-defined sections (i.e. sections that are not custom)): - pre_defined_sections = { - "Education": self.education, - "Experience": self.experience, - "Work Experience": self.work_experience, - "Publications": self.publications, - "Projects": self.projects, - "Academic Projects": self.academic_projects, - "University Projects": self.university_projects, - "Personal Projects": self.personal_projects, - "Certificates": self.certificates, - "Extracurricular Activities": self.extracurricular_activities, - "Test Scores": self.test_scores, - "Skills": self.skills, - "Programming Skills": self.programming_skills, - "Other Skills": self.other_skills, - "Awards": self.awards, - "Interests": self.interests, - "Programming Skills": self.programming_skills, - } - - section_order_is_given = True - if self.section_order is None: - section_order_is_given = False - # If the user didn't specify the section order, then use the default order: - self.section_order = list(pre_defined_sections.keys()) - if self.custom_sections is not None: - # If the user specified custom sections, then add them to the end of the - # section order with the same order as they are in the input file: - self.section_order.extend( - [section.title for section in self.custom_sections] - ) - - link_text = None - entry_type = None - entries = None - for section_name in self.section_order: - # Create a section for each section name in the section order: - if section_name in pre_defined_sections: - if pre_defined_sections[section_name] is None: - if section_order_is_given: - raise ValueError( - f'The section "{section_name}" is not found in the CV.' - " Please create the section or delete it from the section" - " order." - ) - else: - continue - - entry_type = pre_defined_sections[section_name][0].__class__.__name__ - entries = pre_defined_sections[section_name] - if section_name == "Test Scores": - link_text = "Score Report" - elif section_name == "Certificates": - link_text = "Certificate" - else: - link_text = None - else: - # If the section is not pre-defined, then it is a custom section. - # Find the corresponding custom section and get its entries: - for custom_section in self.custom_sections: # type: ignore - if custom_section.title == section_name: - entry_type = custom_section.entries[0].__class__.__name__ - link_text = custom_section.link_text - entries = custom_section.entries - break - else: - entry_type = None - link_text = None - entries = None - - if entry_type is None or entries is None: - raise ValueError( - f'"{section_name}" is not a valid section name. Please create a' - " custom section with this name or delete it from the section" - " order." - ) - - object_map = { - "EducationEntry": SectionWithEducationEntries, - "ExperienceEntry": SectionWithExperienceEntries, - "NormalEntry": SectionWithNormalEntries, - "OneLineEntry": SectionWithOneLineEntries, - "PublicationEntry": SectionWithPublicationEntries, - } - - section = object_map[entry_type]( - title=section_name, - entry_type=entry_type, # type: ignore - entries=entries, - link_text=link_text, - ) - sections.append(section) - - # Check if any of the pre-defined sections are missing from the section order: - for section_name in pre_defined_sections: - if pre_defined_sections[section_name] is not None: - if section_name not in self.section_order: - logger.warning( - f'The section "{section_name}" is not found in the section' - " order! It will not be rendered." - ) - - # Check if any of the custom sections are missing from the section order: - if self.custom_sections is not None: - for custom_section in self.custom_sections: - if custom_section.title not in self.section_order: - logger.warning( - f'The custom section "{custom_section.title}" is not found in' - " the section order! It will not be rendered." - ) - - return sections - - -# ====================================================================================== -# ====================================================================================== -# ====================================================================================== - - -class RenderCVDataModel(BaseModel): - """This class binds both the CV and the design information together.""" - - design: Design = Field( - default=Design(), - title="Design", - description="The design of the CV.", - ) - cv: CurriculumVitae = Field( - default=CurriculumVitae(name="John Doe"), - title="Curriculum Vitae", - description="The data of the CV.", - ) - - @model_validator(mode="after") - @classmethod - def check_classical_theme_show_timespan_in(cls, model): - """Check if the sections that are specified in the "show_timespan_in" option - exist in the CV. - """ - if model.design.theme == "classic": - design: Design = model.design - cv: CurriculumVitae = model.cv - section_titles = [section.title for section in cv.sections] - for title in design.options.show_timespan_in: # type: ignore - if title not in section_titles: - not_used_section_titles = list( - set(section_titles) - set(design.options.show_timespan_in) - ) - not_used_section_titles = ", ".join(not_used_section_titles) - raise ValueError( - f'The section "{title}" that is specified in the' - ' "show_timespan_in" option is not found in the CV. You' - " might have wanted to use one of these:" - f" {not_used_section_titles}." - ) - - return model - - -def read_input_file(file_path: str) -> RenderCVDataModel: - """Read the input file. - - Args: - file_path (str): The path to the input file. - - Returns: - str: The input file as a string. - """ - start_time = time.time() - logger.info(f"Reading and validating the input file {file_path} has started.") - - # check if the file exists: - if not os.path.exists(file_path): - raise FileNotFoundError(f"The file {file_path} doesn't exist.") - - # check the file extension: - accepted_extensions = [".yaml", ".yml", ".json", ".json5"] - if not any(file_path.endswith(extension) for extension in accepted_extensions): - raise ValueError( - f"The file {file_path} doesn't have an accepted extension!" - f" Accepted extensions are: {accepted_extensions}" - ) - - with open(file_path) as file: - yaml = YAML() - raw_json = yaml.load(file) - - data = RenderCVDataModel(**raw_json) - - end_time = time.time() - time_taken = end_time - start_time - logger.info( - f"Reading and validating the input file {file_path} has finished in" - f" {time_taken:.2f} s." - ) - return data diff --git a/rendercv/data_models.py b/rendercv/data_models.py new file mode 100644 index 0000000..ee29e89 --- /dev/null +++ b/rendercv/data_models.py @@ -0,0 +1,1404 @@ +""" +This module contains all the necessary classes to store CV data. These classes are called +data models. The YAML input file is transformed into instances of these classes (i.e., +the input file is read) with the [`read_input_file`](#read_input_file) function. +RenderCV utilizes these instances to generate a $\\LaTeX$ file which is then rendered into a +PDF file. + +The data models are initialized with data validation to prevent unexpected bugs. During +the initialization, we ensure that everything is in the correct place and that the user +has provided a valid RenderCV input. This is achieved through the use of +[Pydantic](https://pypi.org/project/pydantic/). +""" + +from datetime import date as Date +from typing import Literal, Any, Type, Annotated, Optional, get_args +import importlib +import importlib.util +import importlib.machinery +import functools +from urllib.request import urlopen, HTTPError +import json +import re +import ssl +import pathlib + +import pydantic +import pydantic_extra_types.phone_numbers as pydantic_phone_numbers +import ruamel.yaml + +from .themes.classic import ClassicThemeOptions +from .themes.moderncv import ModerncvThemeOptions +from .themes.sb2nov import Sb2novThemeOptions + +# Create a custom type called RenderCVDate that accepts only strings in YYYY-MM-DD or +# YYYY-MM format: +# This type is used to validate the date fields in the data. +# See https://docs.pydantic.dev/2.5/concepts/types/#custom-types for more information +# about custom types. +date_pattern_for_json_schema = r"\d{4}(-\d{2})?(-\d{2})?" +date_pattern_for_validation = r"\d{4}-\d{2}(-\d{2})?" +RenderCVDate = Annotated[ + str, + pydantic.Field( + pattern=date_pattern_for_validation, + json_schema_extra={"pattern": date_pattern_for_json_schema}, + ), +] + + +def get_date_object(date: str | int) -> Date: + """Parse a date string in YYYY-MM-DD, YYYY-MM, or YYYY format and return a + datetime.date object. This function is used throughout the validation process of the + data models. + + Args: + date (str): The date string to parse. + Returns: + datetime.date: The parsed date. + """ + if isinstance(date, int): + date_object = Date.fromisoformat(f"{date}-01-01") + elif re.fullmatch(r"\d{4}-\d{2}-\d{2}", date): + # Then it is in YYYY-MM-DD format + date_object = Date.fromisoformat(date) + elif re.fullmatch(r"\d{4}-\d{2}", date): + # Then it is in YYYY-MM format + date_object = Date.fromisoformat(f"{date}-01") + elif re.fullmatch(r"\d{4}", date): + # Then it is in YYYY format + date_object = Date.fromisoformat(f"{date}-01-01") + elif date == "present": + date_object = Date.today() + else: + raise ValueError( + "This is not a valid date! Please use either YYYY-MM-DD, YYYY-MM, or" + " YYYY format." + ) + + return date_object + + +def format_date(date: Date) -> str: + """Formats a `Date` object to a string in the following format: "Jan. 2021". + + It uses month abbreviations, taken from + [Yale University Library](https://web.library.yale.edu/cataloging/months). + + Example: + ```python + format_date(Date(2024, 5, 1)) + ``` + will return + + `#!python "May 2024"` + + Args: + date (Date): The date to format. + + Returns: + str: The formatted date. + """ + # Month abbreviations, + # taken from: https://web.library.yale.edu/cataloging/months + abbreviations_of_months = [ + "Jan.", + "Feb.", + "Mar.", + "Apr.", + "May", + "June", + "July", + "Aug.", + "Sept.", + "Oct.", + "Nov.", + "Dec.", + ] + + month = int(date.strftime("%m")) + month_abbreviation = abbreviations_of_months[month - 1] + year = date.strftime(format="%Y") + date_string = f"{month_abbreviation} {year}" + + return date_string + + +class RenderCVBaseModel(pydantic.BaseModel): + """This class is the parent class of all the data models in RenderCV. It has only + one difference from the default `pydantic.BaseModel`: It raises an error if an + unknown key is provided in the input file. + """ + + model_config = pydantic.ConfigDict(extra="forbid", validation_error_cause=True) + + +# ====================================================================================== +# Entry models: ======================================================================== +# ====================================================================================== + + +class EntryBase(RenderCVBaseModel): + """This class is the parent class of some of the entry types. It is being used + because some of the entry types have common fields like dates, highlights, location, + etc. + """ + + start_date: Optional[int | RenderCVDate] = pydantic.Field( + default=None, + title="Start Date", + description=( + "The start date of the event in YYYY-MM-DD, YYYY-MM, or YYYY format." + ), + examples=["2020-09-24"], + json_schema_extra={"default": "2000-01-01"}, + ) + end_date: Optional[Literal["present"] | int | RenderCVDate] = pydantic.Field( + default=None, + title="End Date", + description=( + "The end date of the event in YYYY-MM-DD, YYYY-MM, or YYYY format. If the" + ' event is still ongoing, then type "present" or provide only the start' + " date." + ), + examples=["2020-09-24", "present"], + json_schema_extra={"default": "2020-01-01"}, + ) + date: Optional[RenderCVDate | int | str] = pydantic.Field( + default=None, + title="Date", + description=( + "If the event is a one-day event, then this field should be filled in" + " YYYY-MM-DD format. If the event is a multi-day event, then the start date" + " and end date should be provided instead. All of them can't be provided at" + " the same time." + ), + examples=["2020-09-24", "My Custom Date"], + json_schema_extra={"default": "Custom Date or 2020-01-01"}, + ) + highlights: Optional[list[str]] = pydantic.Field( + default=None, + title="Highlights", + description="The highlights of the event as a list of strings.", + examples=["Did this.", "Did that."], + ) + location: Optional[str] = pydantic.Field( + default=None, + title="Location", + description="The location of the event.", + examples=["Istanbul, Türkiye"], + ) + + @pydantic.model_validator( + mode="after", + ) # type: ignore + @classmethod + def check_dates(cls, model: "EntryBase") -> "EntryBase": + """ + Check if the dates are provided correctly and do the necessary adjustments. + """ + date_is_provided = False + start_date_is_provided = False + end_date_is_provided = False + if model.date is not None: + date_is_provided = True + if model.start_date is not None: + start_date_is_provided = True + if model.end_date is not None: + end_date_is_provided = True + + if date_is_provided: + try: + date_object = get_date_object(model.date) # type: ignore + except ValueError: + # Then it is a custom date string (e.g., "My Custom Date") + pass + else: + today_object = Date.today() + if date_object > today_object: + raise ValueError( + '"date" cannot be in the future!', + "date", # this is the location of the error + model.date, # this is value of the error + ) + + elif start_date_is_provided and not end_date_is_provided: + model.end_date = "present" + + elif not start_date_is_provided and end_date_is_provided: + raise ValueError( + '"end_date" is provided in of the entries, but "start_date" is not.' + ' Either provide both "start_date" and "end_date" or provide "date".', + "start_date", # this is the location of the error + "", # this supposed to be the value of the error + ) + + if model.start_date is not None and model.end_date is not None: + try: + end_date = get_date_object(model.end_date) + except ValueError as e: + raise ValueError(str(e), "end_date", str(model.end_date)) + + try: + start_date = get_date_object(model.start_date) + except ValueError as e: + raise ValueError(str(e), "start_date", str(model.start_date)) + + if start_date > end_date: + raise ValueError( + '"start_date" can not be after "end_date"!', + "start_date", # this is the location of the error + str(model.start_date), # this is value of the error + ) + elif end_date > Date.today(): + raise ValueError( + '"end_date" cannot be in the future!', + "end_date", # this is the location of the error + str(model.end_date), # this is value of the error + ) + + return model + + @functools.cached_property + def date_string(self) -> str: + """ + Return a date string based on the `date`, `start_date`, and `end_date` fields. + + Example: + ```python + entry = dm.EntryBase(start_date=2020-10-11, end_date=2021-04-04).date_string + ``` + will return: + `#!python "2020-10-11 to 2021-04-04"` + """ + if self.date is not None: + try: + date_object = get_date_object(self.date) + date_string = format_date(date_object) + except ValueError: + # Then it is a custom date string (e.g., "My Custom Date") + date_string = str(self.date) + + elif self.start_date is not None and self.end_date is not None: + if isinstance(self.start_date, int): + # Then it means only the year is provided + start_date = str(self.start_date) + else: + # Then it means start_date is either in YYYY-MM-DD or YYYY-MM format + date_object = get_date_object(self.start_date) + start_date = format_date(date_object) + + if self.end_date == "present": + end_date = "present" + elif isinstance(self.end_date, int): + # Then it means only the year is provided + end_date = str(self.end_date) + else: + # Then it means end_date is either in YYYY-MM-DD or YYYY-MM format + date_object = get_date_object(self.end_date) + end_date = format_date(date_object) + + date_string = f"{start_date} to {end_date}" + + else: + # Neither date, start_date, nor end_date is provided, so return an empty + # string: + date_string = "" + + return date_string + + @functools.cached_property + def date_string_only_years(self) -> str: + """ + Return a date string that only contains years based on the `date`, `start_date`, + and `end_date` fields. + + Example: + ```python + entry = dm.EntryBase(start_date=2020-10-11, end_date=2021-04-04).date_string + ``` + will return: + `#!python "2020 to 2021"` + """ + if self.date is not None: + try: + date_object = get_date_object(self.date) + date_string = format_date(date_object) + except ValueError: + # Then it is a custom date string (e.g., "My Custom Date") + date_string = str(self.date) + + elif self.start_date is not None and self.end_date is not None: + if isinstance(self.start_date, int): + # Then it means only the year is provided + start_date = str(self.start_date) + else: + # Then it means start_date is either in YYYY-MM-DD or YYYY-MM format + date_object = get_date_object(self.start_date) + start_date = date_object.year + + if self.end_date == "present": + end_date = "present" + elif isinstance(self.end_date, int): + # Then it means only the year is provided + end_date = str(self.end_date) + else: + # Then it means end_date is either in YYYY-MM-DD or YYYY-MM format + date_object = get_date_object(self.end_date) + end_date = date_object.year + + date_string = f"{start_date} to {end_date}" + + else: + # Neither date, start_date, nor end_date is provided, so return an empty + # string: + date_string = "" + + return date_string + + @functools.cached_property + def time_span_string(self) -> str: + """ + Return a time span string based on the `date`, `start_date`, and `end_date` + fields. + + Example: + ```python + entry = dm.EntryBase(start_date=2020-01-01, end_date=2020-04-20).time_span + ``` + will return: + `#!python "4 months"` + """ + start_date = self.start_date + end_date = self.end_date + date = self.date + + if date is not None or (start_date is None and end_date is None): + # If only the date is provided, the time span is irrelevant. So, return an + # empty string. + return "" + + elif isinstance(start_date, int) or isinstance(end_date, int): + # Then it means one of the dates is year, so time span cannot be more + # specific than years. + start_year = get_date_object(start_date).year # type: ignore + end_year = get_date_object(end_date).year # type: ignore + + time_span_in_years = end_year - start_year + + if time_span_in_years < 2: + time_span_string = "1 year" + else: + time_span_string = f"{time_span_in_years} years" + + return time_span_string + + else: + # Then it means both start_date and end_date are in YYYY-MM-DD or YYYY-MM + # format. + end_date = get_date_object(end_date) # type: ignore + start_date = get_date_object(start_date) # type: ignore + + # calculate the number of days between start_date and end_date: + timespan_in_days = (end_date - start_date).days # type: ignore + + # calculate the number of years between start_date and end_date: + how_many_years = timespan_in_days // 365 + if how_many_years == 0: + how_many_years_string = None + elif how_many_years == 1: + how_many_years_string = "1 year" + else: + how_many_years_string = f"{how_many_years} years" + + # calculate the number of months between start_date and end_date: + how_many_months = round((timespan_in_days % 365) / 30) + if how_many_months <= 1: + how_many_months_string = "1 month" + else: + how_many_months_string = f"{how_many_months} months" + + # combine howManyYearsString and howManyMonthsString: + if how_many_years_string is None: + time_span_string = how_many_months_string + else: + time_span_string = f"{how_many_years_string} {how_many_months_string}" + + return time_span_string + + +class OneLineEntry(RenderCVBaseModel): + """This class is the data model of `OneLineEntry`.""" + + name: str = pydantic.Field( + title="Name", + description="The name of the entry. It will be shown as bold text.", + ) + details: str = pydantic.Field( + title="Details", + description="The details of the entry. It will be shown as normal text.", + ) + + +class NormalEntry(EntryBase): + """This class is the data model of `NormalEntry`.""" + + name: str = pydantic.Field( + title="Name", + description="The name of the entry. It will be shown as bold text.", + ) + + +class ExperienceEntry(EntryBase): + """This class is the data model of `ExperienceEntry`.""" + + company: str = pydantic.Field( + title="Company", + description="The company name. It will be shown as bold text.", + ) + position: str = pydantic.Field( + title="Position", + description="The position. It will be shown as normal text.", + ) + + +class EducationEntry(EntryBase): + """This class is the data model of `EducationEntry`.""" + + institution: str = pydantic.Field( + title="Institution", + description="The institution name. It will be shown as bold text.", + ) + area: str = pydantic.Field( + title="Area", + description="The area of study. It will be shown as normal text.", + ) + degree: Optional[str] = pydantic.Field( + default=None, + title="Degree", + description="The type of the degree.", + examples=["BS", "BA", "PhD", "MS"], + json_schema_extra={"default": "PhD"}, + ) + + +class PublicationEntry(RenderCVBaseModel): + """This class is the data model of `PublicationEntry`.""" + + title: str = pydantic.Field( + title="Title of the Publication", + description="The title of the publication. It will be shown as bold text.", + ) + authors: list[str] = pydantic.Field( + title="Authors", + description="The authors of the publication in order as a list of strings.", + ) + doi: str = pydantic.Field( + title="DOI", + description="The DOI of the publication.", + examples=["10.48550/arXiv.2310.03138"], + ) + date: int | RenderCVDate = pydantic.Field( + title="Publication Date", + description=( + "The date of the publication in YYYY-MM-DD, YYYY-MM, or YYYY format." + ), + examples=["2021-10-31", "2010"], + json_schema_extra={"default": "2020-01-01"}, + ) + journal: Optional[str] = pydantic.Field( + default=None, + title="Journal", + description="The journal or the conference name.", + ) + + @pydantic.field_validator("date") + @classmethod + def check_date(cls, date: int | RenderCVDate) -> int | RenderCVDate: + """Check if the date is in the past.""" + date_object = get_date_object(date) + if date_object > Date.today(): + raise ValueError("The publication date cannot be in the future!") + + return date + + @pydantic.field_validator("doi") + @classmethod + def check_doi(cls, doi: str) -> str: + """Check if the DOI exists in the DOI System.""" + # see https://stackoverflow.com/a/60671292/18840665 for the explanation of the + # next line: + ssl._create_default_https_context = ssl._create_unverified_context # type: ignore + + doi_url = f"http://doi.org/{doi}" + + try: + urlopen(doi_url) + except HTTPError as err: + if err.code == 404: + raise ValueError("DOI cannot be found in the DOI System!") + + return doi + + @functools.cached_property + def doi_url(self) -> str: + """Return the URL of the DOI.""" + return f"https://doi.org/{self.doi}" + + @functools.cached_property + def date_string(self) -> str: + """Return the date string of the publication.""" + if isinstance(self.date, int): + date_string = str(self.date) + else: + # Then it is a string + date_object = get_date_object(self.date) + date_string = format_date(date_object) + + return date_string + + +# ====================================================================================== +# Section models: ====================================================================== +# ====================================================================================== +# Each section data model has a field called `entry_type` and a field called `entries`. +# Since the same pydantic.Field object is used in all of the section models, it is +# defined as a separate variable and used in all of the section models: +entry_type_field_of_section_model = pydantic.Field( + title="Entry Type", + description="The type of the entries in the section.", +) +entries_field_of_section_model = pydantic.Field( + title="Entries", + description="The entries of the section. The format depends on the entry type.", +) + + +class SectionBase(RenderCVBaseModel): + """This class is the parent class of all the section types. It is being used + because all of the section types have a common field called `title`. + """ + + # Title is excluded from the JSON schema because this will be written by RenderCV + # depending on the key in the input file. + title: Optional[str] = pydantic.Field(default=None, exclude=True) + + +class SectionWithEducationEntries(SectionBase): + """This class is the data model of the section with `EducationEntry`s.""" + + entry_type: Literal["EducationEntry"] = entry_type_field_of_section_model + entries: list[EducationEntry] = entries_field_of_section_model + + +class SectionWithExperienceEntries(SectionBase): + """This class is the data model of the section with `ExperienceEntry`s.""" + + entry_type: Literal["ExperienceEntry"] = entry_type_field_of_section_model + entries: list[ExperienceEntry] = entries_field_of_section_model + + +class SectionWithNormalEntries(SectionBase): + """This class is the data model of the section with `NormalEntry`s.""" + + entry_type: Literal["NormalEntry"] = entry_type_field_of_section_model + entries: list[NormalEntry] = entries_field_of_section_model + + +class SectionWithOneLineEntries(SectionBase): + """This class is the data model of the section with `OneLineEntry`s.""" + + entry_type: Literal["OneLineEntry"] = entry_type_field_of_section_model + entries: list[OneLineEntry] = entries_field_of_section_model + + +class SectionWithPublicationEntries(SectionBase): + """This class is the data model of the section with `PublicationEntry`s.""" + + entry_type: Literal["PublicationEntry"] = entry_type_field_of_section_model + entries: list[PublicationEntry] = entries_field_of_section_model + + +class SectionWithTextEntries(SectionBase): + """This class is the data model of the section with `TextEntry`s.""" + + entry_type: Literal["TextEntry"] = entry_type_field_of_section_model + entries: list[str] = entries_field_of_section_model + + +# Create a custom type called Section: +# It is a union of all the section types and the correct section type is determined by +# the entry_type field, thanks Pydantic's discriminator feature. +# See https://docs.pydantic.dev/2.5/concepts/fields/#discriminator for more information +# about discriminators. +Section = Annotated[ + SectionWithEducationEntries + | SectionWithExperienceEntries + | SectionWithNormalEntries + | SectionWithOneLineEntries + | SectionWithPublicationEntries + | SectionWithTextEntries, + pydantic.Field( + discriminator="entry_type", + ), +] + + +def get_entry_and_section_type( + entry: ( + dict[str, Any] + | EducationEntry + | ExperienceEntry + | PublicationEntry + | NormalEntry + | OneLineEntry + | str + ), +) -> tuple[ + str, + Type[ + SectionWithTextEntries + | SectionWithOneLineEntries + | SectionWithExperienceEntries + | SectionWithEducationEntries + | SectionWithPublicationEntries + | SectionWithNormalEntries + ], +]: + """Determine the entry and section type based on the entry. + + Args: + entry (dict[str, Any] | EducationEntry | ExperienceEntry | PublicationEntry | NormalEntry | OneLineEntry | str): The entry to determine the type. + Returns: + tuple[str, Type[SectionWithTextEntries | SectionWithOneLineEntries | SectionWithExperienceEntries | SectionWithEducationEntries | SectionWithPublicationEntries | SectionWithNormalEntries]]: The entry type and the section type. + """ + if isinstance(entry, dict): + if "details" in entry: + entry_type = "OneLineEntry" + section_type = SectionWithOneLineEntries + elif "company" in entry or "position" in entry: + entry_type = "ExperienceEntry" + section_type = SectionWithExperienceEntries + elif "institution" in entry or "area" in entry or "degree" in entry: + entry_type = "EducationEntry" + section_type = SectionWithEducationEntries + elif "title" in entry or "authors" in entry or "doi" in entry: + entry_type = "PublicationEntry" + section_type = SectionWithPublicationEntries + elif "name" in entry: + entry_type = "NormalEntry" + section_type = SectionWithNormalEntries + else: + raise ValueError("The entry is not provided correctly.") + else: + if isinstance(entry, str): + entry_type = "TextEntry" + section_type = SectionWithTextEntries + elif isinstance(entry, OneLineEntry): + entry_type = "OneLineEntry" + section_type = SectionWithOneLineEntries + elif isinstance(entry, ExperienceEntry): + entry_type = "ExperienceEntry" + section_type = SectionWithExperienceEntries + elif isinstance(entry, EducationEntry): + entry_type = "EducationEntry" + section_type = SectionWithEducationEntries + elif isinstance(entry, PublicationEntry): + entry_type = "PublicationEntry" + section_type = SectionWithPublicationEntries + elif isinstance(entry, NormalEntry): # type: ignore + entry_type = "NormalEntry" + section_type = SectionWithNormalEntries + else: + raise RuntimeError( + "This error shouldn't have been raised. Please open an issue on GitHub." + ) + + return entry_type, section_type + + +def validate_section_input( + sections_input: Section | list[Any], +) -> Section | list[Any]: + """Validate a SectionInput object and raise an error if it is not valid. + + Sections input is very complex. It is either a `Section` object or a list of + entries. Since there are multiple entry types, it is not possible to validate it + directly. This function looks at the entry list's first element and determines the + section's entry type based on the first element. Then, it validates the rest of the + list based on the determined entry type. If it is a `Section` object, then it + validates it directly. + + Args: + sections_input (Section | list[Any]): The sections input to validate. + Returns: + Section | list[Any]: The validated sections input. + """ + if isinstance(sections_input, list): + # find the entry type based on the first identifiable entry: + entry_type = None + section_type = None + for entry in sections_input: + try: + entry_type, section_type = get_entry_and_section_type(entry) + break + except ValueError: + pass + + if entry_type is None or section_type is None: + raise ValueError( + "RenderCV couldn't match this section with any entry type! Please check" + " the entries and make sure they are provided correctly.", + "", # this is the location of the error + "", # this is value of the error + ) + + test_section = { + "title": "Test Section", + "entry_type": entry_type, + "entries": sections_input, + } + + try: + section_type.model_validate( + test_section, + context={"section": "test"}, + ) + except pydantic.ValidationError as e: + new_error = ValueError( + "There are problems with the entries. RenderCV detected the entry type" + f" of this section to be {entry_type}! The problems are shown below.", + "", # this is the location of the error + "", # this is value of the error + ) + raise new_error from e + + return sections_input + + +# Create a custom type called SectionInput so that it can be validated with +# `validate_section_input` function. +SectionInput = Annotated[ + list[ + EducationEntry + | ExperienceEntry + | PublicationEntry + | NormalEntry + | OneLineEntry + | str + ], + pydantic.BeforeValidator(validate_section_input), +] + + +# ====================================================================================== +# Full RenderCV data models: =========================================================== +# ====================================================================================== + +url_validator = pydantic.TypeAdapter(pydantic.HttpUrl) # type: ignore + + +class SocialNetwork(RenderCVBaseModel): + """This class is the data model of a social network.""" + + network: Literal[ + "LinkedIn", "GitHub", "Instagram", "Orcid", "Mastodon", "Twitter" + ] = pydantic.Field( + title="Social Network", + description="The social network name.", + ) + username: str = pydantic.Field( + title="Username", + description="The username of the social network. The link will be generated.", + ) + + @pydantic.model_validator(mode="after") # type: ignore + @classmethod + def check_networks(cls, model: "SocialNetwork") -> "SocialNetwork": + """Check if the `SocialNetwork` is provided correctly.""" + if model.network == "Mastodon": + if not model.username.startswith("@"): + raise ValueError("Mastodon username should start with '@'!", "username") + if model.username.count("@") > 2: + raise ValueError( + "Mastodon username should contain only two '@'!", "username" + ) + + return model + + @pydantic.model_validator(mode="after") # type: ignore + @classmethod + def validate_urls(cls, model: "SocialNetwork") -> "SocialNetwork": + """Validate the URLs of the social networks.""" + url = model.url + + url_validator.validate_strings(url) + + return model + + @functools.cached_property + def url(self) -> str: + """Return the URL of the social network.""" + url_dictionary = { + "LinkedIn": "https://linkedin.com/in/", + "GitHub": "https://github.com/", + "Instagram": "https://instagram.com/", + "Orcid": "https://orcid.org/", + "Mastodon": "https://mastodon.social/", + "Twitter": "https://twitter.com/", + } + url = url_dictionary[self.network] + self.username + + return url + + +class CurriculumVitae(RenderCVBaseModel): + """This class is the data model of the CV.""" + + name: Optional[str] = pydantic.Field( + default=None, + title="Name", + description="The name of the person.", + ) + label: Optional[str] = pydantic.Field( + default=None, + title="Label", + description="The label of the person.", + ) + location: Optional[str] = pydantic.Field( + default=None, + title="Location", + description="The location of the person. This is not rendered currently.", + ) + email: Optional[pydantic.EmailStr] = pydantic.Field( + default=None, + title="Email", + description="The email of the person.", + ) + phone: Optional[pydantic_phone_numbers.PhoneNumber] = pydantic.Field( + default=None, + title="Phone", + description="The phone number of the person.", + ) + website: Optional[pydantic.HttpUrl] = pydantic.Field( + default=None, + title="Website", + description="The website of the person.", + ) + social_networks: Optional[list[SocialNetwork]] = pydantic.Field( + default=None, + title="Social Networks", + description="The social networks of the person.", + ) + sections_input: Optional[dict[str, SectionInput]] = pydantic.Field( + default=None, + title="Sections", + description="The sections of the CV.", + alias="sections", + ) + + @functools.cached_property + def sections(self) -> list[Section]: + """Return all the sections of the CV with their titles.""" + sections: list[Section] = [] + if self.sections_input is not None: + for title, section_or_entries in self.sections_input.items(): + title = title.replace("_", " ").title() + + entry_type, section_type = get_entry_and_section_type( + section_or_entries[0] + ) + + section = section_type( + title=title, + entry_type=entry_type, # type: ignore + entries=section_or_entries, # type: ignore + ) + sections.append(section) + + return sections + + +# ====================================================================================== +# ====================================================================================== +# ====================================================================================== + +# Create a custom type called Design: +# It is a union of all the design options and the correct design option is determined by +# the theme field, thanks Pydantic's discriminator feature. +# See https://docs.pydantic.dev/2.5/concepts/fields/#discriminator for more information +# about discriminators. +RenderCVDesign = Annotated[ + ClassicThemeOptions | ModerncvThemeOptions | Sb2novThemeOptions, + pydantic.Field(discriminator="theme"), +] +rendercv_design_validator = pydantic.TypeAdapter(RenderCVDesign) +available_themes = ["classic", "moderncv", "sb2nov"] + + +class RenderCVDataModel(RenderCVBaseModel): + """This class binds both the CV and the design information together.""" + + cv: CurriculumVitae = pydantic.Field( + title="Curriculum Vitae", + description="The data of the CV.", + ) + design: RenderCVDesign | pydantic.json_schema.SkipJsonSchema[Any] = pydantic.Field( + default=ClassicThemeOptions(theme="classic"), + title="Design", + description=( + "The design information of the CV. The default is the classic theme." + ), + ) + + @pydantic.field_validator("design", mode="before") + @classmethod + def initialize_if_custom_theme_is_used( + cls, design: RenderCVDesign | Any + ) -> RenderCVDesign | Any: + """Initialize the custom theme if it is used and validate it. Otherwise, return + the built-in theme.""" + # `get_args` for an Annotated object returns the arguments when Annotated is + # used. The first argument is actually the union of the types, so we need to + # access the first argument to use isinstance function. + theme_data_model_types = get_args(RenderCVDesign)[0] + + if isinstance(design, theme_data_model_types): + # then it means RenderCVDataModel is already initialized with a design, so + # return it as is: + return design + elif design["theme"] in available_themes: # type: ignore + # then it means it's a built-in theme, but it is not initialized (validated) + # yet. So, validate and return it: + return rendercv_design_validator.validate_python(design) + else: + theme_name: str = design["theme"] # type: ignore + if not isinstance(theme_name, str): + raise RuntimeError( + "This error shouldn't have been raised. Please open an issue on" + " GitHub." + ) + + # check if the theme name is valid: + if not theme_name.isalpha(): + raise ValueError( + "The custom theme name should contain only letters.", + "theme", # this is the location of the error + theme_name, # this is value of the error + ) + + # then it is a custom theme + custom_theme_folder = pathlib.Path(theme_name) + + # check if the custom theme folder exists: + if not custom_theme_folder.exists(): + raise ValueError( + f"The custom theme folder `{custom_theme_folder}` does not exist." + " It should be in the working directory as the input file.", + "", # this is the location of the error + theme_name, # this is value of the error + ) + + # check if all the necessary files are provided in the custom theme folder: + required_files = [ + "EducationEntry.j2.tex", # education entry template + "ExperienceEntry.j2.tex", # experience entry template + "NormalEntry.j2.tex", # normal entry template + "OneLineEntry.j2.tex", # one line entry template + "PublicationEntry.j2.tex", # publication entry template + "TextEntry.j2.tex", # text entry template + "SectionBeginning.j2.tex", # section beginning template + "SectionEnding.j2.tex", # section ending template + "Preamble.j2.tex", # preamble template + "Header.j2.tex", # header template + ] + + for file in required_files: + file_path = custom_theme_folder / file + if not file_path.exists(): + raise ValueError( + f"You provided a custom theme, but the file `{file}` is not" + f" found in the folder `{custom_theme_folder}`.", + "", # this is the location of the error + theme_name, # this is value of the error + ) + + # import __init__.py file from the custom theme folder if it exists: + path_to_init_file = pathlib.Path(f"{theme_name}/__init__.py") + + if path_to_init_file.exists(): + spec = importlib.util.spec_from_file_location( + "", # this is somehow not required + path_to_init_file, + ) + if spec is None: + raise RuntimeError( + "This error shouldn't have been raised. Please open an issue on" + " GitHub." + ) + + theme_module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(theme_module) # type: ignore + + ThemeDataModel = getattr( + theme_module, f"{theme_name.title()}ThemeOptions" # type: ignore + ) + + # initialize and validate the custom theme data model: + theme_data_model = ThemeDataModel(**design) + else: + # Then it means there is no __init__.py file in the custom theme folder. + # So, create a dummy data model and use that instead. + class ThemeOptionsAreNotProvided(RenderCVBaseModel): + theme: str = theme_name + + theme_data_model = ThemeOptionsAreNotProvided(theme=theme_name) + + return theme_data_model + + +def read_input_file( + file_path: pathlib.Path, +) -> RenderCVDataModel: + """Read the input file and return two instances of RenderCVDataModel. The first + instance is the data model with $\\LaTeX$ strings and the second instance is the data + model with markdown strings. + + Args: + file_path (str): The path to the input file. + + Returns: + tuple[RenderCVDataModel, RenderCVDataModel]: The data models with $\\LaTeX$ and + markdown strings. + """ + # check if the file exists: + if not file_path.exists(): + raise FileNotFoundError( + f"The input file [magenta]{file_path}[/magenta] doesn't exist!" + ) + + # check the file extension: + accepted_extensions = [".yaml", ".yml", ".json", ".json5"] + if file_path.suffix not in accepted_extensions: + user_friendly_accepted_extensions = [ + f"[green]{ext}[/green]" for ext in accepted_extensions + ] + user_friendly_accepted_extensions = ", ".join(user_friendly_accepted_extensions) + raise ValueError( + "The input file should have one of the following extensions:" + f" {user_friendly_accepted_extensions}. The input file is" + f" [magenta]{file_path}[/magenta]." + ) + + file_content = file_path.read_text(encoding="utf-8") + input_as_dictionary: dict[str, Any] = ruamel.yaml.YAML().load(file_content) # type: ignore + + # validate the parsed dictionary by creating an instance of RenderCVDataModel: + rendercv_data_model = RenderCVDataModel(**input_as_dictionary) + + return rendercv_data_model + + +def get_a_sample_data_model(name: str = "John Doe") -> RenderCVDataModel: + """Return a sample data model for new users to start with. + + Args: + name (str, optional): The name of the person. Defaults to "John Doe". + Returns: + RenderCVDataModel: A sample data model. + """ + sections = { + "summary": [ + ( + "This is an example resume to showcase the capabilities of the" + " open-source LaTeX CV generator," + " [RenderCV](https://github.com/sinaatalay/rendercv). A substantial" + " part of the content is taken from" + " [here](https://www.careercup.com/resume), where a *clean and tidy CV*" + " pattern is proposed by **Gayle L. McDowell**." + ), + ], + "education": [ + EducationEntry( + institution="University of Pennsylvania", + area="Computer Science", + degree="BS", + start_date="2000-09", + end_date="2005-05", + highlights=[ + "GPA: 3.9/4.0 ([Transcript](https://example.com))", + ( + "**Coursework:** Software Foundations, Computer" + " Architecture, Algorithms, Artificial Intelligence, Comparison" + " of Learning Algorithms, Computational Theory." + ), + ], + ), + ], + "employment": [ + ExperienceEntry( + company="Apple Computer", + position="Software Engineer, Intern", + start_date="2004-06", + end_date="2004-08", + location="CA, USA", + highlights=[ + ( + "Reduced time to render the user's buddy list by 75% by" + " implementing prediction algorithm." + ), + ( + "Implemented iChat integration with OS X Spotlight Search by" + " creating tool which extracts metadata from saved chat" + " transcripts and provides metadata to a system-wide search" + " database." + ), + ( + "Redesigned chat file format and implemented backwards" + " compatibility for search." + ), + ], + ), + ExperienceEntry( + company="Microsoft Corporation", + position="Lead Student Ambassador", + start_date="2003-09", + end_date="2005-04", + location="WA, USA", + highlights=[ + ( + "Promoted to Lead Student Ambassador in Fall 2004, supervised" + " 10 - 15 Student Ambassadors." + ), + ( + "Created and taught Computer Science course, CSE 099: Software" + " Design and Development." + ), + ], + ), + ExperienceEntry( + company="University of Pennsylvania", + position="Head Teaching Assistant", + start_date="2001-10", + end_date="2005-05", + location="PA, USA", + highlights=[ + ( + "Implemented a user interface for the VS open file switcher" + " (ctrl-tab) and extended it to tool windows." + ), + ( + "Created service to provide gradient across VS and VS add-ins." + " Optimized service via caching." + ), + "Programmer Productivity Research Center (Summers 2001, 2002)", + ( + "Built app to compute similarity of all methods in a code base," + " reduced time from $\\mathcal{O}(n^2)$ to $\\mathcal{O}(n" + " \\log n)$. " + ), + ( + "Created test case generation tool which creates random XML" + " docs from XML Schema." + ), + ], + ), + ExperienceEntry( + company="Microsoft Corporation", + position="Software Design Engineer, Intern", + start_date="2003-06", + end_date="2003-08", + location="WA, USA", + highlights=[ + ( + "Promoted to Lead Student Ambassador in Fall 2004, supervised" + " 10 - 15 Student Ambassadors." + ), + ( + "Created and taught Computer Science course, CSE 099: Software" + " Design and Development." + ), + ], + ), + ], + "publications": [ + PublicationEntry( + title=( + "Magneto-Thermal Thin Shell Approximation for 3D Finite Element" + " Analysis of No-Insulation Coils" + ), + authors=[ + "Albert Smith", + name, + "Jane Derry", + "Harry Tom", + "Anotherfirstname Andsurname", + ], + date="2004-01", + doi="10.1109/TASC.2023.3340648", + ) + ], + "projects": [ + NormalEntry( + name="Multi-User Drawing Tool", + date="2004", + highlights=[ + ( + "Developed an electronic classroom where multiple users can" + ' view and simultaneously draw on a "chalkboard" with each' + " person's edits synchronized." + ), + "Used C++ and MFC.", + ], + ), + NormalEntry( + name="Synchronized Calendar", + start_date="2003", + end_date="2004", + highlights=[ + ( + "Developed a desktop calendar with globally shared and" + " synchronized calendars, allowing users to schedule meetings" + " with other users." + ), + "Used C#.NET, SQL and XML.", + ], + ), + NormalEntry( + name="Operating System", + date="2002", + highlights=[ + ( + "Developed a UNIX-style OS with scheduler, file system, text" + " editor and calculator." + ), + "Used C.", + ], + ), + ], + "additional_experience_and_awards": [ + OneLineEntry( + name="Instructor (2003 - 2005)", + details="Taught two full-credit Computer Science courses.", + ), + OneLineEntry( + name="Third Prize, Senior Design Projects", + details=( + "Awarded 3rd prize for Synchronized Calendar project, out of 100" + " projects." + ), + ), + ], + "technologies": [ + OneLineEntry( + name="Languages", + details="C++, C, Java, Objective-C, C#.NET, SQL, JavaScript", + ), + OneLineEntry( + name="Software", + details=( + "Visual Studio, Microsoft SQL Server, Eclipse, XCode, Interface" + " Builder" + ), + ), + ], + } + + cv = CurriculumVitae( + name=name, + location="Your Location", + email="youremail@yourdomain.com", + phone="+905419999999", # type: ignore + website="https://yourwebsite.com", # type: ignore + social_networks=[ + SocialNetwork(network="LinkedIn", username="yourusername"), + SocialNetwork(network="GitHub", username="yourusername"), + ], + sections=sections, # type: ignore + ) + + # design = ClassicThemeOptions(theme="classic", show_timespan_in=["Employment"]) + design = Sb2novThemeOptions(theme="sb2nov") + + return RenderCVDataModel(cv=cv, design=design) + + +def generate_json_schema() -> dict[str, Any]: + """Generate the JSON schema of RenderCV. + + JSON schema is generated for the users to make it easier for them to write the input + file. The JSON Schema of RenderCV is saved in the `docs` directory of the repository + and distributed to the users with the + [JSON Schema Store](https://www.schemastore.org/). + + Returns: + dict: The JSON schema of RenderCV. + """ + + class RenderCVSchemaGenerator(pydantic.json_schema.GenerateJsonSchema): + def generate(self, schema, mode="validation"): # type: ignore + json_schema = super().generate(schema, mode=mode) + + # Basic information about the schema: + json_schema["title"] = "RenderCV" + json_schema["description"] = "RenderCV data model." + json_schema["$id"] = ( + "https://raw.githubusercontent.com/sinaatalay/rendercv/main/schema.json" + ) + json_schema["$schema"] = "http://json-schema.org/draft-07/schema#" + + # Loop through $defs and remove docstring descriptions and fix optional + # fields + for _, value in json_schema["$defs"].items(): + # Don't allow additional properties + value["additionalProperties"] = False + + # If a type is optional, then Pydantic sets the type to a list of two + # types, one of which is null. The null type can be removed since we + # already have the required field. Moreover, we would like to warn + # users if they provide null values. They can remove the fields if they + # don't want to provide them. + null_type_dict = {} + null_type_dict["type"] = "null" + for field in value["properties"].values(): + if "anyOf" in field: + if ( + len(field["anyOf"]) == 2 + and null_type_dict in field["anyOf"] + ): + field["allOf"] = [field["anyOf"][0]] + del field["anyOf"] + else: + field["oneOf"] = field["anyOf"] + del field["anyOf"] + + # In date field, we both accept normal strings and Date objects. They + # are both strings, therefore, if user provides a Date object, then + # JSON schema will complain that it matches two different types. + # Remember that all of the anyOfs are changed to oneOfs. Only one of + # the types can be matched. Therefore, we remove the first type, which + # is the string with the YYYY-MM-DD format. + if ( + "date" in value["properties"] + and "oneOf" in value["properties"]["date"] + ): + del value["properties"]["date"]["oneOf"][0] + + return json_schema + + schema = RenderCVDataModel.model_json_schema( + schema_generator=RenderCVSchemaGenerator + ) + + return schema + + +def generate_json_schema_file(json_schema_path: pathlib.Path): + """Generate the JSON schema of RenderCV and save it to a file. + + Args: + json_schema_path (pathlib.Path): The path to save the JSON schema. + """ + schema = generate_json_schema() + schema_json = json.dumps(schema, indent=2) + json_schema_path.write_text(schema_json) diff --git a/rendercv/renderer.py b/rendercv/renderer.py new file mode 100644 index 0000000..0b2f1a9 --- /dev/null +++ b/rendercv/renderer.py @@ -0,0 +1,1016 @@ +""" +This module contains functions and classes for generating a $\\LaTeX$ file from the data +model and rendering the $\\LaTeX$ file to produce a PDF. + +The $\\LaTeX$ files are generated with +[Jinja2](https://jinja.palletsprojects.com/en/3.1.x/) templates. Then, the $\\LaTeX$ +file is rendered into a PDF with [TinyTeX](https://yihui.org/tinytex/), a $\\LaTeX$ +distribution. +""" + +import subprocess +import re +import os +import pathlib +import importlib.resources +import shutil +import sys +import copy +from datetime import date as Date +from typing import Optional, Literal, Any + +import jinja2 +import markdown + +from . import data_models as dm + + +class TemplatedFile: + """This class is a base class for LaTeXFile and MarkdownFile classes. It contains + the common methods and attributes for both classes. These classes are used to + generate the $\\LaTeX$ and Markdown files with the data model and Jinja2 templates. + + Args: + data_model (dm.RenderCVDataModel): The data model. + environment (jinja2.Environment): The Jinja2 environment. + """ + + def __init__( + self, + data_model: dm.RenderCVDataModel, + environment: jinja2.Environment, + ): + self.cv = data_model.cv + self.design = data_model.design + self.environment = environment + + def template( + self, + theme_name: str, + template_name: Literal[ + "EducationEntry", + "ExperienceEntry", + "NormalEntry", + "PublicationEntry", + "OneLineEntry", + "TextEntry", + "Header", + "Preamble", + "SectionBeginning", + "SectionEnding", + ], + extension: str, + entry: Optional[ + dm.EducationEntry + | dm.ExperienceEntry + | dm.NormalEntry + | dm.PublicationEntry + | dm.OneLineEntry + | str # TextEntry + ] = None, + section_title: Optional[str] = None, + is_first_entry: Optional[bool] = None, + ) -> str: + """Template one of the files in the `themes` directory. + + Args: + template_name (str): The name of the template file. + entry (Optional[dm.EducationEntry, dm.ExperienceEntry, dm.NormalEntry,dm.PublicationEntry, dm.OneLineEntry, str]): The data model of the entry. + section_title (Optional[str]): The title of the section. + is_first_entry (Optional[bool]): Whether the entry is the first one in the + section. + + Returns: + str: The templated file. + """ + template = self.environment.get_template( + f"{theme_name}/{template_name}.j2.{extension}" + ) + + # Loop through the entry attributes and make them "" if they are None: + # This is necessary because otherwise they will be templated as "None" since + # it's the string representation of None. + + # Only don't touch the date fields, because only date_string is called and + # setting dates to "" will cause problems. + fields_to_ignore = ["start_date", "end_date", "date"] + + if entry is not None and not isinstance(entry, str): + entry_dictionary = entry.model_dump() + for key, value in entry_dictionary.items(): + if value is None and key not in fields_to_ignore: + entry.__setattr__(key, "") + + # The arguments of the template can be used in the template file: + result = template.render( + cv=self.cv, + design=self.design, + entry=entry, + section_title=section_title, + today=Date.today().strftime("%B %Y"), + is_first_entry=is_first_entry, + ) + + return result + + def get_full_code(self, main_template_name: str, **kwargs) -> str: + """Combine all the templates to get the full code of the file.""" + main_template = self.environment.get_template(main_template_name) + latex_code = main_template.render( + **kwargs, + ) + return latex_code + + +class LaTeXFile(TemplatedFile): + """This class represents a $\\LaTeX$ file. It generates the $\\LaTeX$ code with the + data model and Jinja2 templates. It inherits from the TemplatedFile class. + """ + + def __init__( + self, + data_model: dm.RenderCVDataModel, + environment: jinja2.Environment, + ): + transformed_sections = transform_markdown_sections_to_latex_sections( + copy.deepcopy(data_model.cv.sections_input) + ) + data_model.cv.sections_input = transformed_sections + super().__init__(data_model, environment) + + def render_templates(self) -> tuple[str, str, list[tuple[str, list[str], str]]]: + """Render and return all the templates for the $\\LaTeX$ file. + + Returns: + Tuple[str, str, List[Tuple[str, List[str], str]]]: The preamble, header, and + sections of the $\\LaTeX$ file. + """ + # Template the preamble, header, and sections: + preamble = self.template("Preamble") + header = self.template("Header") + sections: list[tuple[str, list[str], str]] = [] + for section in self.cv.sections: + section_beginning = self.template( + "SectionBeginning", section_title=section.title + ) + entries: list[str] = [] + for i, entry in enumerate(section.entries): + if i == 0: + is_first_entry = True + else: + is_first_entry = False + entries.append( + self.template( + section.entry_type, + entry=entry, + section_title=section.title, + is_first_entry=is_first_entry, + ) + ) + section_ending = self.template("SectionEnding", section_title=section.title) + sections.append((section_beginning, entries, section_ending)) + + return preamble, header, sections + + def template( + self, + template_name: Literal[ + "EducationEntry", + "ExperienceEntry", + "NormalEntry", + "PublicationEntry", + "OneLineEntry", + "TextEntry", + "Header", + "Preamble", + "SectionBeginning", + "SectionEnding", + ], + entry: Optional[ + dm.EducationEntry + | dm.ExperienceEntry + | dm.NormalEntry + | dm.PublicationEntry + | dm.OneLineEntry + | str # TextEntry + ] = None, + section_title: Optional[str] = None, + is_first_entry: Optional[bool] = None, + ) -> str: + """Template one of the files in the `themes` directory. + + Args: + template_name (str): The name of the template file. + entry (Optional[dm.EducationEntry, dm.ExperienceEntry, dm.NormalEntry,dm.PublicationEntry, dm.OneLineEntry, str]): The data model of the entry. + section_title (Optional[str]): The title of the section. + is_first_entry (Optional[bool]): Whether the entry is the first one in the section. + + Returns: + str: The templated file. + """ + result = super().template( + self.design.theme, + template_name, + "tex", + entry, + section_title, + is_first_entry, + ) + return result + + def get_latex_code(self): + """Get the $\\LaTeX$ code of the file. + + Returns: + str: The $\\LaTeX$ code. + """ + preamble, header, sections = self.render_templates() + latex_code: str = self.get_full_code( + "main.j2.tex", + preamble=preamble, + header=header, + sections=sections, + ) + return latex_code + + def generate_latex_file(self, file_path: pathlib.Path): + """Write the $\\LaTeX$ code to a file.""" + file_path.write_text(self.get_latex_code(), encoding="utf-8") + + +class MarkdownFile(TemplatedFile): + """This class represents a Markdown file. It generates the Markdown code with the + data model and Jinja2 templates. It inherits from the TemplatedFile class. Markdown + files are generated to produce a PDF which can be copy-pasted to + [Grammarly](https://app.grammarly.com/) for proofreading. + """ + + def render_templates(self): + """Render and return all the templates for the Markdown file. + + Returns: + tuple[str, List[Tuple[str, List[str]]]]: The header and sections of the Markdown file. + """ + # Template the header and sections: + header = self.template("Header") + sections: list[tuple[str, list[str]]] = [] + for section in self.cv.sections: + section_beginning = self.template( + "SectionBeginning", section_title=section.title + ) + entries: list[str] = [] + for i, entry in enumerate(section.entries): + if i == 0: + is_first_entry = True + else: + is_first_entry = False + entries.append( + self.template( + section.entry_type, + entry=entry, + section_title=section.title, + is_first_entry=is_first_entry, + ) + ) + sections.append((section_beginning, entries)) + + result: tuple[str, list[tuple[str, list[str]]]] = (header, sections) + return result + + def template( + self, + template_name: Literal[ + "EducationEntry", + "ExperienceEntry", + "NormalEntry", + "PublicationEntry", + "OneLineEntry", + "TextEntry", + "Header", + "Preamble", + "SectionBeginning", + "SectionEnding", + ], + entry: Optional[ + dm.EducationEntry + | dm.ExperienceEntry + | dm.NormalEntry + | dm.PublicationEntry + | dm.OneLineEntry + | str # TextEntry + ] = None, + section_title: Optional[str] = None, + is_first_entry: Optional[bool] = None, + ) -> str: + """Template one of the files in the `themes` directory. + + Args: + template_name (str): The name of the template file. + entry (Optional[dm.EducationEntry, dm.ExperienceEntry, dm.NormalEntry,dm.PublicationEntry, dm.OneLineEntry, str]): The data model of the entry. + section_title (Optional[str]): The title of the section. + is_first_entry (Optional[bool]): Whether the entry is the first one in the section. + + Returns: + str: The templated file. + """ + result = super().template( + "markdown", + template_name, + "md", + entry, + section_title, + is_first_entry, + ) + return result + + def get_markdown_code(self): + """Get the Markdown code of the file. + + Returns: + str: The Markdown code. + """ + header, sections = self.render_templates() + markdown_code: str = self.get_full_code( + "main.j2.md", + header=header, + sections=sections, + ) + return markdown_code + + def generate_markdown_file(self, file_path: pathlib.Path): + """Write the Markdown code to a file.""" + file_path.write_text(self.get_markdown_code(), encoding="utf-8") + + +def escape_latex_characters(string: str) -> str: + """Escape $\\LaTeX$ characters in a string. + + This function is called during the reading of the input file. Before the validation + process, each input field's special $\\LaTeX$ characters are escaped. + + Example: + ```python + escape_latex_characters("This is a # string.") + ``` + will return: + `#!python "This is a \\# string."` + """ + + # Dictionary of escape characters: + escape_characters = { + "#": "\\#", + # "$": "\\$", # Don't escape $ as it is used for math mode + "%": "\\%", + "&": "\\&", + "~": "\\textasciitilde{}", + # "_": "\\_", # Don't escape _ as it is used for math mode + # "^": "\\textasciicircum{}", # Don't escape ^ as it is used for math mode + } + + # Don't escape links as hyperref package will do it automatically: + + # Find all the links in the sentence: + links = re.findall(r"\[.*?\]\(.*?\)", string) + + # Replace the links with a placeholder: + for i, link in enumerate(links): + string = string.replace(link, f"!!-link{i}-!!") + + # Loop through the letters of the sentence and if you find an escape character, + # replace it with its LaTeX equivalent: + copy_of_the_string = list(string) + for i, character in enumerate(copy_of_the_string): + if character in escape_characters: + new_character = escape_characters[character] + copy_of_the_string[i] = new_character + + string = "".join(copy_of_the_string) + # Replace the links with the original links: + for i, link in enumerate(links): + string = string.replace(f"!!-link{i}-!!", link) + + return string + + +def markdown_to_latex(markdown_string: str) -> str: + """Convert a markdown string to LaTeX. + + This function is called during the reading of the input file. Before the validation + process, each input field is converted from markdown to LaTeX. + + Example: + ```python + markdown_to_latex("This is a **bold** text with an [*italic link*](https://google.com).") + ``` + + will return: + + `#!python "This is a \\textbf{bold} text with a \\href{https://google.com}{\\textit{link}}."` + + Args: + markdown_string (str): The markdown string to convert. + + Returns: + str: The $\\LaTeX$ string. + """ + # convert links + links = re.findall(r"\[([^\]\[]*)\]\((.*?)\)", markdown_string) + if links is not None: + for link in links: + link_text = link[0] + link_url = link[1] + + old_link_string = f"[{link_text}]({link_url})" + new_link_string = "\\href{" + link_url + "}{" + link_text + "}" + + markdown_string = markdown_string.replace(old_link_string, new_link_string) + + # convert bold + bolds = re.findall(r"\*\*([^\*]*)\*\*", markdown_string) + if bolds is not None: + for bold_text in bolds: + old_bold_text = f"**{bold_text}**" + new_bold_text = "\\textbf{" + bold_text + "}" + + markdown_string = markdown_string.replace(old_bold_text, new_bold_text) + + # convert italic + italics = re.findall(r"\*([^\*]*)\*", markdown_string) + if italics is not None: + for italic_text in italics: + old_italic_text = f"*{italic_text}*" + new_italic_text = "\\textit{" + italic_text + "}" + + markdown_string = markdown_string.replace(old_italic_text, new_italic_text) + + # convert code + # not supported by rendercv currently + # codes = re.findall(r"`([^`]*)`", markdown_string) + # if codes is not None: + # for code_text in codes: + # old_code_text = f"`{code_text}`" + # new_code_text = "\\texttt{" + code_text + "}" + + # markdown_string = markdown_string.replace(old_code_text, new_code_text) + + latex_string = markdown_string + + return latex_string + + +def transform_markdown_sections_to_latex_sections( + sections: Optional[dict[str, dm.SectionInput]], +) -> Optional[dict[str, dm.SectionInput]]: + """ + Recursively loop through sections and convert all the markdown strings (user input + is in markdown format) to $\\LaTeX$ strings. Also, escape special $\\LaTeX$ + characters. + + Args: + sections (Optional[dict[str, dm.SectionInput]]): Sections with markdown strings. + Returns: + Optional[dict[str, dm.SectionInput]]: Sections with $\\LaTeX$ strings. + """ + if sections is None: + return None + + for key, value in sections.items(): + # loop through the list and apply markdown_to_latex and escape_latex_characters + # to each item: + transformed_list = [] + for entry in value: + if isinstance(entry, str): + # Then it means it's a TextEntry. + result = markdown_to_latex(escape_latex_characters(entry)) + transformed_list.append(result) + else: + # Then it means it's one of the other entries. + entry_as_dict = entry.model_dump() + for entry_key, value in entry_as_dict.items(): + if isinstance(value, str): + result = markdown_to_latex(escape_latex_characters(value)) + setattr(entry, entry_key, result) + elif isinstance(value, list): + for j, item in enumerate(value): + if isinstance(item, str): + value[j] = markdown_to_latex( + escape_latex_characters(item) + ) + setattr(entry, entry_key, value) + transformed_list.append(entry) + + sections[key] = transformed_list + + return sections + + +def replace_placeholders_with_actual_values( + string: str, placeholders: dict[str, Optional[str]] +) -> str: + """Replace the placeholders in a string with actual values. + + This function can be used as a Jinja2 filter in templates. + + Args: + string (str): The string with placeholders. + placeholders (dict[str, str]): The placeholders and their values. + Returns: + str: The string with actual values. + """ + for placeholder, value in placeholders.items(): + string = string.replace(placeholder, str(value)) + + return string + + +def make_matched_part_something( + value: str, something: str, match_str: Optional[str] = None +) -> str: + """Make the matched parts of the string something. If the match_str is None, the + whole string will be made something. + + Warning: + This function shouldn't be used directly. Use + [make_matched_part_bold](renderer.md#rendercv.rendering.make_matched_part_bold), + [make_matched_part_underlined](renderer.md#rendercv.rendering.make_matched_part_underlined), + [make_matched_part_italic](renderer.md#rendercv.rendering.make_matched_part_italic), + or + [make_matched_part_non_line_breakable](renderer.md#rendercv.rendering.make_matched_part_non_line_breakable) + instead. + + Args: + value (str): The string to make something. + something (str): The $\\LaTeX$ command to use. + match_str (str): The string to match. + Returns: + str: The string with the matched part something. + """ + if match_str is None: + value = f"\\{something}{{{value}}}" + elif match_str in value and match_str != "": + value = value.replace(match_str, f"\\{something}{{{match_str}}}") + + return value + + +def make_matched_part_bold(value: str, match_str: Optional[str] = None) -> str: + """Make the matched parts of the string bold. If the match_str is None, the whole + string will be made bold. + + This function can be used as a Jinja2 filter in templates. + + Example: + ```python + make_it_bold("Hello World!", "Hello") + ``` + + will return: + + `#!python "\\textbf{Hello} World!"` + + Args: + value (str): The string to make bold. + match_str (str): The string to match. + Returns: + str: The string with the matched part bold. + """ + return make_matched_part_something(value, "textbf", match_str) + + +def make_matched_part_underlined(value: str, match_str: Optional[str] = None) -> str: + """Make the matched parts of the string underlined. If the match_str is None, the + whole string will be made underlined. + + This function can be used as a Jinja2 filter in templates. + + Example: + ```python + make_it_underlined("Hello World!", "Hello") + ``` + + will return: + + `#!python "\\underline{Hello} World!"` + + Args: + value (str): The string to make underlined. + match_str (str): The string to match. + Returns: + str: The string with the matched part underlined. + """ + return make_matched_part_something(value, "underline", match_str) + + +def make_matched_part_italic(value: str, match_str: Optional[str] = None) -> str: + """Make the matched parts of the string italic. If the match_str is None, the whole + string will be made italic. + + This function can be used as a Jinja2 filter in templates. + + Example: + ```python + make_it_italic("Hello World!", "Hello") + ``` + + will return: + + `#!python "\\textit{Hello} World!"` + + Args: + value (str): The string to make italic. + match_str (str): The string to match. + Returns: + str: The string with the matched part italic. + """ + return make_matched_part_something(value, "textit", match_str) + + +def make_matched_part_non_line_breakable( + value: str, match_str: Optional[str] = None +) -> str: + """Make the matched parts of the string non line breakable. If the match_str is + None, the whole string will be made nonbreakable. + + This function can be used as a Jinja2 filter in templates. + + Example: + ```python + make_it_nolinebreak("Hello World!", "Hello") + ``` + + will return: + + `#!python "\\mbox{Hello} World!"` + + Args: + value (str): The string to disable line breaks. + match_str (str): The string to match. + Returns: + str: The string with the matched part non line breakable. + """ + return make_matched_part_something(value, "mbox", match_str) + + +def abbreviate_name(name: Optional[str]) -> str: + """Abbreviate a name by keeping the first letters of the first names. + + This function can be used as a Jinja2 filter in templates. + + Example: + ```python + abbreviate_name("John Doe") + ``` + + will return: + + `#!python "J. Doe"` + + Args: + name (str): The name to abbreviate. + Returns: + str: The abbreviated name. + """ + if name is None: + return "" + + number_of_words = len(name.split(" ")) + + if number_of_words == 1: + return name + + first_names = name.split(" ")[:-1] + first_names_initials = [first_name[0] + "." for first_name in first_names] + last_name = name.split(" ")[-1] + abbreviated_name = " ".join(first_names_initials) + " " + last_name + + return abbreviated_name + + +def divide_length_by(length: str, divider: float) -> str: + r"""Divide a length by a number. Length is a string with the following regex + pattern: `\d+\.?\d* *(cm|in|pt|mm|ex|em)` + + This function can be used as a Jinja2 filter in templates. + + Example: + ```python + divide_length_by("10.4cm", 2) + ``` + + will return: + + `#!python "5.2cm"` + + Args: + length (str): The length to divide. + divider (float): The number to divide the length by. + Returns: + str: The divided length. + """ + # Get the value as a float and the unit as a string: + value = re.search(r"\d+\.?\d*", length) + + if value is None: + raise ValueError(f"Invalid length {length}!") + else: + value = value.group() + + if divider <= 0: + raise ValueError(f"The divider must be greater than 0, but got {divider}!") + + unit = re.findall(r"[^\d\.\s]+", length)[0] + + return str(float(value) / divider) + " " + unit + + +def get_an_item_with_a_specific_attribute_value( + items: Optional[list[Any]], attribute: str, value: Any +) -> Any: + """Get an item from a list of items with a specific attribute value. + + This function can be used as a Jinja2 filter in templates. + + Args: + items (list[Any]): The list of items. + attribute (str): The attribute to check. + value (Any): The value of the attribute. + Returns: + Any: The item with the specific attribute value. + """ + if items is not None: + for item in items: + if not hasattr(item, attribute): + raise AttributeError( + f"The attribute {attribute} doesn't exist in the item {item}!" + ) + else: + if getattr(item, attribute) == value: + return item + + return None + + +def setup_jinja2_environment() -> jinja2.Environment: + """Setup and return the Jinja2 environment for templating the $\\LaTeX$ files. + + Returns: + jinja2.Environment: The theme environment. + """ + # create a Jinja2 environment: + # we need to add the current working directory because custom themes might be used. + themes_directory = pathlib.Path(__file__).parent / "themes" + environment = jinja2.Environment( + loader=jinja2.FileSystemLoader([os.getcwd(), themes_directory]), + trim_blocks=True, + lstrip_blocks=True, + ) + + # set custom delimiters for LaTeX templating: + environment.block_start_string = "((*" + environment.block_end_string = "*))" + environment.variable_start_string = "<<" + environment.variable_end_string = ">>" + environment.comment_start_string = "((#" + environment.comment_end_string = "#))" + + # add custom filters to make it easier to template the LaTeX files and add new + # themes: + environment.filters["make_it_bold"] = make_matched_part_bold + environment.filters["make_it_underlined"] = make_matched_part_underlined + environment.filters["make_it_italic"] = make_matched_part_italic + environment.filters["make_it_nolinebreak"] = make_matched_part_non_line_breakable + environment.filters["make_it_something"] = make_matched_part_something + environment.filters["divide_length_by"] = divide_length_by + environment.filters["abbreviate_name"] = abbreviate_name + environment.filters["replace_placeholders_with_actual_values"] = ( + replace_placeholders_with_actual_values + ) + environment.filters["get_an_item_with_a_specific_attribute_value"] = ( + get_an_item_with_a_specific_attribute_value + ) + + return environment + + +def generate_latex_file( + rendercv_data_model: dm.RenderCVDataModel, output_directory: pathlib.Path +) -> pathlib.Path: + """Generate the $\\LaTeX$ file with the given data model and write it to the output + directory. + + Args: + rendercv_data_model (dm.RenderCVDataModel): The data model. + output_directory (pathlib.Path): Path to the output directory. + Returns: + pathlib.Path: The path to the generated $\\LaTeX$ file. + """ + # create output directory if it doesn't exist: + if not output_directory.is_dir(): + output_directory.mkdir(parents=True) + + jinja2_environment = setup_jinja2_environment() + latex_file_object = LaTeXFile( + rendercv_data_model, + jinja2_environment, + ) + + latex_file_name = f"{str(rendercv_data_model.cv.name).replace(' ', '_')}_CV.tex" + latex_file_path = output_directory / latex_file_name + latex_file_object.generate_latex_file(latex_file_path) + + return latex_file_path + + +def generate_markdown_file( + rendercv_data_model: dm.RenderCVDataModel, output_directory: pathlib.Path +) -> pathlib.Path: + """Generate the Markdown file with the given data model and write it to the output + directory. + + Args: + rendercv_data_model (dm.RenderCVDataModel): The data model. + output_directory (pathlib.Path): Path to the output directory. + Returns: + pathlib.Path: The path to the generated Markdown file. + """ + # create output directory if it doesn't exist: + if not output_directory.is_dir(): + output_directory.mkdir(parents=True) + + jinja2_environment = setup_jinja2_environment() + markdown_file_object = MarkdownFile( + rendercv_data_model, + jinja2_environment, + ) + + markdown_file_name = f"{str(rendercv_data_model.cv.name).replace(' ', '_')}_CV.md" + markdown_file_path = output_directory / markdown_file_name + markdown_file_object.generate_markdown_file(markdown_file_path) + + return markdown_file_path + + +def copy_theme_files_to_output_directory( + theme_name: str, output_directory: pathlib.Path +): + """Copy the auxiliary files (all the files that don't end with `.j2.tex` and `.py`) + of the theme to the output directory. For example, the "classic" theme has custom + fonts, and the $\\LaTeX$ needs it. If the theme is a custom theme, then it will be + copied from the current working directory. + + Args: + theme_name (str): The name of the theme. + output_directory (pathlib.Path): Path to the output directory. + """ + try: + theme_directory = importlib.resources.files(f"rendercv.themes.{theme_name}") + except ModuleNotFoundError: + # Then it means the theme is a custom theme: + theme_directory = pathlib.Path(os.getcwd()) / theme_name + + for theme_file in theme_directory.iterdir(): + if not ("j2.tex" in theme_file.name or "py" in theme_file.name): + if theme_file.is_dir(): + shutil.copytree( + str(theme_file), + output_directory / theme_file.name, + dirs_exist_ok=True, + ) + else: + shutil.copyfile(str(theme_file), output_directory / theme_file.name) + + +def generate_latex_file_and_copy_theme_files( + rendercv_data_model: dm.RenderCVDataModel, output_directory: pathlib.Path +) -> pathlib.Path: + """Generate the $\\LaTeX$ file with the given data model in the output directory and + copy the auxiliary theme files to the output directory. + + Args: + rendercv_data_model (dm.RenderCVDataModel): The data model. + output_directory (pathlib.Path): Path to the output directory. + Returns: + pathlib.Path: The path to the generated $\\LaTeX$ file. + """ + latex_file_path = generate_latex_file(rendercv_data_model, output_directory) + copy_theme_files_to_output_directory( + rendercv_data_model.design.theme, output_directory + ) + return latex_file_path + + +def latex_to_pdf( + latex_file_path: pathlib.Path, use_local_latex: bool = False +) -> pathlib.Path: + """Run TinyTeX with the given $\\LaTeX$ file to generate the PDF. + + Args: + latex_file_path (str): The path to the $\\LaTeX$ file to compile. + Returns: + pathlib.Path: The path to the generated PDF file. + """ + # check if the file exists: + if not latex_file_path.is_file(): + raise FileNotFoundError(f"The file {latex_file_path} doesn't exist!") + + if use_local_latex: + executable = "pdflatex" + + # check if pdflatex is installed: + try: + subprocess.run( + [executable, "--version"], + stdout=subprocess.DEVNULL, # don't capture the output + stderr=subprocess.DEVNULL, # don't capture the error + ) + except FileNotFoundError: + raise FileNotFoundError( + "[blue]pdflatex[/blue] isn't installed! Please install LaTeX and try" + " again (or don't use the" + " [bright_black]--use_local_latex[/bright_black] option)." + ) + else: + tinytex_binaries_directory = ( + pathlib.Path(__file__).parent / "tinytex-release" / "TinyTeX" / "bin" + ) + + executables = { + "win32": tinytex_binaries_directory / "windows" / "pdflatex.exe", + "linux": tinytex_binaries_directory / "x86_64-linux" / "pdflatex", + "darwin": tinytex_binaries_directory / "universal-darwin" / "pdflatex", + } + + if sys.platform not in executables: + raise OSError(f"TinyTeX doesn't support the platform {sys.platform}!") + + executable = executables[sys.platform] + # Run TinyTeX: + command = [ + executable, + str(latex_file_path.absolute()), + ] + with subprocess.Popen( + command, + cwd=latex_file_path.parent, + stdout=subprocess.PIPE, # capture the output + stderr=subprocess.DEVNULL, # don't capture the error + stdin=subprocess.DEVNULL, # don't allow TinyTeX to ask for user input + ) as latex_process: + output = latex_process.communicate() # wait for the process to finish + if latex_process.returncode != 0: + raise RuntimeError( + "Running TinyTeX has failed! For debugging, we suggest running the" + " LaTeX file manually in https://overleaf.com.", + "If you want to run it locally, run the command below in the terminal:", + " ".join([str(command_part) for command_part in command]), + "If you can't solve the problem, please open an issue on GitHub.", + ) + else: + output = output[0].decode("utf-8") + if "Rerun to get" in output: + # Run TinyTeX again to get the references right: + subprocess.run( + command, + cwd=latex_file_path.parent, + stdout=subprocess.DEVNULL, # don't capture the output + stderr=subprocess.DEVNULL, # don't capture the error + stdin=subprocess.DEVNULL, # don't allow TinyTeX to ask for user input + ) + + # check if the PDF file is generated: + pdf_file_path = latex_file_path.with_suffix(".pdf") + if not pdf_file_path.is_file(): + raise RuntimeError( + "The PDF file couldn't be generated! If you can't solve the problem," + " please try to re-install RenderCV, or open an issue on GitHub." + ) + + return pdf_file_path + + +def markdown_to_html(markdown_file_path: pathlib.Path) -> pathlib.Path: + """Convert a markdown file to HTML. + + RenderCV doesn't produce an HTML file as the final output, but generates it for + users to easily copy and paste the HTML into Grammarly for proofreading purposes. + + Args: + markdown_file_path (pathlib.Path): The path to the markdown file to convert. + Returns: + pathlib.Path: The path to the generated HTML file. + """ + # check if the file exists: + if not markdown_file_path.is_file(): + raise FileNotFoundError(f"The file {markdown_file_path} doesn't exist!") + + html_file_path = ( + markdown_file_path.parent / f"{markdown_file_path.stem}_PASTETOGRAMMARLY.html" + ) + + # Convert the markdown file to HTML: + html = markdown.markdown(markdown_file_path.read_text(encoding="utf-8")) + + # write html into a file: + html_file_path.write_text(html, encoding="utf-8") + + return html_file_path diff --git a/rendercv/rendering.py b/rendercv/rendering.py deleted file mode 100644 index 9566b15..0000000 --- a/rendercv/rendering.py +++ /dev/null @@ -1,493 +0,0 @@ -"""This module implements LaTeX file generation and LaTeX runner utilities for RenderCV. -""" -import subprocess -import os -import re -import shutil -from datetime import date -import logging -import time -from typing import Optional -import sys -from importlib.resources import files - -from .data_model import RenderCVDataModel, CurriculumVitae, Design, ClassicThemeOptions - -from jinja2 import Environment, PackageLoader - -logger = logging.getLogger(__name__) - - -def markdown_to_latex(markdown_string: str) -> str: - """Convert a markdown string to LaTeX. - - This function is used as a Jinja2 filter. - - Example: - ```python - markdown_to_latex("This is a **bold** text with an [*italic link*](https://google.com).") - ``` - - will return: - - `#!pytjon "This is a \\textbf{bold} text with a \\href{https://google.com}{\\textit{link}}."` - - Args: - markdown_string (str): The markdown string to convert. - - Returns: - str: The LaTeX string. - """ - if not isinstance(markdown_string, str): - raise ValueError("markdown_to_latex should only be used on strings!") - - # convert links - links = re.findall(r"\[([^\]\[]*)\]\((.*?)\)", markdown_string) - if links is not None: - for link in links: - link_text = link[0] - link_url = link[1] - - old_link_string = f"[{link_text}]({link_url})" - new_link_string = "\\href{" + link_url + "}{" + link_text + "}" - - markdown_string = markdown_string.replace(old_link_string, new_link_string) - - # convert bold - bolds = re.findall(r"\*\*([^\*]*)\*\*", markdown_string) - if bolds is not None: - for bold_text in bolds: - old_bold_text = f"**{bold_text}**" - new_bold_text = "\\textbf{" + bold_text + "}" - - markdown_string = markdown_string.replace(old_bold_text, new_bold_text) - - # convert italic - italics = re.findall(r"\*([^\*]*)\*", markdown_string) - if italics is not None: - for italic_text in italics: - old_italic_text = f"*{italic_text}*" - new_italic_text = "\\textit{" + italic_text + "}" - - markdown_string = markdown_string.replace(old_italic_text, new_italic_text) - - latex_string = markdown_string - - return latex_string - - -def markdown_link_to_url(value: str) -> str: - """Convert a markdown link to a normal string URL. - - This function is used as a Jinja2 filter. - - Example: - ```python - markdown_link_to_url("[Google](https://google.com)") - ``` - - will return: - - `#!python "https://google.com"` - - Args: - value (str): The markdown link to convert. - - Returns: - str: The URL as a string. - """ - if not isinstance(value, str): - raise ValueError("markdown_to_latex should only be used on strings!") - - link = re.search(r"\[(.*)\]\((.*?)\)", value) - if link is not None: - url = link.groups()[1] - if url == "": - raise ValueError(f"The markdown link {value} is empty!") - return url - else: - raise ValueError("markdown_link_to_url should only be used on markdown links!") - - -def make_it_something( - value: str, something: str, match_str: Optional[str] = None -) -> str: - """Make the matched parts of the string something. If the match_str is None, the - whole string will be made something. - - Warning: - This function shouldn't be used directly. Use - [make_it_bold](rendering.md#rendercv.rendering.make_it_bold), - [make_it_underlined](rendering.md#rendercv.rendering.make_it_underlined), or - [make_it_italic](rendering.md#rendercv.rendering.make_it_italic) instead. - """ - if not isinstance(value, str): - raise ValueError(f"{something} should only be used on strings!") - - if match_str is not None and not isinstance(match_str, str): - raise ValueError("The string to match should be a string!") - - if match_str is None: - return f"\\{something}{{{value}}}" - - if match_str in value: - value = value.replace(match_str, f"\\{something}{{{match_str}}}") - return value - else: - return value - - -def make_it_bold(value: str, match_str: Optional[str] = None) -> str: - """Make the matched parts of the string bold. If the match_str is None, the whole - string will be made bold. - - This function is used as a Jinja2 filter. - - Example: - ```python - make_it_bold("Hello World!", "Hello") - ``` - - will return: - - `#!python "\\textbf{Hello} World!"` - - Args: - value (str): The string to make bold. - match_str (str): The string to match. - """ - return make_it_something(value, "textbf", match_str) - - -def make_it_underlined(value: str, match_str: Optional[str] = None) -> str: - """Make the matched parts of the string underlined. If the match_str is None, the - whole string will be made underlined. - - This function is used as a Jinja2 filter. - - Example: - ```python - make_it_underlined("Hello World!", "Hello") - ``` - - will return: - - `#!python "\\underline{Hello} World!"` - - Args: - value (str): The string to make underlined. - match_str (str): The string to match. - """ - return make_it_something(value, "underline", match_str) - - -def make_it_italic(value: str, match_str: Optional[str] = None) -> str: - """Make the matched parts of the string italic. If the match_str is None, the whole - string will be made italic. - - This function is used as a Jinja2 filter. - - Example: - ```python - make_it_italic("Hello World!", "Hello") - ``` - - will return: - - `#!python "\\textit{Hello} World!"` - - Args: - value (str): The string to make italic. - match_str (str): The string to match. - """ - return make_it_something(value, "textit", match_str) - - -def make_it_nolinebreak(value: str, match_str: Optional[str] = None) -> str: - """Make the matched parts of the string non line breakable. If the match_str is - None, the whole string will be made nonbreakable. - - This function is used as a Jinja2 filter. - - Example: - ```python - make_it_nolinebreak("Hello World!", "Hello") - ``` - - will return: - - `#!python "\\mbox{Hello} World!"` - - Args: - value (str): The string to disable line breaks. - match_str (str): The string to match. - """ - return make_it_something(value, "mbox", match_str) - - -def abbreviate_name(name: list[str]) -> str: - """Abbreviate a name by keeping the first letters of the first names. - - This function is used as a Jinja2 filter. - - Example: - ```python - abbreviate_name("John Doe") - ``` - - will return: - - `#!python "J. Doe"` - - Args: - name (str): The name to abbreviate. - Returns: - str: The abbreviated name. - """ - first_names = name.split(" ")[:-1] - first_names_initials = [first_name[0] + "." for first_name in first_names] - last_name = name.split(" ")[-1] - abbreviated_name = " ".join(first_names_initials) + " " + last_name - - return abbreviated_name - - -def divide_length_by(length: str, divider: float) -> str: - r"""Divide a length by a number. - - Length is a string with the following regex pattern: `\d+\.?\d* *(cm|in|pt|mm|ex|em)` - """ - # Get the value as a float and the unit as a string: - value = re.search(r"\d+\.?\d*", length).group() # type: ignore - unit = re.findall(r"[^\d\.\s]+", length)[0] - - return str(float(value) / divider) + " " + unit - - -def get_today() -> str: - """Return today's date in the format of "Month Year". - - Returns: - str: Today's date. - """ - - today = date.today() - return today.strftime("%B %Y") - - -def get_path_to_font_directory(font_name: str) -> str: - """Return the path to the fonts directory. - - Returns: - str: The path to the fonts directory. - """ - return str(files("rendercv").joinpath("templates", "fonts", font_name)) - - -def render_template(data: RenderCVDataModel, output_path: Optional[str] = None) -> str: - """Render the template using the given data. - - Args: - data (RenderCVDataModel): The data to use to render the template. - - Returns: - str: The path to the rendered LaTeX file. - """ - start_time = time.time() - logger.info("Rendering the LaTeX file has started.") - - # create a Jinja2 environment: - theme = data.design.theme - environment = Environment( - loader=PackageLoader("rendercv", os.path.join("templates", theme)), - trim_blocks=True, - lstrip_blocks=True, - ) - - # add new functions to the environment: - environment.globals.update(str=str) - - # set custom delimiters for LaTeX templating: - environment.block_start_string = "((*" - environment.block_end_string = "*))" - environment.variable_start_string = "<<" - environment.variable_end_string = ">>" - environment.comment_start_string = "((#" - environment.comment_end_string = "#))" - - # add custom filters: - environment.filters["markdown_to_latex"] = markdown_to_latex - environment.filters["markdown_link_to_url"] = markdown_link_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 - environment.filters["make_it_nolinebreak"] = make_it_nolinebreak - environment.filters["make_it_something"] = make_it_something - environment.filters["divide_length_by"] = divide_length_by - environment.filters["abbreviate_name"] = abbreviate_name - - # load the template: - template = environment.get_template(f"{theme}.tex.j2") - - cv: CurriculumVitae = data.cv - design: Design = data.design - theme_options: ClassicThemeOptions = data.design.options - output_latex_file = template.render( - cv=cv, - design=design, - theme_options=theme_options, - today=get_today(), - ) - - # Create an output file and write the rendered LaTeX code to it: - if output_path is None: - output_path = os.getcwd() - - output_folder = os.path.join(output_path, "output") - file_name = data.cv.name.replace(" ", "_") + "_CV.tex" - output_file_path = os.path.join(output_folder, file_name) - os.makedirs(os.path.dirname(output_file_path), exist_ok=True) - with open(output_file_path, "w") as file: - file.write(output_latex_file) - - # Copy the fonts directory to the output directory: - # Remove the old fonts directory if it exists: - if os.path.exists(os.path.join(os.path.dirname(output_file_path), "fonts")): - shutil.rmtree(os.path.join(os.path.dirname(output_file_path), "fonts")) - - font_directory = get_path_to_font_directory(data.design.font) - output_fonts_directory = os.path.join(os.path.dirname(output_file_path), "fonts") - shutil.copytree( - font_directory, - output_fonts_directory, - 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 = str(files("rendercv").joinpath("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() - time_taken = end_time - start_time - logger.info( - f"Rendering the LaTeX file ({output_file_path}) has finished in" - f" {time_taken:.2f} s." - ) - - return output_file_path - - -def run_latex(latex_file_path: str) -> str: - """ - Run TinyTeX with the given LaTeX file and generate a PDF. - - Args: - latex_file_path (str): The path to the LaTeX file to compile. - """ - start_time = time.time() - logger.info("Running TinyTeX to generate the PDF has started.") - latex_file_name = os.path.basename(latex_file_path) - latex_file_path = os.path.normpath(latex_file_path) - - # check if the file exists: - if not os.path.exists(latex_file_path): - raise FileNotFoundError(f"The file {latex_file_path} doesn't exist!") - - output_file_name = latex_file_name.replace(".tex", ".pdf") - output_file_path = os.path.join(os.path.dirname(latex_file_path), output_file_name) - - if sys.platform == "win32": - # Windows - executable = str( - files("rendercv").joinpath( - "vendor", "TinyTeX", "bin", "windows", "lualatex.exe" - ) - ) - - elif sys.platform == "linux" or sys.platform == "linux2": - # Linux - executable = str( - files("rendercv").joinpath( - "vendor", "TinyTeX", "bin", "x86_64-linux", "lualatex" - ) - ) - elif sys.platform == "darwin": - # MacOS - executable = str( - files("rendercv").joinpath( - "vendor", "TinyTeX", "bin", "universal-darwin", "lualatex" - ) - ) - else: - raise OSError(f"Unknown OS {os.name}!") - - # Check if the executable exists: - if not os.path.exists(executable): - raise FileNotFoundError( - f"The TinyTeX executable ({executable}) doesn't exist! Please install" - " RenderCV again." - ) - - # Run TinyTeX: - def run(): - with subprocess.Popen( - [ - executable, - f"{latex_file_name}", - ], - cwd=os.path.dirname(latex_file_path), - stdout=subprocess.PIPE, - stdin=subprocess.DEVNULL, # don't allow TinyTeX to ask for user input - text=True, - encoding="utf-8", - ) as latex_process: - output, error = latex_process.communicate() - - if latex_process.returncode != 0: - # Find the error line: - for line in output.split("\n"): - if line.startswith("! "): - error_line = line.replace("! ", "") - break - - raise RuntimeError( - "Running TinyTeX has failed with the following error:", - f"{error_line}", - "If you can't solve the problem, please try to re-install RenderCV," - " or open an issue on GitHub.", - ) - - run() - run() # run twice for cross-references - - # check if the PDF file is generated: - if not os.path.exists(output_file_path): - raise FileNotFoundError( - f"The PDF file {output_file_path} couldn't be generated! If you can't" - " solve the problem, please try to re-install RenderCV, or open an issue" - " on GitHub." - ) - - # remove the unnecessary files: - for file_name in os.listdir(os.path.dirname(latex_file_path)): - if ( - file_name.endswith(".aux") - or file_name.endswith(".log") - or file_name.endswith(".out") - ): - os.remove(os.path.join(os.path.dirname(latex_file_path), file_name)) - - end_time = time.time() - time_taken = end_time - start_time - logger.info( - f"Running TinyTeX to generate the PDF ({output_file_path}) has finished in" - f" {time_taken:.2f} s." - ) - - return output_file_path diff --git a/rendercv/templates/classic/components/date_and_location_strings.tex.j2 b/rendercv/templates/classic/components/date_and_location_strings.tex.j2 deleted file mode 100644 index 62fecf3..0000000 --- a/rendercv/templates/classic/components/date_and_location_strings.tex.j2 +++ /dev/null @@ -1,9 +0,0 @@ -((* macro date_and_location_strings(date_and_location_strings) *)) - ((* for item in date_and_location_strings *)) - ((* if loop.last *)) -<> - ((* else *)) -<> \newline - ((* endif *)) - ((* endfor *)) -((* endmacro *)) \ No newline at end of file diff --git a/rendercv/templates/classic/components/entry.tex.j2 b/rendercv/templates/classic/components/entry.tex.j2 deleted file mode 100644 index 6aea6b8..0000000 --- a/rendercv/templates/classic/components/entry.tex.j2 +++ /dev/null @@ -1,114 +0,0 @@ -((* from "components/highlights.tex.j2" import highlights as print_higlights with context *)) -((* from "components/date_and_location_strings.tex.j2" import date_and_location_strings as print_date_and_locations with context *)) - -((* macro education(study_type, institution, area, highlights, date_and_location_strings)*)) -((# \begin{tabularx}{⟨width⟩}[⟨pos⟩]{⟨preamble⟩} #)) - ((# width: \textwidth #)) - ((# preamble: first column, second column, third column #)) - ((# first column: p{0.55cm}; constant width, ragged left column #)) - ((# second column: K{<>}; variable width, justified column #)) - ((# third column: R{<>}; constant widthm ragged right column #)) -\begin{tabularx}{\textwidth-<>-0.13cm}{L{0.85cm} K{<>} R{<>}} - \textbf{<>} - & - \textbf{<>}, <> - <> - & - <> -\end{tabularx} -((* endmacro *)) - -((* macro experience(company, position, highlights, date_and_location_strings)*)) -((# \begin{tabularx}{⟨width⟩}[⟨pos⟩]{⟨preamble⟩} #)) - ((# width: \textwidth #)) - ((# preamble: first column, second column #)) - ((# first column:: K{<>}; variable width, justified column #)) - ((# second column: R{<>}; constant width ragged right column #)) -\begin{tabularx}{\textwidth-<>-0.13cm}{K{<>} R{<>}} - \textbf{<>}, <> - <> - & - <> -\end{tabularx} -((* endmacro *)) - -((* macro normal(name, highlights, date_and_location_strings, markdown_url=none, link_text=none)*)) -((# \begin{tabularx}{⟨width⟩}[⟨pos⟩]{⟨preamble⟩} #)) - ((# width: \textwidth #)) - ((# preamble: first column, second column #)) - ((# first column:: K{<>}; variable width, justified column #)) - ((# second column: R{<>}; constant width ragged right column #)) - ((* if date_and_location_strings == [] *)) -\begin{tabularx}{\textwidth-<>-0.13cm}{K{<>}} - ((* if markdown_url is not none *)) - ((* if link_text is not none *)) - ((* set markdown_url = "["+link_text+"]("+ markdown_url|markdown_link_to_url +")" *)) - \textbf{<>}, <> - ((* else *)) - \textbf{<>}, <> - ((* endif *)) - ((* else *)) - \textbf{<>} - ((* endif *)) - <> -\end{tabularx} - ((* else *)) -\begin{tabularx}{\textwidth-<>-0.13cm}{K{<>} R{<>}} - ((* if markdown_url is not none *)) - ((* if link_text is not none *)) - ((* set markdown_url = "["+link_text+"]("+ markdown_url|markdown_link_to_url +")" *)) - \textbf{<>}, <> - ((* else *)) - \textbf{<>}, <> - ((* endif *)) - ((* else *)) - \textbf{<>} - ((* endif *)) - <> - & - <> -\end{tabularx} - ((* endif *)) -((* endmacro *)) - -((* macro publication(title, authors, journal, date, doi, doi_url)*)) -((# \begin{tabularx}{⟨width⟩}[⟨pos⟩]{⟨preamble⟩} #)) - ((# width: \textwidth #)) - ((# preamble: first column, second column #)) - ((# first column:: K{<>}; variable width, justified column #)) - ((# second column: R{<>}; constant width ragged right column #)) -\begin{tabularx}{\textwidth-<>-0.13cm}{K{<>} R{<>}} - \textbf{<>} - - \vspace{<<theme_options.margins.highlights_area.vertical_between_bullet_points>>} - - <<authors|map("abbreviate_name")|map("make_it_nolinebreak")|join(", ")|make_it_bold(cv.name|abbreviate_name)|make_it_italic(cv.name|abbreviate_name)>> - - \vspace{<<theme_options.margins.highlights_area.vertical_between_bullet_points>>} - - \href{<<doi_url>>}{<<doi>>} (<<journal>>) - & - <<date>> - -\end{tabularx} -((* endmacro *)) - -((* macro one_line(name, details, markdown_url=none, link_text=none) *)) - \begingroup((* if theme_options.text_alignment == "left-aligned" *))\raggedright((* endif *)) - \leftskip=<<theme_options.margins.entry_area.left_and_right>> - \advance\csname @rightskip\endcsname <<theme_options.margins.entry_area.left_and_right>> - \advance\rightskip <<theme_options.margins.entry_area.left_and_right>> - - ((* if markdown_url is not none *)) - ((* if link_text is not none *)) - ((* set markdown_url = "["+link_text+"]("+ markdown_url|markdown_link_to_url +")" *)) - \textbf{<<name|markdown_to_latex>>:} <<details|markdown_to_latex>> (<<markdown_url|markdown_to_latex>>) - ((* else *)) - \textbf{<<name|markdown_to_latex>>:} <<details|markdown_to_latex>> (<<markdown_url|markdown_to_latex>>) - ((* endif *)) - ((* else *)) - \textbf{<<name|markdown_to_latex>>:} <<details|markdown_to_latex>> - ((* endif *)) - - \par\endgroup -((* endmacro *)) \ No newline at end of file diff --git a/rendercv/templates/classic/components/header.tex.j2 b/rendercv/templates/classic/components/header.tex.j2 deleted file mode 100644 index dd7809c..0000000 --- a/rendercv/templates/classic/components/header.tex.j2 +++ /dev/null @@ -1,19 +0,0 @@ -((* import "components/header_connections.tex.j2" as print_connections *)) -((* macro header(name, connections) *)) -\begin{header} - \fontsize{<<theme_options.header_font_size>>}{<<theme_options.header_font_size>>} - \textbf{<<name>>} - - \vspace{<<theme_options.margins.header.vertical_between_name_and_connections>>} - - \normalsize -((* for connection in connections *)) - <<print_connections[connection.name|replace(" ", "")](connection.value, connection.url)>> - ((* if not loop.last *)) - \hspace{0.5cm} - ((* endif *)) -((* endfor *)) -\end{header} - -\vspace{<<theme_options.margins.header.bottom>>} -((* endmacro *)) \ No newline at end of file diff --git a/rendercv/templates/classic/components/header_connections.tex.j2 b/rendercv/templates/classic/components/header_connections.tex.j2 deleted file mode 100644 index d1c95e9..0000000 --- a/rendercv/templates/classic/components/header_connections.tex.j2 +++ /dev/null @@ -1,36 +0,0 @@ -((# Each macro in here is a link with an icon for header. #)) -((* macro LinkedIn(username, url) -*)) -\mbox{\hrefWithoutArrow{<<url>>}{{\small\faLinkedinIn}\hspace{0.13cm}<<username>>}} -((*- endmacro *)) - -((* macro GitHub(username, url) -*)) -\mbox{\hrefWithoutArrow{<<url>>}{{\small\faGithub}\hspace{0.13cm}<<username>>}} -((*- endmacro *)) - -((* macro Instagram(username, url) -*)) -\mbox{\hrefWithoutArrow{<<url>>}{{\small\faInstagram}\hspace{0.13cm}<<username>>}} -((*- endmacro *)) - -((* macro Orcid(username, url) -*)) -\mbox{\hrefWithoutArrow{<<url>>}{{\small\faOrcid}\hspace{0.13cm}<<username>>}} -((*- endmacro *)) - -((* macro Mastodon(username, url) -*)) -\mbox{\hrefWithoutArrow{<<url>>}{{\small\faMastodon}\hspace{0.13cm}<<username>>}} -((*- endmacro *)) - -((* macro phone(number, url) -*)) -\mbox{\hrefWithoutArrow{<<url|replace("-","")>>}{{\footnotesize\faPhone*}\hspace{0.13cm}<<number|replace("tel:", "")|replace("-"," ")>>}} -((*- endmacro *)) - -((* macro email(email, url) -*)) -\mbox{\hrefWithoutArrow{<<url>>}{{\small\faEnvelope[regular]}\hspace{0.13cm}<<email>>}} -((*- endmacro *)) - -((* macro website(url, dummy) -*)) -\mbox{\hrefWithoutArrow{<<url>>}{{\small\faLink}\hspace{0.13cm}<<url|replace("https://","")|replace("/","")>>}} -((*- endmacro *)) - -((* macro location(location, url) -*)) -\mbox{{\small\faMapMarker*}\hspace{0.13cm}<<location>>} -((*- endmacro *)) diff --git a/rendercv/templates/classic/components/highlights.tex.j2 b/rendercv/templates/classic/components/highlights.tex.j2 deleted file mode 100644 index 7bab5d1..0000000 --- a/rendercv/templates/classic/components/highlights.tex.j2 +++ /dev/null @@ -1,13 +0,0 @@ -((* macro highlights(highlights) *)) -\vspace{<<theme_options.margins.highlights_area.top>>} - ((* for item in highlights *)) - ((* if loop.first *)) -\begin{highlights} - ((* endif *)) - \item <<item|markdown_to_latex>> ((* if loop.last *))\hspace*{-0.2cm}((* endif *)) - - ((* if loop.last *)) -\end{highlights} - ((* endif *)) -((* endfor *)) -((* endmacro *)) \ No newline at end of file diff --git a/rendercv/templates/classic/components/section_contents.tex.j2 b/rendercv/templates/classic/components/section_contents.tex.j2 deleted file mode 100644 index 0af0c85..0000000 --- a/rendercv/templates/classic/components/section_contents.tex.j2 +++ /dev/null @@ -1,54 +0,0 @@ -((* import "components/entry.tex.j2" as entry with context *)) - -((* macro section_contents(title, entries, entry_type, link_text=none)*)) - ((* for value in entries *)) - ((* if title in theme_options.show_timespan_in *)) - ((* set date_and_location_strings = value.date_and_location_strings_with_timespan *)) - ((* else *)) - ((* set date_and_location_strings = value.date_and_location_strings_without_timespan *)) - ((* endif *)) - ((* if not loop.first *)) - \vspace{<<theme_options.margins.entry_area.vertical_between>>} - ((* endif *)) - ((* if entry_type == "EducationEntry" *)) - <<entry["education"]( - study_type=value.study_type, - institution=value.institution, - area=value.area, - highlights=value.highlight_strings, - date_and_location_strings=date_and_location_strings - )|indent(4)>> - ((* elif entry_type == "ExperienceEntry" *)) - <<entry["experience"]( - company=value.company, - position=value.position, - highlights=value.highlight_strings, - date_and_location_strings=date_and_location_strings - )|indent(4)>> - ((* elif entry_type == "NormalEntry" *)) - <<entry["normal"]( - name=value.name, - highlights=value.highlight_strings, - date_and_location_strings=date_and_location_strings, - markdown_url=value.markdown_url, - link_text=link_text, - )|indent(4)>> - ((* elif entry_type == "OneLineEntry" *)) - <<entry["one_line"]( - name=value.name, - details=value.details, - markdown_url=value.markdown_url, - link_text=link_text, - )|indent(4)>> - ((* elif entry_type == "PublicationEntry" *)) - <<entry["publication"]( - title=value.title, - authors=value.authors, - journal=value.journal, - date=value.month_and_year, - doi=value.doi, - doi_url=value.doi_url, - )|indent(4)>> - ((* endif *)) - ((* endfor *)) -((* endmacro *)) diff --git a/rendercv/templates/fonts/EBGaramond/COPYING b/rendercv/templates/fonts/EBGaramond/COPYING deleted file mode 100644 index 392771d..0000000 --- a/rendercv/templates/fonts/EBGaramond/COPYING +++ /dev/null @@ -1,93 +0,0 @@ -Copyright (c) 2010-2013 Georg Duffner (http://www.georgduffner.at) - -All "EB Garamond" Font Software is licensed under the SIL Open Font License, Version 1.1. -This license is copied below, and is also available with a FAQ at: -http://scripts.sil.org/OFL - - ------------------------------------------------------------ -SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 ------------------------------------------------------------ - -PREAMBLE -The goals of the Open Font License (OFL) are to stimulate worldwide -development of collaborative font projects, to support the font creation -efforts of academic and linguistic communities, and to provide a free and -open framework in which fonts may be shared and improved in partnership -with others. - -The OFL allows the licensed fonts to be used, studied, modified and -redistributed freely as long as they are not sold by themselves. The -fonts, including any derivative works, can be bundled, embedded, -redistributed and/or sold with any software provided that any reserved -names are not used by derivative works. The fonts and derivatives, -however, cannot be released under any other type of license. The -requirement for fonts to remain under this license does not apply -to any document created using the fonts or their derivatives. - -DEFINITIONS -"Font Software" refers to the set of files released by the Copyright -Holder(s) under this license and clearly marked as such. This may -include source files, build scripts and documentation. - -"Reserved Font Name" refers to any names specified as such after the -copyright statement(s). - -"Original Version" refers to the collection of Font Software components as -distributed by the Copyright Holder(s). - -"Modified Version" refers to any derivative made by adding to, deleting, -or substituting -- in part or in whole -- any of the components of the -Original Version, by changing formats or by porting the Font Software to a -new environment. - -"Author" refers to any designer, engineer, programmer, technical -writer or other person who contributed to the Font Software. - -PERMISSION & CONDITIONS -Permission is hereby granted, free of charge, to any person obtaining -a copy of the Font Software, to use, study, copy, merge, embed, modify, -redistribute, and sell modified and unmodified copies of the Font -Software, subject to the following conditions: - -1) Neither the Font Software nor any of its individual components, -in Original or Modified Versions, may be sold by itself. - -2) Original or Modified Versions of the Font Software may be bundled, -redistributed and/or sold with any software, provided that each copy -contains the above copyright notice and this license. These can be -included either as stand-alone text files, human-readable headers or -in the appropriate machine-readable metadata fields within text or -binary files as long as those fields can be easily viewed by the user. - -3) No Modified Version of the Font Software may use the Reserved Font -Name(s) unless explicit written permission is granted by the corresponding -Copyright Holder. This restriction only applies to the primary font name as -presented to the users. - -4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font -Software shall not be used to promote, endorse or advertise any -Modified Version, except to acknowledge the contribution(s) of the -Copyright Holder(s) and the Author(s) or with their explicit written -permission. - -5) The Font Software, modified or unmodified, in part or in whole, -must be distributed entirely under this license, and must not be -distributed under any other license. The requirement for fonts to -remain under this license does not apply to any document created -using the Font Software. - -TERMINATION -This license becomes null and void if any of the above conditions are -not met. - -DISCLAIMER -THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT -OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE -COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL -DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM -OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/rendercv/templates/fonts/EBGaramond/EBGaramond-Bold.ttf b/rendercv/templates/fonts/EBGaramond/EBGaramond-Bold.ttf deleted file mode 100644 index b73dee0..0000000 Binary files a/rendercv/templates/fonts/EBGaramond/EBGaramond-Bold.ttf and /dev/null differ diff --git a/rendercv/templates/fonts/EBGaramond/EBGaramond-BoldItalic.ttf b/rendercv/templates/fonts/EBGaramond/EBGaramond-BoldItalic.ttf deleted file mode 100644 index 852be7c..0000000 Binary files a/rendercv/templates/fonts/EBGaramond/EBGaramond-BoldItalic.ttf and /dev/null differ diff --git a/rendercv/templates/fonts/EBGaramond/EBGaramond-Italic.ttf b/rendercv/templates/fonts/EBGaramond/EBGaramond-Italic.ttf deleted file mode 100644 index 0f76a8e..0000000 Binary files a/rendercv/templates/fonts/EBGaramond/EBGaramond-Italic.ttf and /dev/null differ diff --git a/rendercv/templates/fonts/EBGaramond/EBGaramond-Regular.ttf b/rendercv/templates/fonts/EBGaramond/EBGaramond-Regular.ttf deleted file mode 100644 index d3d6f3f..0000000 Binary files a/rendercv/templates/fonts/EBGaramond/EBGaramond-Regular.ttf and /dev/null differ diff --git a/rendercv/templates/fonts/Roboto/LICENSE b/rendercv/templates/fonts/Roboto/LICENSE deleted file mode 100644 index 261eeb9..0000000 --- a/rendercv/templates/fonts/Roboto/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/rendercv/templates/fonts/Roboto/Roboto-Bold.ttf b/rendercv/templates/fonts/Roboto/Roboto-Bold.ttf deleted file mode 100644 index 43da14d..0000000 Binary files a/rendercv/templates/fonts/Roboto/Roboto-Bold.ttf and /dev/null differ diff --git a/rendercv/templates/fonts/Roboto/Roboto-BoldItalic.ttf b/rendercv/templates/fonts/Roboto/Roboto-BoldItalic.ttf deleted file mode 100644 index bcfdab4..0000000 Binary files a/rendercv/templates/fonts/Roboto/Roboto-BoldItalic.ttf and /dev/null differ diff --git a/rendercv/templates/fonts/Roboto/Roboto-Italic.ttf b/rendercv/templates/fonts/Roboto/Roboto-Italic.ttf deleted file mode 100644 index 1b5eaa3..0000000 Binary files a/rendercv/templates/fonts/Roboto/Roboto-Italic.ttf and /dev/null differ diff --git a/rendercv/templates/fonts/Roboto/Roboto-Regular.ttf b/rendercv/templates/fonts/Roboto/Roboto-Regular.ttf deleted file mode 100644 index ddf4bfa..0000000 Binary files a/rendercv/templates/fonts/Roboto/Roboto-Regular.ttf and /dev/null differ diff --git a/rendercv/templates/fonts/SourceSans3/LICENSE.md b/rendercv/templates/fonts/SourceSans3/LICENSE.md deleted file mode 100644 index d2b80be..0000000 --- a/rendercv/templates/fonts/SourceSans3/LICENSE.md +++ /dev/null @@ -1,93 +0,0 @@ -Copyright 2010-2022 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe in the United States and/or other countries. - -This Font Software is licensed under the SIL Open Font License, Version 1.1. - -This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL - - ------------------------------------------------------------ -SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 ------------------------------------------------------------ - -PREAMBLE -The goals of the Open Font License (OFL) are to stimulate worldwide -development of collaborative font projects, to support the font creation -efforts of academic and linguistic communities, and to provide a free and -open framework in which fonts may be shared and improved in partnership -with others. - -The OFL allows the licensed fonts to be used, studied, modified and -redistributed freely as long as they are not sold by themselves. The -fonts, including any derivative works, can be bundled, embedded, -redistributed and/or sold with any software provided that any reserved -names are not used by derivative works. The fonts and derivatives, -however, cannot be released under any other type of license. The -requirement for fonts to remain under this license does not apply -to any document created using the fonts or their derivatives. - -DEFINITIONS -"Font Software" refers to the set of files released by the Copyright -Holder(s) under this license and clearly marked as such. This may -include source files, build scripts and documentation. - -"Reserved Font Name" refers to any names specified as such after the -copyright statement(s). - -"Original Version" refers to the collection of Font Software components as -distributed by the Copyright Holder(s). - -"Modified Version" refers to any derivative made by adding to, deleting, -or substituting -- in part or in whole -- any of the components of the -Original Version, by changing formats or by porting the Font Software to a -new environment. - -"Author" refers to any designer, engineer, programmer, technical -writer or other person who contributed to the Font Software. - -PERMISSION & CONDITIONS -Permission is hereby granted, free of charge, to any person obtaining -a copy of the Font Software, to use, study, copy, merge, embed, modify, -redistribute, and sell modified and unmodified copies of the Font -Software, subject to the following conditions: - -1) Neither the Font Software nor any of its individual components, -in Original or Modified Versions, may be sold by itself. - -2) Original or Modified Versions of the Font Software may be bundled, -redistributed and/or sold with any software, provided that each copy -contains the above copyright notice and this license. These can be -included either as stand-alone text files, human-readable headers or -in the appropriate machine-readable metadata fields within text or -binary files as long as those fields can be easily viewed by the user. - -3) No Modified Version of the Font Software may use the Reserved Font -Name(s) unless explicit written permission is granted by the corresponding -Copyright Holder. This restriction only applies to the primary font name as -presented to the users. - -4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font -Software shall not be used to promote, endorse or advertise any -Modified Version, except to acknowledge the contribution(s) of the -Copyright Holder(s) and the Author(s) or with their explicit written -permission. - -5) The Font Software, modified or unmodified, in part or in whole, -must be distributed entirely under this license, and must not be -distributed under any other license. The requirement for fonts to -remain under this license does not apply to any document created -using the Font Software. - -TERMINATION -This license becomes null and void if any of the above conditions are -not met. - -DISCLAIMER -THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT -OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE -COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL -DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM -OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/rendercv/templates/fonts/SourceSans3/SourceSans3-Bold.ttf b/rendercv/templates/fonts/SourceSans3/SourceSans3-Bold.ttf deleted file mode 100644 index 55f6138..0000000 Binary files a/rendercv/templates/fonts/SourceSans3/SourceSans3-Bold.ttf and /dev/null differ diff --git a/rendercv/templates/fonts/SourceSans3/SourceSans3-BoldItalic.ttf b/rendercv/templates/fonts/SourceSans3/SourceSans3-BoldItalic.ttf deleted file mode 100644 index ddeed16..0000000 Binary files a/rendercv/templates/fonts/SourceSans3/SourceSans3-BoldItalic.ttf and /dev/null differ diff --git a/rendercv/templates/fonts/SourceSans3/SourceSans3-Italic.ttf b/rendercv/templates/fonts/SourceSans3/SourceSans3-Italic.ttf deleted file mode 100644 index 8ea9acf..0000000 Binary files a/rendercv/templates/fonts/SourceSans3/SourceSans3-Italic.ttf and /dev/null differ diff --git a/rendercv/templates/fonts/SourceSans3/SourceSans3-Regular.ttf b/rendercv/templates/fonts/SourceSans3/SourceSans3-Regular.ttf deleted file mode 100644 index 803d4da..0000000 Binary files a/rendercv/templates/fonts/SourceSans3/SourceSans3-Regular.ttf and /dev/null differ diff --git a/rendercv/templates/new_input.yaml.j2 b/rendercv/templates/new_input.yaml.j2 deleted file mode 100644 index 199c3e1..0000000 --- a/rendercv/templates/new_input.yaml.j2 +++ /dev/null @@ -1,218 +0,0 @@ -cv: - name: <<name>> - label: Mechanical Engineer - location: TX, USA - email: johndoe@example.com - phone: "+33749882538" - website: https://example.com - social_networks: - - network: GitHub - username: johndoe - - network: LinkedIn - username: johndoe - summary: - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque porta - vitae dolor vel placerat. Class aptent taciti sociosqu ad litora torquent per conubia - nostra, per inceptos himenaeos. Phasellus ullamcorper, neque id varius dignissim, - tellus sem maximus risus, at lobortis nisl sem id ligula. - section_order: - - Education - - Work Experience - - Academic Projects - - Certificates - - Personal Projects - - Skills - - Test Scores - - Extracurricular Activities - - Publications - - My Custom Section - - My Other Custom Section - - My Third Custom Section - - My Final Custom Section - education: - - institution: My University - url: https://boun.edu.tr - area: Mechanical Engineering - study_type: BS - location: Ankara, Türkiye - start_date: "2017-09-01" - end_date: "2023-01-01" - transcript_url: https://example.com - gpa: 3.99/4.00 - highlights: - - "Class rank: 1 of 62" - - institution: The University of Texas at Austin - url: https://utexas.edu - area: Mechanical Engineering, Student Exchange Program - location: Austin, TX, USA - start_date: "2021-08-01" - end_date: "2022-01-15" - transcript_url: https://example.com - gpa: 4.00/4.00 - work_experience: - - company: CERN - position: Mechanical Engineer - location: Geneva, Switzerland - url: https://home.cern - start_date: "2023-02-01" - end_date: present - highlights: - - CERN is a research organization that operates the world's largest and most - powerful particle accelerator. - - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor - incididunt ut labore et dolore magna aliqua. - - Id leo in vitae turpis massa sed, posuere aliquam ultrices sagittis orci a - scelerisque, lorem ipsum dolor sit amet. - - company: AmIACompany - position: Summer Intern - location: Istanbul, Türkiye - url: https://example.com - start_date: "2022-06-15" - end_date: "2022-08-01" - highlights: - - AmIACompany is a technology company that provides web-based engineering - applications that enable the simulation and optimization of products and - manufacturing tools. - - Modeled and simulated a metal-forming process deep drawing using finite element - analysis with open-source software called CalculiX. - academic_projects: - - name: Design and Construction of a Robot - location: Istanbul, Türkiye - date: Fall 2022 - highlights: - - Designed and constructed a controllable robot that measures a car's torque and - power output at different speeds for my senior design project. - url: https://example.com - - name: Design and Construction of an Another Robot - location: Istanbul, Türkiye - date: Fall 2020 - highlights: - - Designed, built, and programmed a microcontroller-based device that plays a - guitar with DC motors as part of a mechatronics course term project. - url: https://example.com - publications: - - title: Phononic band gaps induced by inertial amplification in periodic media - authors: - - Author 1 - - John Doe - - Author 3 - journal: Physical Review B - doi: 10.1103/PhysRevB.76.054309 - date: "2007-08-01" - cited_by: 243 - certificates: - - name: Machine Learning by Stanford University - date: "2022-09-01" - url: https://example.com - skills: - - name: Programming - details: C++, C, Python, JavaScript, MATLAB, Lua, LaTeX - - name: OS - details: Windows, Ubuntu - - name: Other tools - details: Git, Premake, HTML, CSS, React - - name: Languages - details: English (Advanced), French (Lower Intermediate), Turkish (Native) - test_scores: - - name: TOEFL - date: "2022-10-01" - details: - "113/120 — Reading: 29/30, Listening: 30/30, Speaking: 27/30, Writing: - 27/30" - url: https://example.com - - name: GRE - details: "Verbal Reasoning: 160/170, Quantitative Reasoning: 170/170, Analytical - Writing: 5.5/6" - url: https://example.com - personal_projects: - - name: Ray Tracing in C++ - date: Spring 2021 - highlights: - - Coded a ray tracer in C++ that can render scenes with multiple light sources, - spheres, and planes with reflection and refraction properties. - url: https://example.com - extracurricular_activities: - - company: Dumanlikiz Skiing Club - position: Co-founder / Skiing Instructor - location: Chamonix, France - date: Summer 2017 and 2018 - highlights: - - Taught skiing during winters as a certified skiing instructor. - custom_sections: - - title: My Custom Section - entry_type: OneLineEntry - entries: - - name: Testing custom sections - details: Wohooo! - - name: This is a - details: OneLineEntry! - - title: My Other Custom Section - entry_type: EducationEntry - entries: - - institution: Hop! - area: Hop! - study_type: HA - highlights: - - "There are only five types of entries: *EducationEntry*, *ExperienceEntry*, - *NormalEntry*, *OneLineEntry*, and *PublicationEntry*." - - This is an EducationEntry! - start_date: "2022-06-15" - end_date: "2022-08-01" - - title: My Third Custom Section - entry_type: ExperienceEntry - entries: - - company: Hop! - position: Hop! - date: My Date - location: My Location - highlights: - - I think this is really working. This is an *ExperienceEntry*! - - - title: My Final Custom Section - entry_type: NormalEntry - link_text: My Link Text - entries: - - name: This is a normal entry! - url: https://example.com - highlights: - - You don't have to specify a *date* or **location** every time. - - You can use *Markdown* in the **highlights**! - - "Special characters test: üğç" - -design: - theme: classic - font: SourceSans3 - font_size: 10pt - page_size: a4paper - options: - primary_color: rgb(0,79,144) - date_and_location_width: 3.6 cm - show_timespan_in: - - Work Experience - - My Other Custom Section - show_last_updated_date: True - text_alignment: justified - header_font_size: 30 pt - - margins: - page: - top: 2 cm - bottom: 2 cm - left: 1.24 cm - right: 1.24 cm - section_title: - top: 0.2 cm - bottom: 0.2 cm - - entry_area: - left_and_right: 0.2 cm - vertical_between: 0.2 cm - - highlights_area: - top: 0.10 cm - left: 0.4 cm - vertical_between_bullet_points: 0.10 cm - - header: - vertical_between_name_and_connections: 0.2 cm - bottom: 0.2 cm \ No newline at end of file diff --git a/rendercv/themes/__init__.py b/rendercv/themes/__init__.py new file mode 100644 index 0000000..c6b075d --- /dev/null +++ b/rendercv/themes/__init__.py @@ -0,0 +1,253 @@ +"""This module containts some general-purpose data models for the themes. The themes +are encouraged to inherit from these data models and add their own options, to avoid +code duplication. +""" + +from typing import Literal, Annotated + +import pydantic +import pydantic_extra_types.color as pydantic_color + +# Create a custom type called LaTeXDimension that accepts only strings in a specified +# format. +# This type is used to validate the dimension fields in the design data. +# See https://docs.pydantic.dev/2.5/concepts/types/#custom-types for more information +# about custom types. +LaTeXDimension = Annotated[ + str, + pydantic.Field( + pattern=r"\d+\.?\d* *(cm|in|pt|mm|ex|em)", + ), +] + + +class PageMargins(pydantic.BaseModel): + """This class is a data model for the page margins.""" + + top: LaTeXDimension = pydantic.Field( + default="2 cm", + title="Top Margin", + description="The top margin of the page with units. The default value is 2 cm.", + ) + bottom: LaTeXDimension = pydantic.Field( + default="2 cm", + title="Bottom Margin", + description=( + "The bottom margin of the page with units. The default value is 2 cm." + ), + ) + left: LaTeXDimension = pydantic.Field( + default="2 cm", + title="Left Margin", + description=( + "The left margin of the page with units. The default value is 2 cm." + ), + ) + right: LaTeXDimension = pydantic.Field( + default="2 cm", + title="Right Margin", + description=( + "The right margin of the page with units. The default value is 2 cm." + ), + ) + + +class SectionTitleMargins(pydantic.BaseModel): + """This class is a data model for the section title margins.""" + + top: LaTeXDimension = pydantic.Field( + default="0.3 cm", + title="Top Margin", + description="The top margin of section titles. The default value is 0.3 cm.", + ) + bottom: LaTeXDimension = pydantic.Field( + default="0.2 cm", + title="Bottom Margin", + description="The bottom margin of section titles. The default value is 0.3 cm.", + ) + + +class EntryAreaMargins(pydantic.BaseModel): + """This class is a data model for the entry area margins.""" + + left_and_right: LaTeXDimension = pydantic.Field( + default="0.2 cm", + title="Left Margin", + description="The left margin of entry areas. The default value is 0.2 cm.", + ) + + vertical_between: LaTeXDimension = pydantic.Field( + default="0.2 cm", + title="Vertical Margin Between Entry Areas", + description=( + "The vertical margin between entry areas. The default value is 0.2 cm." + ), + ) + + date_and_location_width: LaTeXDimension = pydantic.Field( + default="4.1 cm", + title="Date and Location Column Width", + description=( + "The width of the date and location column. The default value is 4.1 cm." + ), + ) + + +class HighlightsAreaMargins(pydantic.BaseModel): + """This class is a data model for the highlights area margins.""" + + top: LaTeXDimension = pydantic.Field( + default="0.10 cm", + title="Top Margin", + description="The top margin of highlights areas. The default value is 0.10 cm.", + ) + left: LaTeXDimension = pydantic.Field( + default="0.4 cm", + title="Left Margin", + description="The left margin of highlights areas. The default value is 0.4 cm.", + ) + vertical_between_bullet_points: LaTeXDimension = pydantic.Field( + default="0.10 cm", + title="Vertical Margin Between Bullet Points", + description=( + "The vertical margin between bullet points. The default value is 0.10 cm." + ), + ) + + +class HeaderMargins(pydantic.BaseModel): + """This class is a data model for the header margins.""" + + vertical_between_name_and_connections: LaTeXDimension = pydantic.Field( + default="0.3 cm", + title="Vertical Margin Between the Name and Connections", + description=( + "The vertical margin between the name of the person and the connections." + " The default value is 0.3 cm." + ), + ) + bottom: LaTeXDimension = pydantic.Field( + default="0.3 cm", + title="Bottom Margin", + description=( + "The bottom margin of the header, i.e., the vertical margin between the" + " connections and the first section title. The default value is 0.3 cm." + ), + ) + horizontal_between_connections: LaTeXDimension = pydantic.Field( + default="0.5 cm", + title="Space Between Connections", + description=( + "The space between the connections (like phone, email, and website). The" + " default value is 0.5 cm." + ), + ) + + +class Margins(pydantic.BaseModel): + """This class is a data model for the margins.""" + + page: PageMargins = pydantic.Field( + default=PageMargins(), + title="Page Margins", + description="Page margins.", + ) + section_title: SectionTitleMargins = pydantic.Field( + default=SectionTitleMargins(), + title="Section Title Margins", + description="Section title margins.", + ) + entry_area: EntryAreaMargins = pydantic.Field( + default=EntryAreaMargins(), + title="Entry Area Margins", + description="Entry area margins.", + ) + highlights_area: HighlightsAreaMargins = pydantic.Field( + default=HighlightsAreaMargins(), + title="Highlights Area Margins", + description="Highlights area margins.", + ) + header: HeaderMargins = pydantic.Field( + default=HeaderMargins(), + title="Header Margins", + description="Header margins.", + ) + + +class ThemeOptions(pydantic.BaseModel): + """This class is a generic data model for the theme options. The themes are + encouraged to inherit from this data model and add their own options, to avoid code + duplication. + """ + + model_config = pydantic.ConfigDict(extra="forbid") + + font_size: Literal["10pt", "11pt", "12pt"] = pydantic.Field( + default="10pt", + title="Font Size", + description="The font size of the CV. The default value is 10pt.", + ) + page_size: Literal["a4paper", "letterpaper"] = pydantic.Field( + default="letterpaper", + title="Page Size", + description=( + "The page size of the CV. It can be a4paper or letterpaper. The default" + " value is letterpaper." + ), + ) + color: pydantic_color.Color = pydantic.Field( + default="rgb(0,79,144)", + validate_default=True, + title="Primary Color", + description=( + "The primary color of the theme. \nThe color can be specified either with" + " their [name](https://www.w3.org/TR/SVG11/types.html#ColorKeywords)," + " hexadecimal value, RGB value, or HSL value. The default value is" + " rgb(0,79,144)." + ), + examples=["Black", "7fffd4", "rgb(0,79,144)", "hsl(270, 60%, 70%)"], + ) + disable_page_numbering: bool = pydantic.Field( + default=False, + title="Disable Page Numbering", + description=( + "If this option is set to true, then the page numbering will be disabled." + " The default value is false." + ), + ) + page_numbering_style: str = pydantic.Field( + default="NAME - Page PAGE_NUMBER of TOTAL_PAGES", + title="Page Numbering Style", + description=( + "The style of the page numbering. The following placeholders can be used:" + "\n- NAME: The name of the person\n- PAGE_NUMBER: The current page number" + "\n- TOTAL_PAGES: The total number of pages\nThe default value is" + " NAME - Page PAGE_NUMBER of TOTAL_PAGES." + ), + ) + show_last_updated_date: bool = pydantic.Field( + default=True, + title="Show Last Updated Date", + description=( + "If this option is set to true, then the last updated date will be shown" + " in the header. The default value is true." + ), + ) + header_font_size: LaTeXDimension = pydantic.Field( + default="30 pt", + title="Header Font Size", + description=( + "The font size of the header (the name of the person). The default value is" + " 30 pt." + ), + ) + text_alignment: Literal["left-aligned", "justified"] = pydantic.Field( + default="justified", + title="Text Alignment", + description="The alignment of the text. The default value is justified.", + ) + margins: Margins = pydantic.Field( + default=Margins(), + title="Margins", + description="Page, section title, entry field, and highlights field margins.", + ) diff --git a/rendercv/themes/classic/EducationEntry.j2.tex b/rendercv/themes/classic/EducationEntry.j2.tex new file mode 100644 index 0000000..ec3776d --- /dev/null +++ b/rendercv/themes/classic/EducationEntry.j2.tex @@ -0,0 +1,44 @@ +((* if section_title in design.show_timespan_in *)) + ((* set date_and_location_strings = [entry.location, entry.date_string, entry.time_span_string] *)) +((* else *)) + ((* set date_and_location_strings = [entry.location, entry.date_string] *)) +((* endif *)) +((* if not is_first_entry *)) +\vspace{<<design.margins.entry_area.vertical_between>>} +((* endif *)) +((# \begin{tabularx}{⟨width⟩}[⟨pos⟩]{⟨preamble⟩} #)) + ((# width: \textwidth #)) + ((# preamble: first column, second column, third column #)) + ((# first column: p{0.55cm}; constant width, ragged left column #)) + ((# second column: K{<<design.margins.entry_area.left_and_right>>}; variable width, justified column #)) + ((# third column: R{<<design.margins.entry_area.date_and_location_width>>}; constant widthm ragged right column #)) +\begin{tabularx}{ + \textwidth-<<design.margins.entry_area.left_and_right|divide_length_by(0.5)>>-0.13cm +}{ + L{0.85cm} + K{<<design.margins.entry_area.left_and_right>>} + R{<<design.margins.entry_area.date_and_location_width>>} +} + \textbf{<<entry.degree>>} + & + \textbf{<<entry.institution>>}, <<entry.area>> + + \vspace{<<design.margins.highlights_area.top>>} + +((* for item in entry.highlights *)) + ((* if loop.first *)) + \begin{highlights} + ((* endif *)) + \item <<item>> + ((* if loop.last *)) + \end{highlights} + ((* endif *)) +((* endfor *)) + & +((* for item in date_and_location_strings *)) + <<item>> + ((* if not loop.last *)) + + ((* endif *)) +((* endfor *)) +\end{tabularx} diff --git a/rendercv/themes/classic/ExperienceEntry.j2.tex b/rendercv/themes/classic/ExperienceEntry.j2.tex new file mode 100644 index 0000000..3cd5043 --- /dev/null +++ b/rendercv/themes/classic/ExperienceEntry.j2.tex @@ -0,0 +1,40 @@ +((* if section_title in design.show_timespan_in *)) + ((* set date_and_location_strings = [entry.location, entry.date_string, entry.time_span_string] *)) +((* else *)) + ((* set date_and_location_strings = [entry.location, entry.date_string] *)) +((* endif *)) +((* if not is_first_entry *)) +\vspace{<<design.margins.entry_area.vertical_between>>} +((* endif *)) +((# \begin{tabularx}{⟨width⟩}[⟨pos⟩]{⟨preamble⟩} #)) + ((# width: \textwidth #)) + ((# preamble: first column, second column #)) + ((# first column:: K{<<design.margins.entry_area.left_and_right>>}; variable width, justified column #)) + ((# second column: R{<<design.margins.entry_area.date_and_location_width>>}; constant width ragged right column #)) +\begin{tabularx}{ + \textwidth-<<design.margins.entry_area.left_and_right|divide_length_by(0.5)>>-0.13cm +}{ + K{<<design.margins.entry_area.left_and_right>>} + R{<<design.margins.entry_area.date_and_location_width>>} +} + \textbf{<<entry.company>>}, <<entry.position>> + + \vspace{<<design.margins.highlights_area.top>>} + +((* for item in entry.highlights *)) + ((* if loop.first *)) + \begin{highlights} + ((* endif *)) + \item <<item>> + ((* if loop.last *)) + \end{highlights} + ((* endif *)) +((* endfor *)) + & +((* for item in date_and_location_strings *)) + <<item>> + ((* if not loop.last *)) + + ((* endif *)) +((* endfor *)) +\end{tabularx} diff --git a/rendercv/themes/classic/Header.j2.tex b/rendercv/themes/classic/Header.j2.tex new file mode 100644 index 0000000..91d3539 --- /dev/null +++ b/rendercv/themes/classic/Header.j2.tex @@ -0,0 +1,52 @@ +((* set orcid_url = (cv.social_networks|get_an_item_with_a_specific_attribute_value("network", "Orcid")).url *)) +((* if design.show_last_updated_date *)) +\placelastupdatedtext +((* endif *)) +((* if cv.name is not none *)) +\begin{header} + \fontsize{<<design.header_font_size>>}{<<design.header_font_size>>} + ((* if orcid_url *)) + \hrefWithoutArrow{<<orcid_url>>}{\textbf{<<cv.name>>}} + ((* else *)) + \textbf{<<cv.name>>} + ((* endif *)) + + \vspace{<<design.margins.header.vertical_between_name_and_connections>>} + + \normalsize +((* if cv.phone *)) + \mbox{\hrefWithoutArrow{<<cv.phone|replace("-","")>>}{{\footnotesize\faPhone*}\hspace*{0.13cm}<<cv.phone|replace("tel:", "")|replace("-"," ")>>}} + \hspace*{<<design.margins.header.horizontal_between_connections>>} +((* endif *)) +((* if cv.email *)) + \mbox{\hrefWithoutArrow{mailto:<<cv.email>>}{{\small\faEnvelope[regular]}\hspace*{0.13cm}<<cv.email>>}} + \hspace*{<<design.margins.header.horizontal_between_connections>>} +((* endif *)) +((* if cv.location *)) + \mbox{{\small\faMapMarker*}\hspace*{0.13cm}<<cv.location>>} + \hspace*{<<design.margins.header.horizontal_between_connections>>} +((* endif *)) +((* if cv.website *)) + \mbox{\hrefWithoutArrow{<<cv.website>>}{{\small\faLink}\hspace*{0.13cm}<<cv.website|replace("https://","")|reverse|replace("/", "", 1)|reverse>>}} + \hspace*{<<design.margins.header.horizontal_between_connections>>} +((* endif *)) +((* + set icon_dictionary = { + "LinkedIn": "\\faLinkedinIn", + "GitHub": "\\faGithub", + "Instagram": "\\faInstagram", + "Mastodon": "\\faMastodon", + } +*)) +((* if cv.social_networks *)) + ((* for network in cv.social_networks *)) + ((* if network.network in icon_dictionary *)) + \mbox{\hrefWithoutArrow{<<network.url>>}{{\small<<icon_dictionary[network.network]>>}\hspace*{0.13cm}<<network.username>>}} + \hspace*{<<design.margins.header.horizontal_between_connections>>} + ((* endif *)) + ((* endfor *)) +((* endif *)) +\end{header} + +\vspace{<<design.margins.header.bottom>>} +((* endif *)) \ No newline at end of file diff --git a/rendercv/themes/classic/NormalEntry.j2.tex b/rendercv/themes/classic/NormalEntry.j2.tex new file mode 100644 index 0000000..03eb128 --- /dev/null +++ b/rendercv/themes/classic/NormalEntry.j2.tex @@ -0,0 +1,66 @@ +((* if section_title in design.show_timespan_in *)) + ((* set date_and_location_strings = [entry.location, entry.date_string, entry.time_span_string] *)) +((* else *)) + ((* set date_and_location_strings = [entry.location, entry.date_string] *)) +((* endif *)) +((* if not is_first_entry *)) +\vspace{<<design.margins.entry_area.vertical_between>>} +((* endif *)) +((* if date_and_location_strings == ["", "", ""] or date_and_location_strings == ["", ""] *)) +((# \begin{tabularx}{⟨width⟩}[⟨pos⟩]{⟨preamble⟩} #)) + ((# width: \textwidth #)) + ((# preamble: first column #)) + ((# first column:: K{<<design.margins.entry_area.left_and_right>>}; variable width, justified column #)) +\begin{tabularx}{ + \textwidth-<<design.margins.entry_area.left_and_right|divide_length_by(0.5)>>-0.13cm +}{ + K{<<design.margins.entry_area.left_and_right>>} +} + \textbf{<<entry.name>>} + + \vspace{<<design.margins.highlights_area.top>>} + + ((* for item in entry.highlights *)) + ((* if loop.first *)) + \begin{highlights} + ((* endif *)) + \item <<item>> + ((* if loop.last *)) + \end{highlights} + ((* endif *)) + ((* endfor *)) +\end{tabularx} +((* else *)) +((# \begin{tabularx}{⟨width⟩}[⟨pos⟩]{⟨preamble⟩} #)) + ((# width: \textwidth #)) + ((# preamble: first column, second column #)) + ((# first column:: K{<<design.margins.entry_area.left_and_right>>}; variable width, justified column #)) + ((# second column: R{<<design.margins.entry_area.date_and_location_width>>}; constant width ragged right column #)) +\begin{tabularx}{ + \textwidth-<<design.margins.entry_area.left_and_right|divide_length_by(0.5)>>-0.13cm +}{ + K{<<design.margins.entry_area.left_and_right>>} + R{<<design.margins.entry_area.date_and_location_width>>} +} + \textbf{<<entry.name>>} + + \vspace{<<design.margins.highlights_area.top>>} + + ((* for item in entry.highlights *)) + ((* if loop.first *)) + \begin{highlights} + ((* endif *)) + \item <<item>> + ((* if loop.last *)) + \end{highlights} + ((* endif *)) + ((* endfor *)) + & + ((* for item in date_and_location_strings *)) + <<item>> + ((* if not loop.last *)) + + ((* endif *)) + ((* endfor *)) +\end{tabularx} +((* endif *)) diff --git a/rendercv/themes/classic/OneLineEntry.j2.tex b/rendercv/themes/classic/OneLineEntry.j2.tex new file mode 100644 index 0000000..6ec1748 --- /dev/null +++ b/rendercv/themes/classic/OneLineEntry.j2.tex @@ -0,0 +1,10 @@ +((* if not is_first_entry *)) +\vspace{<<design.margins.entry_area.vertical_between>>} +((* endif *)) +\begingroup((* if design.text_alignment == "left-aligned" *))\raggedright((* endif *)) +\leftskip=<<design.margins.entry_area.left_and_right>> +\advance\csname @rightskip\endcsname <<design.margins.entry_area.left_and_right>> +\advance\rightskip <<design.margins.entry_area.left_and_right>> + +\textbf{<<entry.name>>:} <<entry.details>> ((* if entry.url *)) (\href{<<entry.url>>}{<<entry.url_text>>}) ((* endif *)) +\par\endgroup \ No newline at end of file diff --git a/rendercv/templates/classic/classic.tex.j2 b/rendercv/themes/classic/Preamble.j2.tex similarity index 55% rename from rendercv/templates/classic/classic.tex.j2 rename to rendercv/themes/classic/Preamble.j2.tex index 2afbd50..0c0666e 100644 --- a/rendercv/templates/classic/classic.tex.j2 +++ b/rendercv/themes/classic/Preamble.j2.tex @@ -1,27 +1,23 @@ -((# IMPORT MACROS #)) -((* from "components/section_contents.tex.j2" import section_contents with context *)) -((* from "components/header.tex.j2" import header with context *)) - \documentclass[<<design.font_size>>, <<design.page_size>>]{article} % Packages: \usepackage[ ignoreheadfoot, % set margins without considering header and footer - top=<<theme_options.margins.page.top>>, % seperation between body and page edge from the top - bottom=<<theme_options.margins.page.bottom>>, % seperation between body and page edge from the bottom - left=<<theme_options.margins.page.left>>, % seperation between body and page edge from the left - right=<<theme_options.margins.page.right>>, % seperation between body and page edge from the right - footskip=<<theme_options.margins.page.bottom|divide_length_by(2)>>, % seperation between body and footer + top=<<design.margins.page.top>>, % seperation between body and page edge from the top + 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 + footskip=<<design.margins.page.bottom|divide_length_by(2)>>, % seperation between body and footer % showframe % for debugging ]{geometry} % for adjusting page geometry -\usepackage{fontspec} % for loading fonts \usepackage[explicit]{titlesec} % for customizing section titles \usepackage{tabularx} % for making tables with fixed width columns \usepackage{array} % tabularx requires this \usepackage[dvipsnames]{xcolor} % for coloring text -\definecolor{primaryColor}{RGB}{<<theme_options.primary_color.as_rgb_tuple()|join(", ")>>} % define primary color +\definecolor{primaryColor}{RGB}{<<design.color.as_rgb_tuple()|join(", ")>>} % define primary color \usepackage{enumitem} % for customizing lists \usepackage{fontawesome5} % for using icons +\usepackage{amsmath} % for math \usepackage[ pdftitle={<<cv.name>>'s CV}, pdfauthor={<<cv.name>>}, @@ -32,29 +28,30 @@ \usepackage{calc} % for calculating lengths \usepackage{bookmark} % for bookmarks \usepackage{lastpage} % for getting the total number of pages +\usepackage[default, type1]{sourcesanspro} % for using source sans 3 font +\usepackage{ifthen} % Some settings: \pagestyle{empty} % no header or footer \setcounter{secnumdepth}{0} % no section numbering \setlength{\parindent}{0pt} % no indentation \setlength{\topskip}{0pt} % no top skip -((# \pagenumbering{gobble} % no page numbering #)) +((* if design.disable_page_numbering *)) +\pagenumbering{gobble} % no page numbering +((* else *)) +((* set page_numbering_style_placeholders = { + "NAME": cv.name, + "PAGE_NUMBER": "\\thepage{}", + "TOTAL_PAGES": "\pageref*{LastPage}" +} *)) \makeatletter \let\ps@customFooterStyle\ps@plain % Copy the plain style to customFooterStyle \patchcmd{\ps@customFooterStyle}{\thepage}{ - \color{gray}\textit{\small <<cv.name>> | Page \thepage{} of \pageref*{LastPage}} + \color{gray}\textit{\small <<design.page_numbering_style|replace_placeholders_with_actual_values(page_numbering_style_placeholders)>>} }{}{} % replace number by desired string \makeatother \pagestyle{customFooterStyle} - -\setmainfont{<<design.font>>}[ - Path= fonts/, - Extension = .ttf, - UprightFont = *-Regular, - ItalicFont = *-Italic, - BoldFont = *-Bold, - BoldItalicFont = *-BoldItalic -] +((* endif *)) \titleformat{\section}{ % make the font size of the section title large and color it with the primary color @@ -72,10 +69,10 @@ 0pt }{ % top space: - <<theme_options.margins.section_title.top>> + <<design.margins.section_title.top>> }{ % bottom space: - <<theme_options.margins.section_title.bottom>> + <<design.margins.section_title.bottom>> } % section title spacing \newcolumntype{L}[1]{ @@ -84,11 +81,11 @@ \newcolumntype{R}[1]{ >{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1} } % right-aligned fixed width column type -((* if theme_options.text_alignment == "justified" *)) +((* if design.text_alignment == "justified" *)) \newcolumntype{K}[1]{ >{\let\newline\\\arraybackslash\hspace{0pt}}X } % justified flexible width column type -((* elif theme_options.text_alignment == "left-aligned" *)) +((* elif design.text_alignment == "left-aligned" *)) \newcolumntype{K}[1]{ >{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}X } % left-aligned flexible width column type @@ -97,11 +94,11 @@ \newenvironment{highlights}{ \begin{itemize}[ topsep=0pt, - parsep=<<theme_options.margins.highlights_area.vertical_between_bullet_points>>, + parsep=<<design.margins.highlights_area.vertical_between_bullet_points>>, partopsep=0pt, itemsep=0pt, after=\vspace{-1\baselineskip}, - leftmargin=<<theme_options.margins.highlights_area.left>> + 3pt + leftmargin=<<design.margins.highlights_area.left>> + 3pt ] }{ \end{itemize} @@ -116,8 +113,8 @@ \newcommand{\placelastupdatedtext}{% \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>} \AddToShipoutPictureFG*{% Add <stuff> to current page foreground \put( - \LenToUnit{\paperwidth-<<theme_options.margins.page.right>>-<<theme_options.margins.entry_area.left_and_right>>+0.05cm}, - \LenToUnit{\paperheight-<<theme_options.margins.page.top|divide_length_by(2)>>} + \LenToUnit{\paperwidth-<<design.margins.page.right>>-<<design.margins.entry_area.left_and_right>>+0.05cm}, + \LenToUnit{\paperheight-<<design.margins.page.top|divide_length_by(2)>>} ){\vtop{{\null}\makebox[0pt][c]{ \small\color{gray}\textit{Last updated in <<today>>}\hspace{\widthof{Last updated in <<today>>}} }}}% @@ -127,37 +124,16 @@ % save the original href command in a new command: \let\hrefWithoutArrow\href % new command for external links: -\renewcommand{\href}[2]{\hrefWithoutArrow{#1}{#2 \raisebox{.15ex}{\footnotesize \faExternalLink*}}} +\renewcommand{\href}[2]{\hrefWithoutArrow{#1}{\mbox{\ifthenelse{\equal{#2}{}}{ }{#2 }\raisebox{.15ex}{\footnotesize \faExternalLink*}}}} -\begin{document} -((* if theme_options.show_last_updated_date *)) - \placelastupdatedtext -((* endif *)) +\let\originalTabularx\tabularx +\let\originalEndTabularx\endtabularx - <<header(name=cv.name, connections=cv.connections)|indent(4)>> +\renewenvironment{tabularx}{\bgroup\centering\originalTabularx}{\originalEndTabularx\par\egroup} -((* if cv.summary is not none *)) - \section{Summary} - { - ((* if theme_options.text_alignment == "left-aligned" *)) - \raggedright - ((* endif *)) - \setlength{\leftskip}{<<theme_options.margins.entry_area.left_and_right>>} - \setlength{\rightskip}{<<theme_options.margins.entry_area.left_and_right>>} +% For TextEntrys (see https://tex.stackexchange.com/a/600/287984): +\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1\topsep=0pt\itemsep=0pt\parsep=0pt\parskip=0pt\labelwidth=0pt\itemindent=0pt\labelsep=0pt}\item[]} +\let\endchangemargin=\endlist - <<cv.summary>> - - \setlength{\leftskip}{0cm} - \setlength{\rightskip}{0cm} - } -((* endif *)) - - \centering -((* for section in cv.sections *)) - \section{<<section.title>>} - - <<section_contents(title=section.title, entries=section.entries, entry_type=section.entry_type, link_text=section.link_text)|indent(4)>> - -((* endfor *)) - -\end{document} \ No newline at end of file +% Ensure that generate pdf is machine readable/ATS parsable +\pdfgentounicode=1 \ No newline at end of file diff --git a/rendercv/themes/classic/PublicationEntry.j2.tex b/rendercv/themes/classic/PublicationEntry.j2.tex new file mode 100644 index 0000000..7601c37 --- /dev/null +++ b/rendercv/themes/classic/PublicationEntry.j2.tex @@ -0,0 +1,21 @@ +((* if not is_first_entry *)) +\vspace{<<design.margins.entry_area.vertical_between>>} +((* endif *)) +((# \begin{tabularx}{⟨width⟩}[⟨pos⟩]{⟨preamble⟩} #)) + ((# width: \textwidth #)) + ((# preamble: first column, second column #)) + ((# first column:: K{<<design.margins.entry_area.left_and_right>>}; variable width, justified column #)) + ((# second column: R{<<design.margins.entry_area.date_and_location_width>>}; constant width ragged right column #)) +\begin{tabularx}{\textwidth-<<design.margins.entry_area.left_and_right|divide_length_by(0.5)>>-0.13cm}{K{<<design.margins.entry_area.left_and_right>>} R{<<design.margins.entry_area.date_and_location_width>>}} + \textbf{<<entry.title>>} + + \vspace{<<design.margins.highlights_area.vertical_between_bullet_points>>} + + <<entry.authors|map("abbreviate_name")|map("make_it_nolinebreak")|join(", ")|make_it_bold(cv.name|abbreviate_name)|make_it_italic(cv.name|abbreviate_name)>> + + \vspace{<<design.margins.highlights_area.vertical_between_bullet_points>>} + + \href{<<entry.doi_url>>}{<<entry.doi>>} ((* if entry.journal is not none *))(<<entry.journal>>)((* endif *)) + & + <<entry.date_string>> +\end{tabularx} diff --git a/rendercv/themes/classic/SectionBeginning.j2.tex b/rendercv/themes/classic/SectionBeginning.j2.tex new file mode 100644 index 0000000..b72afb4 --- /dev/null +++ b/rendercv/themes/classic/SectionBeginning.j2.tex @@ -0,0 +1 @@ +\section{<<section_title>>} \ No newline at end of file diff --git a/rendercv/themes/classic/SectionEnding.j2.tex b/rendercv/themes/classic/SectionEnding.j2.tex new file mode 100644 index 0000000..e69de29 diff --git a/rendercv/themes/classic/TextEntry.j2.tex b/rendercv/themes/classic/TextEntry.j2.tex new file mode 100644 index 0000000..4c72719 --- /dev/null +++ b/rendercv/themes/classic/TextEntry.j2.tex @@ -0,0 +1,15 @@ +((* if not is_first_entry *)) +\vspace{<<design.margins.entry_area.vertical_between>>} +((* endif *)) +\begin{changemargin}{<<design.margins.entry_area.left_and_right>>}{<<design.margins.entry_area.left_and_right>>} +((* if design.text_alignment == "left-aligned" *)) +\raggedright +((* endif *)) +<<entry>> +((* if design.text_alignment == "left-aligned" *)) +\par +((* endif *)) +\end{changemargin} + + + diff --git a/rendercv/themes/classic/__init__.py b/rendercv/themes/classic/__init__.py new file mode 100644 index 0000000..77fa100 --- /dev/null +++ b/rendercv/themes/classic/__init__.py @@ -0,0 +1,21 @@ +from typing import Literal + +import pydantic + +from .. import ThemeOptions + + +class ClassicThemeOptions(ThemeOptions): + """This class is the data model of the theme options for the classic theme.""" + + theme: Literal["classic"] + show_timespan_in: list[str] = pydantic.Field( + default=[], + title="Show Time Span in These Sections", + description=( + "The time span will be shown in the date and location column in these" + " sections. The input should be a list of section titles as strings" + " (case-sensitive). The default value is an empty list, which means the" + " time span will not be shown in any section." + ), + ) diff --git a/rendercv/themes/main.j2.md b/rendercv/themes/main.j2.md new file mode 100644 index 0000000..09e21d0 --- /dev/null +++ b/rendercv/themes/main.j2.md @@ -0,0 +1,9 @@ +<<header>> + +((* for section_beginning, entries in sections*)) +<<section_beginning>> + + ((* for entry in entries *)) +<<entry>> + ((* endfor *)) +((* endfor *)) diff --git a/rendercv/themes/main.j2.tex b/rendercv/themes/main.j2.tex new file mode 100644 index 0000000..178edfb --- /dev/null +++ b/rendercv/themes/main.j2.tex @@ -0,0 +1,17 @@ +<<preamble>> + +\begin{document} + <<header|indent(4)>> + +((* for section_beginning, entries, section_ending in sections*)) + <<section_beginning|indent(4)>> + + ((* for entry in entries *)) + <<entry|indent(8)>> + + ((* endfor *)) + + <<section_ending|indent(4)>> +((* endfor *)) + +\end{document} \ No newline at end of file diff --git a/rendercv/themes/markdown/EducationEntry.j2.md b/rendercv/themes/markdown/EducationEntry.j2.md new file mode 100644 index 0000000..431f642 --- /dev/null +++ b/rendercv/themes/markdown/EducationEntry.j2.md @@ -0,0 +1,9 @@ +## <<entry.institution>>, ((* if entry.degree *))<<entry.degree>> in ((* endif *))<<entry.area>> + +((* if entry.date_string *))- <<entry.date_string>> ((* endif *)) + +((* if entry.location *))- <<entry.location>> ((* endif *)) + +((* for item in entry.highlights *)) +- <<item>> +((* endfor *)) diff --git a/rendercv/themes/markdown/ExperienceEntry.j2.md b/rendercv/themes/markdown/ExperienceEntry.j2.md new file mode 100644 index 0000000..c998edd --- /dev/null +++ b/rendercv/themes/markdown/ExperienceEntry.j2.md @@ -0,0 +1,9 @@ +## <<entry.company>>, <<entry.position>> + +((* if entry.date_string *))- <<entry.date_string>> ((* endif *)) + +((* if entry.location *))- <<entry.location>> ((* endif *)) + +((* for item in entry.highlights *)) +- <<item>> +((* endfor *)) diff --git a/rendercv/themes/markdown/Header.j2.md b/rendercv/themes/markdown/Header.j2.md new file mode 100644 index 0000000..b897996 --- /dev/null +++ b/rendercv/themes/markdown/Header.j2.md @@ -0,0 +1,19 @@ +# <<cv.name>>'s CV + +((* if cv.phone *)) +- Phone: <<cv.phone|replace("tel:", "")|replace("-"," ")>> +((* endif *)) +((* if cv.email *)) +- Email: [<<cv.email>>](mailto:<<cv.email>>) +((* endif *)) +((* if cv.location *)) +- Location: <<cv.location>> +((* endif *)) +((* if cv.website *)) +- Website: [<<cv.website|replace("https://","")|replace("/","")>>](<<cv.website>>) +((* endif *)) +((* if cv.social_networks *)) + ((* for network in cv.social_networks *)) +- <<network.network>>: [<<network.username>>](<<network.url>>) + ((* endfor *)) +((* endif *)) diff --git a/rendercv/themes/markdown/NormalEntry.j2.md b/rendercv/themes/markdown/NormalEntry.j2.md new file mode 100644 index 0000000..cfa1860 --- /dev/null +++ b/rendercv/themes/markdown/NormalEntry.j2.md @@ -0,0 +1,7 @@ +## <<entry.name>> + +((* if entry.date_string *))- <<entry.date_string>> ((* endif *)) +((* if entry.location *))- <<entry.location>> ((* endif *)) +((* for item in entry.highlights *)) +- <<item>> +((* endfor *)) diff --git a/rendercv/themes/markdown/OneLineEntry.j2.md b/rendercv/themes/markdown/OneLineEntry.j2.md new file mode 100644 index 0000000..33d622f --- /dev/null +++ b/rendercv/themes/markdown/OneLineEntry.j2.md @@ -0,0 +1 @@ +- <<entry.name>>: <<entry.details>> \ No newline at end of file diff --git a/rendercv/themes/markdown/PublicationEntry.j2.md b/rendercv/themes/markdown/PublicationEntry.j2.md new file mode 100644 index 0000000..1edff20 --- /dev/null +++ b/rendercv/themes/markdown/PublicationEntry.j2.md @@ -0,0 +1,5 @@ +## <<entry.title>> ([<<entry.doi>>](<<entry.doi_url>>)) + +- <<entry.date_string>> +- <<entry.authors|map("abbreviate_name")|join(", ")>> +((* if entry.journal *))- <<entry.journal>> ((* endif *)) diff --git a/rendercv/themes/markdown/SectionBeginning.j2.md b/rendercv/themes/markdown/SectionBeginning.j2.md new file mode 100644 index 0000000..5d2a0c8 --- /dev/null +++ b/rendercv/themes/markdown/SectionBeginning.j2.md @@ -0,0 +1 @@ +# <<section_title>> \ No newline at end of file diff --git a/rendercv/themes/markdown/TextEntry.j2.md b/rendercv/themes/markdown/TextEntry.j2.md new file mode 100644 index 0000000..68019b1 --- /dev/null +++ b/rendercv/themes/markdown/TextEntry.j2.md @@ -0,0 +1 @@ +<<entry>> diff --git a/rendercv/themes/moderncv/EducationEntry.j2.tex b/rendercv/themes/moderncv/EducationEntry.j2.tex new file mode 100644 index 0000000..762c3cb --- /dev/null +++ b/rendercv/themes/moderncv/EducationEntry.j2.tex @@ -0,0 +1,4 @@ +\cventry{((* if design.show_only_years *))<<entry.date_string_only_years>>((* else *))<<entry.date_string>>((* endif *))}{((* if entry.degree != "" *))<<entry.degree>>, ((* endif *))<<entry.area>>}{<<entry.institution>>}{<<entry.location>>}{}{} +((* for item in entry.highlights *)) +\cvline{}{\small <<item>>} +((* endfor *)) \ No newline at end of file diff --git a/rendercv/themes/moderncv/ExperienceEntry.j2.tex b/rendercv/themes/moderncv/ExperienceEntry.j2.tex new file mode 100644 index 0000000..352f410 --- /dev/null +++ b/rendercv/themes/moderncv/ExperienceEntry.j2.tex @@ -0,0 +1,4 @@ +\cventry{((* if design.show_only_years *))<<entry.date_string_only_years>>((* else *))<<entry.date_string>>((* endif *))}{<<entry.position>>}{<<entry.company>>}{<<entry.location>>}{}{} +((* for item in entry.highlights *)) +\cvline{}{\small <<item>>} +((* endfor *)) \ No newline at end of file diff --git a/rendercv/themes/moderncv/Header.j2.tex b/rendercv/themes/moderncv/Header.j2.tex new file mode 100644 index 0000000..591f326 --- /dev/null +++ b/rendercv/themes/moderncv/Header.j2.tex @@ -0,0 +1,9 @@ +((* if cv.name is not none *)) +\maketitle +((* endif *)) + + +% save the original href command in a new command: +\let\hrefWithoutArrow\href + % new command for external links: +\renewcommand{\href}[2]{\hrefWithoutArrow{#1}{\mbox{\color{color1} #2 \raisebox{.15ex}{\footnotesize \faExternalLink*}}}} \ No newline at end of file diff --git a/rendercv/themes/moderncv/NormalEntry.j2.tex b/rendercv/themes/moderncv/NormalEntry.j2.tex new file mode 100644 index 0000000..aec1921 --- /dev/null +++ b/rendercv/themes/moderncv/NormalEntry.j2.tex @@ -0,0 +1,4 @@ +\cventry{((* if design.show_only_years *))<<entry.date_string_only_years>>((* else *))<<entry.date_string>>((* endif *))}{<<entry.name>>}{}{<<entry.location>>}{}{} +((* for item in entry.highlights *)) +\cvline{}{\small <<item>>} +((* endfor *)) \ No newline at end of file diff --git a/rendercv/themes/moderncv/OneLineEntry.j2.tex b/rendercv/themes/moderncv/OneLineEntry.j2.tex new file mode 100644 index 0000000..477931f --- /dev/null +++ b/rendercv/themes/moderncv/OneLineEntry.j2.tex @@ -0,0 +1 @@ +\cvline{<<entry.name>>}{<<entry.details>>} \ No newline at end of file diff --git a/rendercv/themes/moderncv/Preamble.j2.tex b/rendercv/themes/moderncv/Preamble.j2.tex new file mode 100644 index 0000000..56366c1 --- /dev/null +++ b/rendercv/themes/moderncv/Preamble.j2.tex @@ -0,0 +1,87 @@ +%% start of file `template.tex'. +%% Copyright 2006-2015 Xavier Danaux (xdanaux@gmail.com), 2020-2022 moderncv maintainers (github.com/moderncv). +% +% This work may be distributed and/or modified under the +% conditions of the LaTeX Project Public License version 1.3c, +% available at http://www.latex-project.org/lppl/. + +\documentclass[<<design.font_size>>,<<design.page_size>>,sans]{moderncv} % possible options include font size ('10pt', '11pt' and '12pt'), paper size ('a4paper', 'letterpaper', 'a5paper', 'legalpaper', 'executivepaper' and 'landscape') and font family ('sans' and 'roman') + +% moderncv themes +\moderncvstyle{classic} % style options are 'casual' (default), 'classic', 'banking', 'oldstyle' and 'fancy' +\moderncvcolor{<<design.color>>} % color options 'black', 'blue' (default), 'burgundy', 'green', 'grey', 'orange', 'purple' and 'red' +%\renewcommand{\familydefault}{\sfdefault} % to set the default font; use '\sfdefault' for the default sans serif font, '\rmdefault' for the default roman one, or any tex font name +((* if design.disable_page_numbers *)) +\nopagenumbers{} +((* endif *)) + +\usepackage{amsmath} % for math + +% adjust the page margins +\usepackage[scale=<<design.content_scale>>]{geometry} +\setlength{\hintscolumnwidth}{<<design.date_width>>} % if you want to change the width of the column with the dates +%\setlength{\makecvheadnamewidth}{10cm} % for the 'classic' style, if you want to force the width allocated to your name and avoid line breaks. be careful though, the length is normally calculated to avoid any overlap with your personal info; use this at your own typographical risks... + +% font loading +% for luatex and xetex, do not use inputenc and fontenc +% see https://tex.stackexchange.com/a/496643 +\ifxetexorluatex + \usepackage{fontspec} + \usepackage{unicode-math} + \defaultfontfeatures{Ligatures=TeX} + \setmainfont{Latin Modern Roman} + \setsansfont{Latin Modern Sans} + \setmonofont{Latin Modern Mono} + \setmathfont{Latin Modern Math} +\else + \usepackage[T1]{fontenc} + \usepackage{lmodern} +\fi + +% document language +\usepackage[english]{babel} % FIXME: using spanish breaks moderncv + +% personal data +\name{<<cv.name>>}{} +((* if cv.label *)) +\title{<<cv.label>>} % optional, remove / comment the line if not wanted +((* endif *)) +% \familyname{} +((* if cv.location *)) +\address{<<cv.location>>}{} +((* endif *)) +((* if cv.phone *)) +\phone[mobile]{<<cv.phone|replace("tel:", "")|replace("-"," ")>>} +((* endif *)) +((* if cv.email *)) +\email{<<cv.email>>} +((* endif *)) +((* if cv.website *)) +\homepage{<<cv.website|replace("https://", "")|reverse|replace("/", "", 1)|reverse>>} +((* endif *)) + +((* set available_social_networks = ["LinkedIn", "GitHub", "Orcid" ]*)) +((* if cv.social_networks *)) + ((* for network in cv.social_networks *)) + ((* if network.network in available_social_networks *)) +\social[<<network.network|lower()>>]{<<network.username>>} + ((* endif *)) + ((* endfor *)) +((* endif *)) +% Social icons +% \social[linkedin]{john.doe} % optional, remove / comment the line if not wanted +% \social[xing]{john\_doe} % optional, remove / comment the line if not wanted +% \social[twitter]{ji\_doe} % optional, remove / comment the line if not wanted +% \social[github]{jdoe} % optional, remove / comment the line if not wanted +% \social[gitlab]{jdoe} % optional, remove / comment the line if not wanted +% \social[stackoverflow]{0000000/johndoe} % optional, remove / comment the line if not wanted +% \social[bitbucket]{jdoe} % optional, remove / comment the line if not wanted +% \social[skype]{jdoe} % optional, remove / comment the line if not wanted +% \social[orcid]{0000-0000-000-000} % optional, remove / comment the line if not wanted +% \social[researchgate]{jdoe} % optional, remove / comment the line if not wanted +% \social[researcherid]{jdoe} % optional, remove / comment the line if not wanted +% \social[telegram]{jdoe} % optional, remove / comment the line if not wanted +% \social[whatsapp]{12345678901} % optional, remove / comment the line if not wanted +% \social[signal]{12345678901} % optional, remove / comment the line if not wanted +% \social[matrix]{@johndoe:matrix.org} % optional, remove / comment the line if not wanted +% \social[googlescholar]{googlescholarid} % optional, remove / comment the line if not wanted diff --git a/rendercv/themes/moderncv/PublicationEntry.j2.tex b/rendercv/themes/moderncv/PublicationEntry.j2.tex new file mode 100644 index 0000000..bd11e56 --- /dev/null +++ b/rendercv/themes/moderncv/PublicationEntry.j2.tex @@ -0,0 +1,2 @@ +\cventry{<<entry.date_string>>}{<<entry.title>>}{<<entry.journal>>}{\href{<<entry.doi_url>>}{<<entry.doi>>}}{}{} +\cvline{}{\small <<entry.authors|map("abbreviate_name")|map("make_it_nolinebreak")|join(", ")|make_it_bold(cv.name|abbreviate_name)|make_it_italic(cv.name|abbreviate_name)>>} \ No newline at end of file diff --git a/rendercv/themes/moderncv/SectionBeginning.j2.tex b/rendercv/themes/moderncv/SectionBeginning.j2.tex new file mode 100644 index 0000000..b72afb4 --- /dev/null +++ b/rendercv/themes/moderncv/SectionBeginning.j2.tex @@ -0,0 +1 @@ +\section{<<section_title>>} \ No newline at end of file diff --git a/rendercv/themes/moderncv/SectionEnding.j2.tex b/rendercv/themes/moderncv/SectionEnding.j2.tex new file mode 100644 index 0000000..e69de29 diff --git a/rendercv/themes/moderncv/TextEntry.j2.tex b/rendercv/themes/moderncv/TextEntry.j2.tex new file mode 100644 index 0000000..bed2213 --- /dev/null +++ b/rendercv/themes/moderncv/TextEntry.j2.tex @@ -0,0 +1 @@ +\cvlistitem{<<entry>>} diff --git a/rendercv/themes/moderncv/__init__.py b/rendercv/themes/moderncv/__init__.py new file mode 100644 index 0000000..f0fa8ec --- /dev/null +++ b/rendercv/themes/moderncv/__init__.py @@ -0,0 +1,80 @@ +from typing import Literal + +import pydantic + +from .. import LaTeXDimension + + +class ModerncvThemeOptions(pydantic.BaseModel): + """This class is the data model of the theme options for the moderncv theme.""" + + model_config = pydantic.ConfigDict(extra="forbid") + + theme: Literal["moderncv"] + font_size: Literal["10pt", "11pt", "12pt"] = pydantic.Field( + default="10pt", + title="Font Size", + description='The font size of the CV. The default value is "10pt".', + examples=["10pt", "11pt", "12pt"], + ) + page_size: Literal["a4paper", "letterpaper"] = pydantic.Field( + default="letterpaper", + title="Page Size", + description='The page size of the CV. The default value is "letterpaper".', + examples=["a4paper", "letterpaper"], + ) + color: ( + Literal["blue"] + | Literal["black"] + | Literal["burgundy"] + | Literal["green"] + | Literal["grey"] + | Literal["orange"] + | Literal["purple"] + | Literal["red"] + ) = pydantic.Field( + default="blue", + validate_default=True, + title="Primary Color", + description='The primary color of the CV. The default value is "blue".', + examples=[ + "blue", + "black", + "burgundy", + "green", + "grey", + "orange", + "purple", + "red", + ], + ) + date_width: LaTeXDimension = pydantic.Field( + default="3.8 cm", + validate_default=True, + title="Date and Location Column Width", + description='The width of the date column. The default value is "3.8 cm".', + ) + content_scale: float = pydantic.Field( + default=0.75, + title="Content Scale", + description=( + "The scale of the content with respect to the page size. The default value" + ' is "0.75".' + ), + ) + show_only_years: bool = pydantic.Field( + default=False, + title="Show Only Years", + description=( + 'If "True", only the years will be shown in the date column. The default' + ' value is "False".' + ), + ) + disable_page_numbers: bool = pydantic.Field( + default=False, + title="Disable Page Numbers", + description=( + 'If "True", the page numbers will be disabled. The default value is' + ' "False".' + ), + ) diff --git a/rendercv/themes/sb2nov/EducationEntry.j2.tex b/rendercv/themes/sb2nov/EducationEntry.j2.tex new file mode 100644 index 0000000..8803537 --- /dev/null +++ b/rendercv/themes/sb2nov/EducationEntry.j2.tex @@ -0,0 +1,12 @@ +\resumeSubheading + {<<entry.institution>>}{<<entry.location>>} + {((* if entry.degree *))<<entry.degree>> in ((* endif *))<<entry.area>>}{<<entry.date_string>>} +((* for item in entry.highlights *)) + ((* if loop.first *)) + \resumeItemListStart + ((* endif *)) + \resumeItem{}{<<item>>} + ((* if loop.last *)) + \resumeItemListEnd + ((* endif *)) +((* endfor *)) \ No newline at end of file diff --git a/rendercv/themes/sb2nov/ExperienceEntry.j2.tex b/rendercv/themes/sb2nov/ExperienceEntry.j2.tex new file mode 100644 index 0000000..269affc --- /dev/null +++ b/rendercv/themes/sb2nov/ExperienceEntry.j2.tex @@ -0,0 +1,12 @@ +\resumeSubheading + {<<entry.company>>}{<<entry.location>>} + {<<entry.position>>}{<<entry.date_string>>} +((* for item in entry.highlights *)) + ((* if loop.first *)) + \resumeItemListStart + ((* endif *)) + \resumeItem{}{<<item>>} + ((* if loop.last *)) + \resumeItemListEnd + ((* endif *)) +((* endfor *)) \ No newline at end of file diff --git a/rendercv/themes/sb2nov/Header.j2.tex b/rendercv/themes/sb2nov/Header.j2.tex new file mode 100644 index 0000000..b28c3bc --- /dev/null +++ b/rendercv/themes/sb2nov/Header.j2.tex @@ -0,0 +1,63 @@ +((* set orcid_url = (cv.social_networks|get_an_item_with_a_specific_attribute_value("network", "Orcid")).url *)) +((* if design.show_last_updated_date *)) +\placelastupdatedtext +((* endif *)) + +((* if cv.name is not none *)) +{ + \centering + \textbf{\fontsize{<<design.header_font_size>>}{<<design.header_font_size>>}\selectfont + ((* if orcid_url *)) + \href{<<orcid_url>>}{<<cv.name>>} + ((* else *)) + <<cv.name>> + ((* endif *)) + } \\ \vspace{3pt} + \small + + \vspace{<<design.margins.header.vertical_between_name_and_connections>>} + + \begin{spacing}{1.6} + ((* if cv.phone *)) + \mbox{\href{<<cv.phone|replace("-","")>>}{{\footnotesize\faPhone*}\hspace{4pt}<<cv.phone|replace("tel:", "")|replace("-"," ")>>}} + \hspace{<<design.margins.header.horizontal_between_connections>>} + ((* endif *)) + ((* if cv.email *)) + \mbox{\href{mailto:<<cv.email>>}{{\small\faEnvelope[regular]}\hspace{4pt}<<cv.email>>}} + \hspace{<<design.margins.header.horizontal_between_connections>>} + ((* endif *)) + ((* if cv.location *)) + \mbox{{\small\faMapMarker*}\hspace{4pt}<<cv.location>>} + \hspace{<<design.margins.header.horizontal_between_connections>>} + ((* endif *)) + ((* if cv.website *)) + \mbox{\href{<<cv.website>>}{{\small\faLink}\hspace{4pt}<<cv.website|replace("https://","")|reverse|replace("/", "", 1)|reverse>>}} + \hspace{<<design.margins.header.horizontal_between_connections>>} + ((* endif *)) + ((* + set icon_dictionary = { + "LinkedIn": "\\faLinkedinIn", + "GitHub": "\\faGithub", + "Instagram": "\\faInstagram", + "Mastodon": "\\faMastodon", + } + *)) + ((* if cv.social_networks *)) + ((* for network in cv.social_networks *)) + ((* if network.network in icon_dictionary *)) + \mbox{\href{<<network.url>>}{{\small<<icon_dictionary[network.network]>>}\hspace{4pt}<<network.username>>}} + \hspace*{<<design.margins.header.horizontal_between_connections>>} + ((* endif *)) + ((* endfor *)) + ((* endif *)) + \end{spacing} + \par +} + +\vspace{<<design.margins.header.bottom>>} +((* endif *)) + +% save the original href command in a new command: +\let\hrefWithoutArrow\href +% new command for external links: +\renewcommand{\href}[2]{\hrefWithoutArrow{#1}{\color{primaryColor}\mbox{\ifthenelse{\equal{#2}{}}{}{#2 }\raisebox{.15ex}{\footnotesize \faExternalLink*}}}} \ No newline at end of file diff --git a/rendercv/themes/sb2nov/LICENSE b/rendercv/themes/sb2nov/LICENSE new file mode 100644 index 0000000..4d4f656 --- /dev/null +++ b/rendercv/themes/sb2nov/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 Sourabh Bajaj + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/rendercv/themes/sb2nov/NormalEntry.j2.tex b/rendercv/themes/sb2nov/NormalEntry.j2.tex new file mode 100644 index 0000000..66d29d7 --- /dev/null +++ b/rendercv/themes/sb2nov/NormalEntry.j2.tex @@ -0,0 +1,11 @@ +\resumeNormalSubheading + {<<entry.name>>}{((* if entry.date_string == "" *))<<entry.location>>((* else *))<<entry.date_string>>((* endif *))} +((* for item in entry.highlights *)) + ((* if loop.first *)) + \resumeItemListStart + ((* endif *)) + \resumeItem{}{<<item>>} + ((* if loop.last *)) + \resumeItemListEnd + ((* endif *)) +((* endfor *)) \ No newline at end of file diff --git a/rendercv/themes/sb2nov/OneLineEntry.j2.tex b/rendercv/themes/sb2nov/OneLineEntry.j2.tex new file mode 100644 index 0000000..e7d4024 --- /dev/null +++ b/rendercv/themes/sb2nov/OneLineEntry.j2.tex @@ -0,0 +1,5 @@ +((* if is_first_entry *)) +\vspace{0.08cm} +((* endif *)) +\resumeSubItem{<<entry.name>>} + {<<entry.details>>} \ No newline at end of file diff --git a/rendercv/themes/sb2nov/Preamble.j2.tex b/rendercv/themes/sb2nov/Preamble.j2.tex new file mode 100644 index 0000000..290b0dd --- /dev/null +++ b/rendercv/themes/sb2nov/Preamble.j2.tex @@ -0,0 +1,132 @@ +%------------------------- +% Resume in Latex +% Author : Sourabh Bajaj +% License : MIT +%------------------------ + +\documentclass[<<design.font_size>>, <<design.page_size>>]{article} + +\usepackage[ + ignoreheadfoot, % set margins without considering header and footer + top=<<design.margins.page.top>>, % seperation between body and page edge from the top + 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 + footskip=<<design.margins.page.bottom|divide_length_by(2)>>, % seperation between body and footer + % showframe % for debugging + ]{geometry} % for adjusting page geometry +\usepackage{latexsym} +\usepackage[nobottomtitles*]{titlesec} +\usepackage{marvosym} +\usepackage{verbatim} +\usepackage{setspace} +\usepackage{xcolor} +\usepackage{enumitem} +\usepackage[ + hidelinks, + pdftitle={<<cv.name>>'s CV}, + pdfauthor={<<cv.name>>} +]{hyperref} +\usepackage{fancyhdr} +\usepackage[english]{babel} +\usepackage{tabularx} +\usepackage{ifthen} +\usepackage{fontawesome5} +\usepackage{calc} % for calculating lengths +\usepackage[pscoord]{eso-pic} % for floating text on the page +\usepackage{lastpage} % for getting the total number of pages +\input{glyphtounicode} + +\pagestyle{fancy} +\fancyhf{} % clear all header and footer fields +((* if not design.disable_page_numbering *)) +((* set page_numbering_style_placeholders = { + "NAME": cv.name, + "PAGE_NUMBER": "\\thepage{}", + "TOTAL_PAGES": "\pageref*{LastPage}" +} *)) +\fancyfoot[CO]{\color{gray}\textit{\small <<design.page_numbering_style|replace_placeholders_with_actual_values(page_numbering_style_placeholders)>>}} +((* endif *)) +\renewcommand{\headrulewidth}{0pt} +\renewcommand{\footrulewidth}{0pt} + +\definecolor{primaryColor}{RGB}{<<design.color.as_rgb_tuple()|join(", ")>>} % define primary color + +\urlstyle{same} + +\setcounter{secnumdepth}{0} % no section numbering +\setlength{\parindent}{0pt} % no indentation +\setlength{\topskip}{0pt} % no top skip + +% \raggedbottom +((* if design.text_alignment == "left-aligned"*)) +\raggedright +((* endif *)) +\setlength{\tabcolsep}{0in} + +% Sections formatting +\titleformat{\section}{ + \scshape\raggedright\large +}{}{0em}{}[\color{black}\titlerule] + +% Ensure that generate pdf is machine readable/ATS parsable +\pdfgentounicode=1 + + +\newcolumntype{R}[1]{ + >{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1} +} % right-aligned fixed width column type + +\titlespacing{\section}{ + % left space: + 0pt + }{ + % top space: + <<design.margins.section_title.top>> - 0.1cm + }{ + % bottom space: + <<design.margins.section_title.bottom>> + } % section title spacing + +%------------------------- +% Custom commands +\newcommand{\placelastupdatedtext}{% \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>} + \AddToShipoutPictureFG*{% Add <stuff> to current page foreground + \put( + \LenToUnit{\paperwidth-<<design.margins.page.right>>-<<design.margins.entry_area.left_and_right>>+0.05cm}, + \LenToUnit{\paperheight-<<design.margins.page.top|divide_length_by(2)>>} + ){\vtop{{\null}\makebox[0pt][c]{ + \small\color{gray}\textit{Last updated in <<today>>}\hspace{\widthof{Last updated in <<today>>}} + }}}% + }% +}% + +\newcommand{\resumeItem}[2]{ + \item\small{ + \ifthenelse{\equal{#1}{}}{#2}{\textbf{#1}{: #2}} + } +} + +\newcommand{\resumeSubheading}[4]{ + \item + \begin{tabularx}{0.98\textwidth-<<design.margins.entry_area.left_and_right|divide_length_by(0.5)>>}[t]{X R{<<design.margins.entry_area.date_and_location_width>>}} + \textbf{#1} & \textit{\small\ifthenelse{\equal{#2}{}}{#4}{#2}} \\ + \textit{\small#3} & \textit{\small\ifthenelse{\equal{#2}{}}{}{#4}} \\ + \end{tabularx} +} + +\newcommand{\resumeNormalSubheading}[2]{ + \item + \begin{tabularx}{0.98\textwidth-<<design.margins.entry_area.left_and_right|divide_length_by(0.5)>>}[t]{X R{<<design.margins.entry_area.date_and_location_width>>}} + \textbf{#1} & \textit{\small #2} + \end{tabularx} +} + +\newcommand{\resumeSubItem}[2]{\resumeItem{#1}{#2}} + +\renewcommand{\labelitemii}{$\circ$} + +\newcommand{\resumeSubHeadingListStart}{\begin{itemize}[left=<<design.margins.entry_area.left_and_right>>, topsep=0pt, parsep=<<design.margins.entry_area.vertical_between>>, partopsep=0pt, rightmargin=<<design.margins.entry_area.left_and_right>>]} +\newcommand{\resumeSubHeadingListEnd}{\end{itemize}} +\newcommand{\resumeItemListStart}{\vspace{<<design.margins.highlights_area.top>>}\begin{itemize}[left=<<design.margins.highlights_area.left>>, topsep=-<<design.margins.entry_area.vertical_between>>, itemsep=<<design.margins.highlights_area.vertical_between_bullet_points>>, partopsep=0pt, rightmargin=0cm]} +\newcommand{\resumeItemListEnd}{\end{itemize}} diff --git a/rendercv/themes/sb2nov/PublicationEntry.j2.tex b/rendercv/themes/sb2nov/PublicationEntry.j2.tex new file mode 100644 index 0000000..4d9088a --- /dev/null +++ b/rendercv/themes/sb2nov/PublicationEntry.j2.tex @@ -0,0 +1,6 @@ +\resumeSubheading + {<<entry.title>>}{<<entry.date_string>>} + {\href{<<entry.doi_url>>}{<<entry.doi>>}}{} + \resumeItemListStart + \resumeItem{}{\raggedright <<entry.authors|map("abbreviate_name")|map("make_it_nolinebreak")|join(", ")|make_it_bold(cv.name|abbreviate_name)|make_it_italic(cv.name|abbreviate_name)>> \par} + \resumeItemListEnd \ No newline at end of file diff --git a/rendercv/themes/sb2nov/SectionBeginning.j2.tex b/rendercv/themes/sb2nov/SectionBeginning.j2.tex new file mode 100644 index 0000000..cde297d --- /dev/null +++ b/rendercv/themes/sb2nov/SectionBeginning.j2.tex @@ -0,0 +1,2 @@ +\section{<<section_title>>} + \resumeSubHeadingListStart \ No newline at end of file diff --git a/rendercv/themes/sb2nov/SectionEnding.j2.tex b/rendercv/themes/sb2nov/SectionEnding.j2.tex new file mode 100644 index 0000000..5247af9 --- /dev/null +++ b/rendercv/themes/sb2nov/SectionEnding.j2.tex @@ -0,0 +1 @@ +\resumeSubHeadingListEnd \ No newline at end of file diff --git a/rendercv/themes/sb2nov/TextEntry.j2.tex b/rendercv/themes/sb2nov/TextEntry.j2.tex new file mode 100644 index 0000000..79b58fa --- /dev/null +++ b/rendercv/themes/sb2nov/TextEntry.j2.tex @@ -0,0 +1 @@ +\resumeSubItem{}{<<entry>>} \ No newline at end of file diff --git a/rendercv/themes/sb2nov/__init__.py b/rendercv/themes/sb2nov/__init__.py new file mode 100644 index 0000000..ae2f77d --- /dev/null +++ b/rendercv/themes/sb2nov/__init__.py @@ -0,0 +1,21 @@ +from typing import Literal + +import pydantic + +from .. import ThemeOptions, LaTeXDimension + + +class Sb2novThemeOptions(ThemeOptions): + """This class is the data model of the theme options for the sb2nov theme.""" + + theme: Literal["sb2nov"] + + header_font_size: LaTeXDimension = pydantic.Field( + default="24 pt", + title="Header Font Size", + description=( + "The font size of the header (the name of the person). The default value is" + " 24 pt. Unfortunately, sb2nov does not support font sizes bigger than" + " 24 pt." + ), + ) diff --git a/rendercv/tinytex-release b/rendercv/tinytex-release new file mode 160000 index 0000000..e304917 --- /dev/null +++ b/rendercv/tinytex-release @@ -0,0 +1 @@ +Subproject commit e3049178912f6ee8119afe9a6c3a4e651036f84b diff --git a/rendercv/vendor/README.md b/rendercv/vendor/README.md deleted file mode 100644 index 6efac33..0000000 --- a/rendercv/vendor/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# TinyTeX - -This directory contains `TinyTeX` folder with all the TinyTeX binaries. This is done to make RenderCV usable without installing LaTeX. For RenderCV, I deleted most of the files to get a minimal TinyTeX that can render the CV and save space. diff --git a/run_rendercv.py b/run_rendercv.py deleted file mode 100644 index ec7ce23..0000000 --- a/run_rendercv.py +++ /dev/null @@ -1,14 +0,0 @@ -from rendercv.__main__ import render -from rendercv.data_model import generate_json_schema -import os - -input_file_path = "John_Doe_CV.yaml" -render(input_file_path) # type: ignore - -# This script is equivalent to running the following command in the terminal: -# python -m rendercv personal.yaml -# or -# rendercv personal.yaml - -# Generate schema.json -generate_json_schema(os.path.dirname(__file__)) diff --git a/schema.json b/schema.json index 02a9305..05ce0b9 100644 --- a/schema.json +++ b/schema.json @@ -1,155 +1,33 @@ { "$defs": { - "ClassicThemeEntryAreaMargins": { - "properties": { - "left_and_right": { - "default": "0.2 cm", - "description": "The left margin of entry areas.", - "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", - "title": "Left Margin", - "type": "string" - }, - "vertical_between": { - "default": "0.12 cm", - "description": "The vertical margin between entry areas.", - "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", - "title": "Vertical Margin Between Entry Areas", - "type": "string" - } - }, - "title": "ClassicThemeEntryAreaMargins", - "type": "object", - "additionalProperties": false - }, - "ClassicThemeHeaderMargins": { - "properties": { - "vertical_between_name_and_connections": { - "default": "0.2 cm", - "description": "The vertical margin between the name of the person and the connections.", - "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", - "title": "Vertical Margin Between the Name and Connections", - "type": "string" - }, - "bottom": { - "default": "0.2 cm", - "description": "The bottom margin of the header, i.e., the vertical margin between the connections and the first section title.", - "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", - "title": "Bottom Margin", - "type": "string" - } - }, - "title": "ClassicThemeHeaderMargins", - "type": "object", - "additionalProperties": false - }, - "ClassicThemeHighlightsAreaMargins": { - "properties": { - "top": { - "default": "0.10 cm", - "description": "The top margin of highlights areas.", - "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", - "title": "Top Margin", - "type": "string" - }, - "left": { - "default": "0.4 cm", - "description": "The left margin of highlights areas.", - "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", - "title": "Left Margin", - "type": "string" - }, - "vertical_between_bullet_points": { - "default": "0.10 cm", - "description": "The vertical margin between bullet points.", - "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", - "title": "Vertical Margin Between Bullet Points", - "type": "string" - } - }, - "title": "ClassicThemeHighlightsAreaMargins", - "type": "object", - "additionalProperties": false - }, - "ClassicThemeMargins": { - "properties": { - "page": { - "allOf": [ - { - "$ref": "#/$defs/ClassicThemePageMargins" - } - ], - "default": { - "bottom": "2 cm", - "left": "1.24 cm", - "right": "1.24 cm", - "top": "2 cm" - }, - "description": "Page margins for the classic theme.", - "title": "Page Margins" - }, - "section_title": { - "allOf": [ - { - "$ref": "#/$defs/ClassicThemeSectionTitleMargins" - } - ], - "default": { - "bottom": "0.2 cm", - "top": "0.2 cm" - }, - "description": "Section title margins for the classic theme.", - "title": "Section Title Margins" - }, - "entry_area": { - "allOf": [ - { - "$ref": "#/$defs/ClassicThemeEntryAreaMargins" - } - ], - "default": { - "left_and_right": "0.2 cm", - "vertical_between": "0.12 cm" - }, - "description": "Entry area margins for the classic theme.", - "title": "Entry Area Margins" - }, - "highlights_area": { - "allOf": [ - { - "$ref": "#/$defs/ClassicThemeHighlightsAreaMargins" - } - ], - "default": { - "left": "0.4 cm", - "top": "0.10 cm", - "vertical_between_bullet_points": "0.10 cm" - }, - "description": "Highlights area margins for the classic theme.", - "title": "Highlights Area Margins" - }, - "header": { - "allOf": [ - { - "$ref": "#/$defs/ClassicThemeHeaderMargins" - } - ], - "default": { - "bottom": "0.2 cm", - "vertical_between_name_and_connections": "0.2 cm" - }, - "description": "Header margins for the classic theme.", - "title": "Header Margins" - } - }, - "title": "ClassicThemeMargins", - "type": "object", - "additionalProperties": false - }, "ClassicThemeOptions": { + "additionalProperties": false, + "description": "This class is the data model of the theme options for the classic theme.", "properties": { - "primary_color": { + "font_size": { + "default": "10pt", + "description": "The font size of the CV. The default value is 10pt.", + "enum": [ + "10pt", + "11pt", + "12pt" + ], + "title": "Font Size", + "type": "string" + }, + "page_size": { + "default": "letterpaper", + "description": "The page size of the CV. It can be a4paper or letterpaper. The default value is letterpaper.", + "enum": [ + "a4paper", + "letterpaper" + ], + "title": "Page Size", + "type": "string" + }, + "color": { "default": "rgb(0,79,144)", - "description": "The primary color of Classic Theme. It is used for the section titles, heading, and the links.\nThe color can be specified either with their [name](https://www.w3.org/TR/SVG11/types.html#ColorKeywords), hexadecimal value, RGB value, or HSL value.", + "description": "The primary color of the theme. \nThe color can be specified either with their [name](https://www.w3.org/TR/SVG11/types.html#ColorKeywords), hexadecimal value, RGB value, or HSL value. The default value is rgb(0,79,144).", "examples": [ "Black", "7fffd4", @@ -160,16 +38,34 @@ "title": "Primary Color", "type": "string" }, - "date_and_location_width": { - "default": "4.1 cm", - "description": "The width of the date and location column.", + "disable_page_numbering": { + "default": false, + "description": "If this option is set to true, then the page numbering will be disabled. The default value is false.", + "title": "Disable Page Numbering", + "type": "boolean" + }, + "page_numbering_style": { + "default": "NAME - Page PAGE_NUMBER of TOTAL_PAGES", + "description": "The style of the page numbering. The following placeholders can be used:\n- NAME: The name of the person\n- PAGE_NUMBER: The current page number\n- TOTAL_PAGES: The total number of pages\nThe default value is NAME - Page PAGE_NUMBER of TOTAL_PAGES.", + "title": "Page Numbering Style", + "type": "string" + }, + "show_last_updated_date": { + "default": true, + "description": "If this option is set to true, then the last updated date will be shown in the header. The default value is true.", + "title": "Show Last Updated Date", + "type": "boolean" + }, + "header_font_size": { + "default": "30 pt", + "description": "The font size of the header (the name of the person). The default value is 30 pt.", "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", - "title": "Date and Location Column Width", + "title": "Header Font Size", "type": "string" }, "text_alignment": { - "default": "left-aligned", - "description": "The alignment of the text.", + "default": "justified", + "description": "The alignment of the text. The default value is justified.", "enum": [ "left-aligned", "justified" @@ -177,129 +73,75 @@ "title": "Text Alignment", "type": "string" }, - "show_timespan_in": { - "default": [], - "description": "The time span will be shown in the date and location column in these sections. The input should be a list of strings.", - "items": { - "type": "string" - }, - "title": "Show Time Span in These Sections", - "type": "array" - }, - "show_last_updated_date": { - "default": true, - "description": "If this option is set to true, then the last updated date will be shown in the header.", - "title": "Show Last Updated Date", - "type": "boolean" - }, - "header_font_size": { - "default": "30 pt", - "description": "The font size of the header (the name of the person).", - "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", - "title": "Header Font Size", - "type": "string" - }, "margins": { "allOf": [ { - "$ref": "#/$defs/ClassicThemeMargins" + "$ref": "#/$defs/Margins" } ], "default": { - "entry_area": { - "left_and_right": "0.2 cm", - "vertical_between": "0.12 cm" + "page": { + "bottom": "2 cm", + "left": "2 cm", + "right": "2 cm", + "top": "2 cm" }, - "header": { + "section_title": { "bottom": "0.2 cm", - "vertical_between_name_and_connections": "0.2 cm" + "top": "0.3 cm" + }, + "entry_area": { + "date_and_location_width": "4.1 cm", + "left_and_right": "0.2 cm", + "vertical_between": "0.2 cm" }, "highlights_area": { "left": "0.4 cm", "top": "0.10 cm", "vertical_between_bullet_points": "0.10 cm" }, - "page": { - "bottom": "2 cm", - "left": "1.24 cm", - "right": "1.24 cm", - "top": "2 cm" - }, - "section_title": { - "bottom": "0.2 cm", - "top": "0.2 cm" + "header": { + "bottom": "0.3 cm", + "horizontal_between_connections": "0.5 cm", + "vertical_between_name_and_connections": "0.3 cm" } }, "description": "Page, section title, entry field, and highlights field margins.", "title": "Margins" + }, + "theme": { + "const": "classic", + "title": "Theme" + }, + "show_timespan_in": { + "default": [], + "description": "The time span will be shown in the date and location column in these sections. The input should be a list of section titles as strings (case-sensitive). The default value is an empty list, which means the time span will not be shown in any section.", + "items": { + "type": "string" + }, + "title": "Show Time Span in These Sections", + "type": "array" } }, + "required": [ + "theme" + ], "title": "ClassicThemeOptions", - "type": "object", - "additionalProperties": false - }, - "ClassicThemePageMargins": { - "properties": { - "top": { - "default": "2 cm", - "description": "The top margin of the page with units.", - "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", - "title": "Top Margin", - "type": "string" - }, - "bottom": { - "default": "2 cm", - "description": "The bottom margin of the page with units.", - "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", - "title": "Bottom Margin", - "type": "string" - }, - "left": { - "default": "1.24 cm", - "description": "The left margin of the page with units.", - "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", - "title": "Left Margin", - "type": "string" - }, - "right": { - "default": "1.24 cm", - "description": "The right margin of the page with units.", - "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", - "title": "Right Margin", - "type": "string" - } - }, - "title": "ClassicThemePageMargins", - "type": "object", - "additionalProperties": false - }, - "ClassicThemeSectionTitleMargins": { - "properties": { - "top": { - "default": "0.2 cm", - "description": "The top margin of section titles.", - "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", - "title": "Top Margin", - "type": "string" - }, - "bottom": { - "default": "0.2 cm", - "description": "The bottom margin of section titles.", - "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", - "title": "Bottom Margin", - "type": "string" - } - }, - "title": "ClassicThemeSectionTitleMargins", - "type": "object", - "additionalProperties": false + "type": "object" }, "CurriculumVitae": { + "additionalProperties": false, + "description": "This class is the data model of the CV.", "properties": { "name": { + "default": null, "description": "The name of the person.", "title": "Name", - "type": "string" + "allOf": [ + { + "type": "string" + } + ] }, "label": { "default": null, @@ -323,7 +165,7 @@ }, "email": { "default": null, - "description": "The email of the person. It will be rendered in the heading.", + "description": "The email of the person.", "title": "Email", "allOf": [ { @@ -334,9 +176,11 @@ }, "phone": { "default": null, + "description": "The phone number of the person.", "title": "Phone", "allOf": [ { + "format": "phone", "maxLength": 64, "minLength": 7, "type": "string" @@ -345,6 +189,7 @@ }, "website": { "default": null, + "description": "The website of the person.", "title": "Website", "allOf": [ { @@ -357,7 +202,7 @@ }, "social_networks": { "default": null, - "description": "The social networks of the person. They will be rendered in the heading.", + "description": "The social networks of the person.", "title": "Social Networks", "allOf": [ { @@ -368,396 +213,116 @@ } ] }, - "summary": { + "sections": { "default": null, - "description": "The summary of the person.", - "title": "Summary", + "description": "The sections of the CV.", + "title": "Sections", "allOf": [ { - "type": "string" - } - ] - }, - "section_order": { - "default": null, - "description": "The order of sections in the CV. The section title should be used.", - "title": "Section Order", - "allOf": [ - { - "items": { - "type": "string" - }, - "type": "array" - } - ] - }, - "education": { - "default": null, - "description": "The education entries of the person.", - "title": "Education", - "allOf": [ - { - "items": { - "$ref": "#/$defs/EducationEntry" - }, - "type": "array" - } - ] - }, - "experience": { - "default": null, - "description": "The experience entries of the person.", - "title": "Experience", - "allOf": [ - { - "items": { - "$ref": "#/$defs/ExperienceEntry" - }, - "type": "array" - } - ] - }, - "work_experience": { - "default": null, - "description": "The work experience entries of the person.", - "title": "Work Experience", - "allOf": [ - { - "items": { - "$ref": "#/$defs/ExperienceEntry" - }, - "type": "array" - } - ] - }, - "projects": { - "default": null, - "description": "The project entries of the person.", - "title": "Projects", - "allOf": [ - { - "items": { - "$ref": "#/$defs/NormalEntry" - }, - "type": "array" - } - ] - }, - "academic_projects": { - "default": null, - "description": "The academic project entries of the person.", - "title": "Academic Projects", - "allOf": [ - { - "items": { - "$ref": "#/$defs/NormalEntry" - }, - "type": "array" - } - ] - }, - "university_projects": { - "default": null, - "description": "The university project entries of the person.", - "title": "University Projects", - "allOf": [ - { - "items": { - "$ref": "#/$defs/NormalEntry" - }, - "type": "array" - } - ] - }, - "personal_projects": { - "default": null, - "description": "The personal project entries of the person.", - "title": "Personal Projects", - "allOf": [ - { - "items": { - "$ref": "#/$defs/NormalEntry" - }, - "type": "array" - } - ] - }, - "publications": { - "default": null, - "description": "The publication entries of the person.", - "title": "Publications", - "allOf": [ - { - "items": { - "$ref": "#/$defs/PublicationEntry" - }, - "type": "array" - } - ] - }, - "certificates": { - "default": null, - "description": "The certificate entries of the person.", - "title": "Certificates", - "allOf": [ - { - "items": { - "$ref": "#/$defs/NormalEntry" - }, - "type": "array" - } - ] - }, - "extracurricular_activities": { - "default": null, - "description": "The extracurricular activity entries of the person.", - "title": "Extracurricular Activities", - "allOf": [ - { - "items": { - "$ref": "#/$defs/ExperienceEntry" - }, - "type": "array" - } - ] - }, - "test_scores": { - "default": null, - "description": "The test score entries of the person.", - "title": "Test Scores", - "allOf": [ - { - "items": { - "$ref": "#/$defs/OneLineEntry" - }, - "type": "array" - } - ] - }, - "programming_skills": { - "default": null, - "description": "The programming skill entries of the person.", - "title": "Programming Skills", - "allOf": [ - { - "items": { - "$ref": "#/$defs/NormalEntry" - }, - "type": "array" - } - ] - }, - "skills": { - "default": null, - "description": "The skill entries of the person.", - "title": "Skills", - "allOf": [ - { - "items": { - "$ref": "#/$defs/OneLineEntry" - }, - "type": "array" - } - ] - }, - "other_skills": { - "default": null, - "description": "The skill entries of the person.", - "title": "Skills", - "allOf": [ - { - "items": { - "$ref": "#/$defs/OneLineEntry" - }, - "type": "array" - } - ] - }, - "awards": { - "default": null, - "description": "The award entries of the person.", - "title": "Awards", - "allOf": [ - { - "items": { - "$ref": "#/$defs/OneLineEntry" - }, - "type": "array" - } - ] - }, - "interests": { - "default": null, - "description": "The interest entries of the person.", - "title": "Interests", - "allOf": [ - { - "items": { - "$ref": "#/$defs/OneLineEntry" - }, - "type": "array" - } - ] - }, - "custom_sections": { - "default": null, - "description": "Custom sections with custom section titles can be rendered as well.", - "title": "Custom Sections", - "allOf": [ - { - "items": { - "discriminator": { - "mapping": { - "EducationEntry": "#/$defs/SectionWithEducationEntries", - "ExperienceEntry": "#/$defs/SectionWithExperienceEntries", - "NormalEntry": "#/$defs/SectionWithNormalEntries", - "OneLineEntry": "#/$defs/SectionWithOneLineEntries", - "PublicationEntry": "#/$defs/SectionWithPublicationEntries" - }, - "propertyName": "entry_type" + "additionalProperties": { + "items": { + "anyOf": [ + { + "$ref": "#/$defs/EducationEntry" + }, + { + "$ref": "#/$defs/ExperienceEntry" + }, + { + "$ref": "#/$defs/PublicationEntry" + }, + { + "$ref": "#/$defs/NormalEntry" + }, + { + "$ref": "#/$defs/OneLineEntry" + }, + { + "type": "string" + } + ] }, - "oneOf": [ - { - "$ref": "#/$defs/SectionWithEducationEntries" - }, - { - "$ref": "#/$defs/SectionWithExperienceEntries" - }, - { - "$ref": "#/$defs/SectionWithNormalEntries" - }, - { - "$ref": "#/$defs/SectionWithOneLineEntries" - }, - { - "$ref": "#/$defs/SectionWithPublicationEntries" - } - ] + "type": "array" }, - "type": "array" + "type": "object" } ] } }, - "required": [ - "name" - ], "title": "CurriculumVitae", - "type": "object", - "additionalProperties": false - }, - "Design": { - "properties": { - "theme": { - "const": "classic", - "default": "classic", - "description": "The only option is \"Classic\" for now.", - "title": "Theme name" - }, - "font": { - "default": "SourceSans3", - "description": "The font of the CV.", - "enum": [ - "SourceSans3", - "Roboto", - "EBGaramond" - ], - "title": "Font", - "type": "string" - }, - "font_size": { - "default": "10pt", - "description": "The font size of the CV. It can be 10pt, 11pt, or 12pt.", - "enum": [ - "10pt", - "11pt", - "12pt" - ], - "title": "Font Size", - "type": "string" - }, - "page_size": { - "default": "a4paper", - "description": "The page size of the CV. It can be a4paper or letterpaper.", - "enum": [ - "a4paper", - "letterpaper" - ], - "title": "Page Size", - "type": "string" - }, - "options": { - "default": null, - "description": "The options of the theme.", - "title": "Theme Options", - "allOf": [ - { - "$ref": "#/$defs/ClassicThemeOptions" - } - ] - } - }, - "title": "Design", - "type": "object", - "additionalProperties": false + "type": "object" }, "EducationEntry": { + "additionalProperties": false, + "description": "This class is the data model of `EducationEntry`.", "properties": { "start_date": { - "default": null, - "description": "The start date of the event in YYYY-MM-DD format.", + "default": "2000-01-01", + "description": "The start date of the event in YYYY-MM-DD, YYYY-MM, or YYYY format.", "examples": [ "2020-09-24" ], "title": "Start Date", - "allOf": [ + "oneOf": [ { - "pattern": "\\d{4}-?(\\d{2})?-?(\\d{2})?", + "type": "integer" + }, + { + "pattern": "\\d{4}(-\\d{2})?(-\\d{2})?", "type": "string" + }, + { + "type": "null" } ] }, "end_date": { + "default": "2020-01-01", + "description": "The end date of the event in YYYY-MM-DD, YYYY-MM, or YYYY format. If the event is still ongoing, then type \"present\" or provide only the start date.", + "examples": [ + "2020-09-24", + "present" + ], + "title": "End Date", "oneOf": [ { "const": "present" }, { - "pattern": "\\d{4}-?(\\d{2})?-?(\\d{2})?", + "type": "integer" + }, + { + "pattern": "\\d{4}(-\\d{2})?(-\\d{2})?", "type": "string" }, { "type": "null" } - ], - "default": null, - "description": "The end date of the event in YYYY-MM-DD format. If the event is still ongoing, then the value should be \"present\".", - "examples": [ - "2020-09-24", - "present" - ], - "title": "End Date" + ] }, "date": { - "oneOf": [ - { - "type": "string" - }, - { - "type": "null" - } - ], - "default": null, + "default": "Custom Date or 2020-01-01", "description": "If the event is a one-day event, then this field should be filled in YYYY-MM-DD format. If the event is a multi-day event, then the start date and end date should be provided instead. All of them can't be provided at the same time.", "examples": [ "2020-09-24", "My Custom Date" ], - "title": "Date" + "title": "Date", + "oneOf": [ + { + "type": "integer" + }, + { + "type": "string" + }, + { + "type": "null" + } + ] }, "highlights": { - "default": [], - "description": "The highlights of the event. It will be rendered as bullet points.", + "default": null, + "description": "The highlights of the event as a list of strings.", "examples": [ "Did this.", "Did that." @@ -774,9 +339,9 @@ }, "location": { "default": null, - "description": "The location of the event. It will be shown with the date in the same column.", + "description": "The location of the event.", "examples": [ - "Istanbul, Turkey" + "Istanbul, T\u00fcrkiye" ], "title": "Location", "allOf": [ @@ -785,23 +350,8 @@ } ] }, - "url": { - "default": null, - "title": "Url", - "allOf": [ - { - "format": "uri", - "maxLength": 2083, - "minLength": 1, - "type": "string" - } - ] - }, "institution": { "description": "The institution name. It will be shown as bold text.", - "examples": [ - "Bogazici University" - ], "title": "Institution", "type": "string" }, @@ -810,8 +360,8 @@ "title": "Area", "type": "string" }, - "study_type": { - "default": null, + "degree": { + "default": "PhD", "description": "The type of the degree.", "examples": [ "BS", @@ -819,44 +369,12 @@ "PhD", "MS" ], - "title": "Study Type", + "title": "Degree", "allOf": [ { "type": "string" } ] - }, - "gpa": { - "oneOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "null" - } - ], - "default": null, - "description": "The GPA of the degree.", - "title": "GPA" - }, - "transcript_url": { - "default": null, - "description": "The URL of the transcript. It will be shown as a link next to the GPA.", - "examples": [ - "https://example.com/transcript.pdf" - ], - "title": "Transcript URL", - "allOf": [ - { - "format": "uri", - "maxLength": 2083, - "minLength": 1, - "type": "string" - } - ] } }, "required": [ @@ -864,66 +382,108 @@ "area" ], "title": "EducationEntry", + "type": "object" + }, + "EntryAreaMargins": { + "description": "This class is a data model for the entry area margins.", + "properties": { + "left_and_right": { + "default": "0.2 cm", + "description": "The left margin of entry areas. The default value is 0.2 cm.", + "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", + "title": "Left Margin", + "type": "string" + }, + "vertical_between": { + "default": "0.2 cm", + "description": "The vertical margin between entry areas. The default value is 0.2 cm.", + "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", + "title": "Vertical Margin Between Entry Areas", + "type": "string" + }, + "date_and_location_width": { + "default": "4.1 cm", + "description": "The width of the date and location column. The default value is 4.1 cm.", + "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", + "title": "Date and Location Column Width", + "type": "string" + } + }, + "title": "EntryAreaMargins", "type": "object", "additionalProperties": false }, "ExperienceEntry": { + "additionalProperties": false, + "description": "This class is the data model of `ExperienceEntry`.", "properties": { "start_date": { - "default": null, - "description": "The start date of the event in YYYY-MM-DD format.", + "default": "2000-01-01", + "description": "The start date of the event in YYYY-MM-DD, YYYY-MM, or YYYY format.", "examples": [ "2020-09-24" ], "title": "Start Date", - "allOf": [ + "oneOf": [ { - "pattern": "\\d{4}-?(\\d{2})?-?(\\d{2})?", + "type": "integer" + }, + { + "pattern": "\\d{4}(-\\d{2})?(-\\d{2})?", "type": "string" + }, + { + "type": "null" } ] }, "end_date": { + "default": "2020-01-01", + "description": "The end date of the event in YYYY-MM-DD, YYYY-MM, or YYYY format. If the event is still ongoing, then type \"present\" or provide only the start date.", + "examples": [ + "2020-09-24", + "present" + ], + "title": "End Date", "oneOf": [ { "const": "present" }, { - "pattern": "\\d{4}-?(\\d{2})?-?(\\d{2})?", + "type": "integer" + }, + { + "pattern": "\\d{4}(-\\d{2})?(-\\d{2})?", "type": "string" }, { "type": "null" } - ], - "default": null, - "description": "The end date of the event in YYYY-MM-DD format. If the event is still ongoing, then the value should be \"present\".", - "examples": [ - "2020-09-24", - "present" - ], - "title": "End Date" + ] }, "date": { - "oneOf": [ - { - "type": "string" - }, - { - "type": "null" - } - ], - "default": null, + "default": "Custom Date or 2020-01-01", "description": "If the event is a one-day event, then this field should be filled in YYYY-MM-DD format. If the event is a multi-day event, then the start date and end date should be provided instead. All of them can't be provided at the same time.", "examples": [ "2020-09-24", "My Custom Date" ], - "title": "Date" + "title": "Date", + "oneOf": [ + { + "type": "integer" + }, + { + "type": "string" + }, + { + "type": "null" + } + ] }, "highlights": { - "default": [], - "description": "The highlights of the event. It will be rendered as bullet points.", + "default": null, + "description": "The highlights of the event as a list of strings.", "examples": [ "Did this.", "Did that." @@ -940,9 +500,9 @@ }, "location": { "default": null, - "description": "The location of the event. It will be shown with the date in the same column.", + "description": "The location of the event.", "examples": [ - "Istanbul, Turkey" + "Istanbul, T\u00fcrkiye" ], "title": "Location", "allOf": [ @@ -951,18 +511,6 @@ } ] }, - "url": { - "default": null, - "title": "Url", - "allOf": [ - { - "format": "uri", - "maxLength": 2083, - "minLength": 1, - "type": "string" - } - ] - }, "company": { "description": "The company name. It will be shown as bold text.", "title": "Company", @@ -979,66 +527,326 @@ "position" ], "title": "ExperienceEntry", + "type": "object" + }, + "HeaderMargins": { + "description": "This class is a data model for the header margins.", + "properties": { + "vertical_between_name_and_connections": { + "default": "0.3 cm", + "description": "The vertical margin between the name of the person and the connections. The default value is 0.3 cm.", + "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", + "title": "Vertical Margin Between the Name and Connections", + "type": "string" + }, + "bottom": { + "default": "0.3 cm", + "description": "The bottom margin of the header, i.e., the vertical margin between the connections and the first section title. The default value is 0.3 cm.", + "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", + "title": "Bottom Margin", + "type": "string" + }, + "horizontal_between_connections": { + "default": "0.5 cm", + "description": "The space between the connections (like phone, email, and website). The default value is 0.5 cm.", + "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", + "title": "Space Between Connections", + "type": "string" + } + }, + "title": "HeaderMargins", "type": "object", "additionalProperties": false }, + "HighlightsAreaMargins": { + "description": "This class is a data model for the highlights area margins.", + "properties": { + "top": { + "default": "0.10 cm", + "description": "The top margin of highlights areas. The default value is 0.10 cm.", + "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", + "title": "Top Margin", + "type": "string" + }, + "left": { + "default": "0.4 cm", + "description": "The left margin of highlights areas. The default value is 0.4 cm.", + "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", + "title": "Left Margin", + "type": "string" + }, + "vertical_between_bullet_points": { + "default": "0.10 cm", + "description": "The vertical margin between bullet points. The default value is 0.10 cm.", + "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", + "title": "Vertical Margin Between Bullet Points", + "type": "string" + } + }, + "title": "HighlightsAreaMargins", + "type": "object", + "additionalProperties": false + }, + "Margins": { + "description": "This class is a data model for the margins.", + "properties": { + "page": { + "allOf": [ + { + "$ref": "#/$defs/PageMargins" + } + ], + "default": { + "top": "2 cm", + "bottom": "2 cm", + "left": "2 cm", + "right": "2 cm" + }, + "description": "Page margins.", + "title": "Page Margins" + }, + "section_title": { + "allOf": [ + { + "$ref": "#/$defs/SectionTitleMargins" + } + ], + "default": { + "top": "0.3 cm", + "bottom": "0.2 cm" + }, + "description": "Section title margins.", + "title": "Section Title Margins" + }, + "entry_area": { + "allOf": [ + { + "$ref": "#/$defs/EntryAreaMargins" + } + ], + "default": { + "left_and_right": "0.2 cm", + "vertical_between": "0.2 cm", + "date_and_location_width": "4.1 cm" + }, + "description": "Entry area margins.", + "title": "Entry Area Margins" + }, + "highlights_area": { + "allOf": [ + { + "$ref": "#/$defs/HighlightsAreaMargins" + } + ], + "default": { + "top": "0.10 cm", + "left": "0.4 cm", + "vertical_between_bullet_points": "0.10 cm" + }, + "description": "Highlights area margins.", + "title": "Highlights Area Margins" + }, + "header": { + "allOf": [ + { + "$ref": "#/$defs/HeaderMargins" + } + ], + "default": { + "vertical_between_name_and_connections": "0.3 cm", + "bottom": "0.3 cm", + "horizontal_between_connections": "0.5 cm" + }, + "description": "Header margins.", + "title": "Header Margins" + } + }, + "title": "Margins", + "type": "object", + "additionalProperties": false + }, + "ModerncvThemeOptions": { + "additionalProperties": false, + "description": "This class is the data model of the theme options for the moderncv theme.", + "properties": { + "theme": { + "const": "moderncv", + "title": "Theme" + }, + "font_size": { + "default": "10pt", + "description": "The font size of the CV. The default value is \"10pt\".", + "enum": [ + "10pt", + "11pt", + "12pt" + ], + "examples": [ + "10pt", + "11pt", + "12pt" + ], + "title": "Font Size", + "type": "string" + }, + "page_size": { + "default": "letterpaper", + "description": "The page size of the CV. The default value is \"letterpaper\".", + "enum": [ + "a4paper", + "letterpaper" + ], + "examples": [ + "a4paper", + "letterpaper" + ], + "title": "Page Size", + "type": "string" + }, + "color": { + "default": "blue", + "description": "The primary color of the CV. The default value is \"blue\".", + "examples": [ + "blue", + "black", + "burgundy", + "green", + "grey", + "orange", + "purple", + "red" + ], + "title": "Primary Color", + "oneOf": [ + { + "const": "blue" + }, + { + "const": "black" + }, + { + "const": "burgundy" + }, + { + "const": "green" + }, + { + "const": "grey" + }, + { + "const": "orange" + }, + { + "const": "purple" + }, + { + "const": "red" + } + ] + }, + "date_width": { + "default": "3.8 cm", + "description": "The width of the date column. The default value is \"3.8 cm\".", + "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", + "title": "Date and Location Column Width", + "type": "string" + }, + "content_scale": { + "default": 0.75, + "description": "The scale of the content with respect to the page size. The default value is \"0.75\".", + "title": "Content Scale", + "type": "number" + }, + "show_only_years": { + "default": false, + "description": "If \"True\", only the years will be shown in the date column. The default value is \"False\".", + "title": "Show Only Years", + "type": "boolean" + }, + "disable_page_numbers": { + "default": false, + "description": "If \"True\", the page numbers will be disabled. The default value is \"False\".", + "title": "Disable Page Numbers", + "type": "boolean" + } + }, + "required": [ + "theme" + ], + "title": "ModerncvThemeOptions", + "type": "object" + }, "NormalEntry": { + "additionalProperties": false, + "description": "This class is the data model of `NormalEntry`.", "properties": { "start_date": { - "default": null, - "description": "The start date of the event in YYYY-MM-DD format.", + "default": "2000-01-01", + "description": "The start date of the event in YYYY-MM-DD, YYYY-MM, or YYYY format.", "examples": [ "2020-09-24" ], "title": "Start Date", - "allOf": [ + "oneOf": [ { - "pattern": "\\d{4}-?(\\d{2})?-?(\\d{2})?", + "type": "integer" + }, + { + "pattern": "\\d{4}(-\\d{2})?(-\\d{2})?", "type": "string" + }, + { + "type": "null" } ] }, "end_date": { + "default": "2020-01-01", + "description": "The end date of the event in YYYY-MM-DD, YYYY-MM, or YYYY format. If the event is still ongoing, then type \"present\" or provide only the start date.", + "examples": [ + "2020-09-24", + "present" + ], + "title": "End Date", "oneOf": [ { "const": "present" }, { - "pattern": "\\d{4}-?(\\d{2})?-?(\\d{2})?", + "type": "integer" + }, + { + "pattern": "\\d{4}(-\\d{2})?(-\\d{2})?", "type": "string" }, { "type": "null" } - ], - "default": null, - "description": "The end date of the event in YYYY-MM-DD format. If the event is still ongoing, then the value should be \"present\".", - "examples": [ - "2020-09-24", - "present" - ], - "title": "End Date" + ] }, "date": { - "oneOf": [ - { - "type": "string" - }, - { - "type": "null" - } - ], - "default": null, + "default": "Custom Date or 2020-01-01", "description": "If the event is a one-day event, then this field should be filled in YYYY-MM-DD format. If the event is a multi-day event, then the start date and end date should be provided instead. All of them can't be provided at the same time.", "examples": [ "2020-09-24", "My Custom Date" ], - "title": "Date" + "title": "Date", + "oneOf": [ + { + "type": "integer" + }, + { + "type": "string" + }, + { + "type": "null" + } + ] }, "highlights": { - "default": [], - "description": "The highlights of the event. It will be rendered as bullet points.", + "default": null, + "description": "The highlights of the event as a list of strings.", "examples": [ "Did this.", "Did that." @@ -1055,9 +863,9 @@ }, "location": { "default": null, - "description": "The location of the event. It will be shown with the date in the same column.", + "description": "The location of the event.", "examples": [ - "Istanbul, Turkey" + "Istanbul, T\u00fcrkiye" ], "title": "Location", "allOf": [ @@ -1066,18 +874,6 @@ } ] }, - "url": { - "default": null, - "title": "Url", - "allOf": [ - { - "format": "uri", - "maxLength": 2083, - "minLength": 1, - "type": "string" - } - ] - }, "name": { "description": "The name of the entry. It will be shown as bold text.", "title": "Name", @@ -1088,105 +884,12 @@ "name" ], "title": "NormalEntry", - "type": "object", - "additionalProperties": false + "type": "object" }, "OneLineEntry": { + "additionalProperties": false, + "description": "This class is the data model of `OneLineEntry`.", "properties": { - "start_date": { - "default": null, - "description": "The start date of the event in YYYY-MM-DD format.", - "examples": [ - "2020-09-24" - ], - "title": "Start Date", - "allOf": [ - { - "pattern": "\\d{4}-?(\\d{2})?-?(\\d{2})?", - "type": "string" - } - ] - }, - "end_date": { - "oneOf": [ - { - "const": "present" - }, - { - "pattern": "\\d{4}-?(\\d{2})?-?(\\d{2})?", - "type": "string" - }, - { - "type": "null" - } - ], - "default": null, - "description": "The end date of the event in YYYY-MM-DD format. If the event is still ongoing, then the value should be \"present\".", - "examples": [ - "2020-09-24", - "present" - ], - "title": "End Date" - }, - "date": { - "oneOf": [ - { - "type": "string" - }, - { - "type": "null" - } - ], - "default": null, - "description": "If the event is a one-day event, then this field should be filled in YYYY-MM-DD format. If the event is a multi-day event, then the start date and end date should be provided instead. All of them can't be provided at the same time.", - "examples": [ - "2020-09-24", - "My Custom Date" - ], - "title": "Date" - }, - "highlights": { - "default": [], - "description": "The highlights of the event. It will be rendered as bullet points.", - "examples": [ - "Did this.", - "Did that." - ], - "title": "Highlights", - "allOf": [ - { - "items": { - "type": "string" - }, - "type": "array" - } - ] - }, - "location": { - "default": null, - "description": "The location of the event. It will be shown with the date in the same column.", - "examples": [ - "Istanbul, Turkey" - ], - "title": "Location", - "allOf": [ - { - "type": "string" - } - ] - }, - "url": { - "default": null, - "title": "Url", - "allOf": [ - { - "format": "uri", - "maxLength": 2083, - "minLength": 1, - "type": "string" - } - ] - }, "name": { "description": "The name of the entry. It will be shown as bold text.", "title": "Name", @@ -1203,96 +906,48 @@ "details" ], "title": "OneLineEntry", + "type": "object" + }, + "PageMargins": { + "description": "This class is a data model for the page margins.", + "properties": { + "top": { + "default": "2 cm", + "description": "The top margin of the page with units. The default value is 2 cm.", + "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", + "title": "Top Margin", + "type": "string" + }, + "bottom": { + "default": "2 cm", + "description": "The bottom margin of the page with units. The default value is 2 cm.", + "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", + "title": "Bottom Margin", + "type": "string" + }, + "left": { + "default": "2 cm", + "description": "The left margin of the page with units. The default value is 2 cm.", + "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", + "title": "Left Margin", + "type": "string" + }, + "right": { + "default": "2 cm", + "description": "The right margin of the page with units. The default value is 2 cm.", + "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", + "title": "Right Margin", + "type": "string" + } + }, + "title": "PageMargins", "type": "object", "additionalProperties": false }, "PublicationEntry": { + "additionalProperties": false, + "description": "This class is the data model of `PublicationEntry`.", "properties": { - "start_date": { - "default": null, - "description": "The start date of the event in YYYY-MM-DD format.", - "examples": [ - "2020-09-24" - ], - "title": "Start Date", - "allOf": [ - { - "pattern": "\\d{4}-?(\\d{2})?-?(\\d{2})?", - "type": "string" - } - ] - }, - "end_date": { - "oneOf": [ - { - "const": "present" - }, - { - "pattern": "\\d{4}-?(\\d{2})?-?(\\d{2})?", - "type": "string" - }, - { - "type": "null" - } - ], - "default": null, - "description": "The end date of the event in YYYY-MM-DD format. If the event is still ongoing, then the value should be \"present\".", - "examples": [ - "2020-09-24", - "present" - ], - "title": "End Date" - }, - "date": { - "description": "The date of the publication.", - "examples": [ - "2021-10-31" - ], - "title": "Publication Date", - "type": "string" - }, - "highlights": { - "default": [], - "description": "The highlights of the event. It will be rendered as bullet points.", - "examples": [ - "Did this.", - "Did that." - ], - "title": "Highlights", - "allOf": [ - { - "items": { - "type": "string" - }, - "type": "array" - } - ] - }, - "location": { - "default": null, - "description": "The location of the event. It will be shown with the date in the same column.", - "examples": [ - "Istanbul, Turkey" - ], - "title": "Location", - "allOf": [ - { - "type": "string" - } - ] - }, - "url": { - "default": null, - "title": "Url", - "allOf": [ - { - "format": "uri", - "maxLength": 2083, - "minLength": 1, - "type": "string" - } - ] - }, "title": { "description": "The title of the publication. It will be shown as bold text.", "title": "Title of the Publication", @@ -1314,13 +969,18 @@ "title": "DOI", "type": "string" }, - "cited_by": { - "default": null, - "description": "The number of citations of the publication.", - "title": "Cited By", - "allOf": [ + "date": { + "default": "2020-01-01", + "description": "The date of the publication in YYYY-MM-DD, YYYY-MM, or YYYY format.", + "examples": [ + "2021-10-31", + "2010" + ], + "title": "Publication Date", + "oneOf": [ { - "type": "integer" + "pattern": "\\d{4}(-\\d{2})?(-\\d{2})?", + "type": "string" } ] }, @@ -1336,251 +996,159 @@ } }, "required": [ - "date", "title", "authors", - "doi" + "doi", + "date" ], "title": "PublicationEntry", - "type": "object", - "additionalProperties": false + "type": "object" }, - "SectionWithEducationEntries": { + "Sb2novThemeOptions": { + "additionalProperties": false, + "description": "This class is the data model of the theme options for the sb2nov theme.", "properties": { - "title": { - "description": "The title of the section.", - "examples": [ - "My Custom Section" + "font_size": { + "default": "10pt", + "description": "The font size of the CV. The default value is 10pt.", + "enum": [ + "10pt", + "11pt", + "12pt" ], - "title": "Section Title", + "title": "Font Size", "type": "string" }, - "link_text": { - "default": null, - "description": "If the section has a link, then what should be the text of the link? If this field is not provided, then the link text will be generated automatically based on the URL.", - "examples": [ - "view on GitHub", - "view on LinkedIn" + "page_size": { + "default": "letterpaper", + "description": "The page size of the CV. It can be a4paper or letterpaper. The default value is letterpaper.", + "enum": [ + "a4paper", + "letterpaper" ], - "title": "Link Text", + "title": "Page Size", + "type": "string" + }, + "color": { + "default": "rgb(0,79,144)", + "description": "The primary color of the theme. \nThe color can be specified either with their [name](https://www.w3.org/TR/SVG11/types.html#ColorKeywords), hexadecimal value, RGB value, or HSL value. The default value is rgb(0,79,144).", + "examples": [ + "Black", + "7fffd4", + "rgb(0,79,144)", + "hsl(270, 60%, 70%)" + ], + "format": "color", + "title": "Primary Color", + "type": "string" + }, + "disable_page_numbering": { + "default": false, + "description": "If this option is set to true, then the page numbering will be disabled. The default value is false.", + "title": "Disable Page Numbering", + "type": "boolean" + }, + "page_numbering_style": { + "default": "NAME - Page PAGE_NUMBER of TOTAL_PAGES", + "description": "The style of the page numbering. The following placeholders can be used:\n- NAME: The name of the person\n- PAGE_NUMBER: The current page number\n- TOTAL_PAGES: The total number of pages\nThe default value is NAME - Page PAGE_NUMBER of TOTAL_PAGES.", + "title": "Page Numbering Style", + "type": "string" + }, + "show_last_updated_date": { + "default": true, + "description": "If this option is set to true, then the last updated date will be shown in the header. The default value is true.", + "title": "Show Last Updated Date", + "type": "boolean" + }, + "header_font_size": { + "default": "24 pt", + "description": "The font size of the header (the name of the person). The default value is 24 pt. Unfortunately, sb2nov does not support font sizes bigger than 24 pt.", + "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", + "title": "Header Font Size", + "type": "string" + }, + "text_alignment": { + "default": "justified", + "description": "The alignment of the text. The default value is justified.", + "enum": [ + "left-aligned", + "justified" + ], + "title": "Text Alignment", + "type": "string" + }, + "margins": { "allOf": [ { - "type": "string" + "$ref": "#/$defs/Margins" + } + ], + "default": { + "page": { + "bottom": "2 cm", + "left": "2 cm", + "right": "2 cm", + "top": "2 cm" + }, + "section_title": { + "bottom": "0.2 cm", + "top": "0.3 cm" + }, + "entry_area": { + "date_and_location_width": "4.1 cm", + "left_and_right": "0.2 cm", + "vertical_between": "0.2 cm" + }, + "highlights_area": { + "left": "0.4 cm", + "top": "0.10 cm", + "vertical_between_bullet_points": "0.10 cm" + }, + "header": { + "bottom": "0.3 cm", + "horizontal_between_connections": "0.5 cm", + "vertical_between_name_and_connections": "0.3 cm" } - ] - }, - "entry_type": { - "const": "EducationEntry", - "description": "The type of the entries in the section.", - "title": "Entry Type" - }, - "entries": { - "description": "The entries of the section. The format depends on the entry type.", - "items": { - "$ref": "#/$defs/EducationEntry" }, - "title": "Entries", - "type": "array" + "description": "Page, section title, entry field, and highlights field margins.", + "title": "Margins" + }, + "theme": { + "const": "sb2nov", + "title": "Theme" } }, "required": [ - "title", - "entry_type", - "entries" + "theme" ], - "title": "SectionWithEducationEntries", - "type": "object", - "additionalProperties": false + "title": "Sb2novThemeOptions", + "type": "object" }, - "SectionWithExperienceEntries": { + "SectionTitleMargins": { + "description": "This class is a data model for the section title margins.", "properties": { - "title": { - "description": "The title of the section.", - "examples": [ - "My Custom Section" - ], - "title": "Section Title", + "top": { + "default": "0.3 cm", + "description": "The top margin of section titles. The default value is 0.3 cm.", + "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", + "title": "Top Margin", "type": "string" }, - "link_text": { - "default": null, - "description": "If the section has a link, then what should be the text of the link? If this field is not provided, then the link text will be generated automatically based on the URL.", - "examples": [ - "view on GitHub", - "view on LinkedIn" - ], - "title": "Link Text", - "allOf": [ - { - "type": "string" - } - ] - }, - "entry_type": { - "const": "ExperienceEntry", - "description": "The type of the entries in the section.", - "title": "Entry Type" - }, - "entries": { - "description": "The entries of the section. The format depends on the entry type.", - "items": { - "$ref": "#/$defs/ExperienceEntry" - }, - "title": "Entries", - "type": "array" - } - }, - "required": [ - "title", - "entry_type", - "entries" - ], - "title": "SectionWithExperienceEntries", - "type": "object", - "additionalProperties": false - }, - "SectionWithNormalEntries": { - "properties": { - "title": { - "description": "The title of the section.", - "examples": [ - "My Custom Section" - ], - "title": "Section Title", + "bottom": { + "default": "0.2 cm", + "description": "The bottom margin of section titles. The default value is 0.3 cm.", + "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", + "title": "Bottom Margin", "type": "string" - }, - "link_text": { - "default": null, - "description": "If the section has a link, then what should be the text of the link? If this field is not provided, then the link text will be generated automatically based on the URL.", - "examples": [ - "view on GitHub", - "view on LinkedIn" - ], - "title": "Link Text", - "allOf": [ - { - "type": "string" - } - ] - }, - "entry_type": { - "const": "NormalEntry", - "description": "The type of the entries in the section.", - "title": "Entry Type" - }, - "entries": { - "description": "The entries of the section. The format depends on the entry type.", - "items": { - "$ref": "#/$defs/NormalEntry" - }, - "title": "Entries", - "type": "array" } }, - "required": [ - "title", - "entry_type", - "entries" - ], - "title": "SectionWithNormalEntries", - "type": "object", - "additionalProperties": false - }, - "SectionWithOneLineEntries": { - "properties": { - "title": { - "description": "The title of the section.", - "examples": [ - "My Custom Section" - ], - "title": "Section Title", - "type": "string" - }, - "link_text": { - "default": null, - "description": "If the section has a link, then what should be the text of the link? If this field is not provided, then the link text will be generated automatically based on the URL.", - "examples": [ - "view on GitHub", - "view on LinkedIn" - ], - "title": "Link Text", - "allOf": [ - { - "type": "string" - } - ] - }, - "entry_type": { - "const": "OneLineEntry", - "description": "The type of the entries in the section.", - "title": "Entry Type" - }, - "entries": { - "description": "The entries of the section. The format depends on the entry type.", - "items": { - "$ref": "#/$defs/OneLineEntry" - }, - "title": "Entries", - "type": "array" - } - }, - "required": [ - "title", - "entry_type", - "entries" - ], - "title": "SectionWithOneLineEntries", - "type": "object", - "additionalProperties": false - }, - "SectionWithPublicationEntries": { - "properties": { - "title": { - "description": "The title of the section.", - "examples": [ - "My Custom Section" - ], - "title": "Section Title", - "type": "string" - }, - "link_text": { - "default": null, - "description": "If the section has a link, then what should be the text of the link? If this field is not provided, then the link text will be generated automatically based on the URL.", - "examples": [ - "view on GitHub", - "view on LinkedIn" - ], - "title": "Link Text", - "allOf": [ - { - "type": "string" - } - ] - }, - "entry_type": { - "const": "PublicationEntry", - "description": "The type of the entries in the section.", - "title": "Entry Type" - }, - "entries": { - "description": "The entries of the section. The format depends on the entry type.", - "items": { - "$ref": "#/$defs/PublicationEntry" - }, - "title": "Entries", - "type": "array" - } - }, - "required": [ - "title", - "entry_type", - "entries" - ], - "title": "SectionWithPublicationEntries", + "title": "SectionTitleMargins", "type": "object", "additionalProperties": false }, "SocialNetwork": { + "additionalProperties": false, + "description": "This class is the data model of a social network.", "properties": { "network": { "description": "The social network name.", @@ -1589,7 +1157,8 @@ "GitHub", "Instagram", "Orcid", - "Mastodon" + "Mastodon", + "Twitter" ], "title": "Social Network", "type": "string" @@ -1605,100 +1174,88 @@ "username" ], "title": "SocialNetwork", - "type": "object", - "additionalProperties": false + "type": "object" } }, + "additionalProperties": false, + "description": "RenderCV data model.", "properties": { - "design": { - "allOf": [ - { - "$ref": "#/$defs/Design" - } - ], - "default": { - "font": "SourceSans3", - "font_size": "10pt", - "options": { - "date_and_location_width": "4.1 cm", - "header_font_size": "30 pt", - "margins": { - "entry_area": { - "left_and_right": "0.2 cm", - "vertical_between": "0.12 cm" - }, - "header": { - "bottom": "0.2 cm", - "vertical_between_name_and_connections": "0.2 cm" - }, - "highlights_area": { - "left": "0.4 cm", - "top": "0.10 cm", - "vertical_between_bullet_points": "0.10 cm" - }, - "page": { - "bottom": "2 cm", - "left": "1.24 cm", - "right": "1.24 cm", - "top": "2 cm" - }, - "section_title": { - "bottom": "0.2 cm", - "top": "0.2 cm" - } - }, - "primary_color": "#004f90", - "show_last_updated_date": true, - "show_timespan_in": [], - "text_alignment": "left-aligned" - }, - "page_size": "a4paper", - "theme": "classic" - }, - "description": "The design of the CV.", - "title": "Design" - }, "cv": { "allOf": [ { "$ref": "#/$defs/CurriculumVitae" } ], - "default": { - "academic_projects": null, - "awards": null, - "certificates": null, - "connections": [], - "custom_sections": null, - "education": null, - "email": null, - "experience": null, - "extracurricular_activities": null, - "interests": null, - "label": null, - "location": null, - "name": "John Doe", - "other_skills": null, - "personal_projects": null, - "phone": null, - "programming_skills": null, - "projects": null, - "publications": null, - "section_order": null, - "sections": [], - "skills": null, - "social_networks": null, - "summary": null, - "test_scores": null, - "university_projects": null, - "website": null, - "work_experience": null - }, "description": "The data of the CV.", "title": "Curriculum Vitae" + }, + "design": { + "default": { + "font_size": "10pt", + "page_size": "letterpaper", + "color": "#004f90", + "disable_page_numbering": false, + "page_numbering_style": "NAME - Page PAGE_NUMBER of TOTAL_PAGES", + "show_last_updated_date": true, + "header_font_size": "30 pt", + "text_alignment": "justified", + "margins": { + "entry_area": { + "date_and_location_width": "4.1 cm", + "left_and_right": "0.2 cm", + "vertical_between": "0.2 cm" + }, + "header": { + "bottom": "0.3 cm", + "horizontal_between_connections": "0.5 cm", + "vertical_between_name_and_connections": "0.3 cm" + }, + "highlights_area": { + "left": "0.4 cm", + "top": "0.10 cm", + "vertical_between_bullet_points": "0.10 cm" + }, + "page": { + "bottom": "2 cm", + "left": "2 cm", + "right": "2 cm", + "top": "2 cm" + }, + "section_title": { + "bottom": "0.2 cm", + "top": "0.3 cm" + } + }, + "theme": "classic", + "show_timespan_in": [] + }, + "description": "The design information of the CV. The default is the classic theme.", + "discriminator": { + "mapping": { + "classic": "#/$defs/ClassicThemeOptions", + "moderncv": "#/$defs/ModerncvThemeOptions", + "sb2nov": "#/$defs/Sb2novThemeOptions" + }, + "propertyName": "theme" + }, + "oneOf": [ + { + "$ref": "#/$defs/ClassicThemeOptions" + }, + { + "$ref": "#/$defs/ModerncvThemeOptions" + }, + { + "$ref": "#/$defs/Sb2novThemeOptions" + } + ], + "title": "Design" } }, - "title": "RenderCV Input", + "required": [ + "cv" + ], + "title": "RenderCV", "type": "object", "$id": "https://raw.githubusercontent.com/sinaatalay/rendercv/main/schema.json", "$schema": "http://json-schema.org/draft-07/schema#" diff --git a/tests/auxiliary_files/John_Doe_CV.yaml b/tests/auxiliary_files/John_Doe_CV.yaml new file mode 100644 index 0000000..cf13d02 --- /dev/null +++ b/tests/auxiliary_files/John_Doe_CV.yaml @@ -0,0 +1,4 @@ +cv: + name: John Doe +design: + theme: classic diff --git a/tests/auxiliary_files/test_copy_theme_files_to_output_directory/LICENSE b/tests/auxiliary_files/test_copy_theme_files_to_output_directory/LICENSE new file mode 100644 index 0000000..4d4f656 --- /dev/null +++ b/tests/auxiliary_files/test_copy_theme_files_to_output_directory/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 Sourabh Bajaj + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/EducationEntry.j2.tex b/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/EducationEntry.j2.tex new file mode 100644 index 0000000..e69de29 diff --git a/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/ExperienceEntry.j2.tex b/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/ExperienceEntry.j2.tex new file mode 100644 index 0000000..e69de29 diff --git a/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/Header.j2.tex b/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/Header.j2.tex new file mode 100644 index 0000000..e69de29 diff --git a/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/NormalEntry.j2.tex b/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/NormalEntry.j2.tex new file mode 100644 index 0000000..e69de29 diff --git a/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/OneLineEntry.j2.tex b/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/OneLineEntry.j2.tex new file mode 100644 index 0000000..e69de29 diff --git a/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/Preamble.j2.tex b/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/Preamble.j2.tex new file mode 100644 index 0000000..e69de29 diff --git a/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/PublicationEntry.j2.tex b/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/PublicationEntry.j2.tex new file mode 100644 index 0000000..e69de29 diff --git a/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/SectionBeginning.j2.tex b/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/SectionBeginning.j2.tex new file mode 100644 index 0000000..e69de29 diff --git a/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/SectionEnding.j2.tex b/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/SectionEnding.j2.tex new file mode 100644 index 0000000..e69de29 diff --git a/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/TextEntry.j2.tex b/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/TextEntry.j2.tex new file mode 100644 index 0000000..e69de29 diff --git a/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/__init__.py b/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/__init__.py new file mode 100644 index 0000000..ce07e49 --- /dev/null +++ b/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/__init__.py @@ -0,0 +1,7 @@ +from typing import Literal + +import pydantic + + +class DummythemeThemeOptions(pydantic.BaseModel): + theme: Literal['dummytheme'] diff --git a/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/theme_auxiliary_file.cls b/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/dummytheme/theme_auxiliary_file.cls new file mode 100644 index 0000000..e69de29 diff --git a/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/theme_auxiliary_files/theme_auxiliary_file.cls b/tests/auxiliary_files/test_copy_theme_files_to_output_directory_custom_theme/theme_auxiliary_files/theme_auxiliary_file.cls new file mode 100644 index 0000000..e69de29 diff --git a/tests/auxiliary_files/test_generate_latex_file/classic_empty/None_CV.tex b/tests/auxiliary_files/test_generate_latex_file/classic_empty/None_CV.tex new file mode 100644 index 0000000..cdf6845 --- /dev/null +++ b/tests/auxiliary_files/test_generate_latex_file/classic_empty/None_CV.tex @@ -0,0 +1,142 @@ +\documentclass[10pt, letterpaper]{article} + +% Packages: +\usepackage[ + ignoreheadfoot, % set margins without considering header and footer + top=2 cm, % seperation between body and page edge from the top + bottom=2 cm, % seperation between body and page edge from the bottom + left=2 cm, % seperation between body and page edge from the left + right=2 cm, % seperation between body and page edge from the right + footskip=1.0 cm, % seperation between body and footer + % showframe % for debugging + ]{geometry} % for adjusting page geometry +\usepackage[explicit]{titlesec} % for customizing section titles +\usepackage{tabularx} % for making tables with fixed width columns +\usepackage{array} % tabularx requires this +\usepackage[dvipsnames]{xcolor} % for coloring text +\definecolor{primaryColor}{RGB}{0, 79, 144} % define primary color +\usepackage{enumitem} % for customizing lists +\usepackage{fontawesome5} % for using icons +\usepackage{amsmath} % for math +\usepackage[ + pdftitle={None's CV}, + pdfauthor={None}, + colorlinks=true, + urlcolor=primaryColor +]{hyperref} % for links, metadata and bookmarks +\usepackage[pscoord]{eso-pic} % for floating text on the page +\usepackage{calc} % for calculating lengths +\usepackage{bookmark} % for bookmarks +\usepackage{lastpage} % for getting the total number of pages +\usepackage[default, type1]{sourcesanspro} % for using source sans 3 font +\usepackage{ifthen} + +% Some settings: +\pagestyle{empty} % no header or footer +\setcounter{secnumdepth}{0} % no section numbering +\setlength{\parindent}{0pt} % no indentation +\setlength{\topskip}{0pt} % no top skip +\makeatletter +\let\ps@customFooterStyle\ps@plain % Copy the plain style to customFooterStyle +\patchcmd{\ps@customFooterStyle}{\thepage}{ + \color{gray}\textit{\small None - Page \thepage{} of \pageref*{LastPage}} +}{}{} % replace number by desired string +\makeatother +\pagestyle{customFooterStyle} + +\titleformat{\section}{ + % make the font size of the section title large and color it with the primary color + \Large\color{primaryColor} + }{ + }{ + }{ + % print bold title, give 0.15 cm space and draw a line of 0.8 pt thickness + % from the end of the title to the end of the body + \textbf{#1}\hspace{0.15cm}\titlerule[0.8pt]\hspace{-0.1cm} + }[] % section title formatting + +\titlespacing{\section}{ + % left space: + 0pt + }{ + % top space: + 0.3 cm + }{ + % bottom space: + 0.2 cm + } % section title spacing + +\newcolumntype{L}[1]{ + >{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1} +} % left-aligned fixed width column type +\newcolumntype{R}[1]{ + >{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1} +} % right-aligned fixed width column type +\newcolumntype{K}[1]{ + >{\let\newline\\\arraybackslash\hspace{0pt}}X +} % justified flexible width column type +\setlength\tabcolsep{-1.5pt} % no space between columns +\newenvironment{highlights}{ + \begin{itemize}[ + topsep=0pt, + parsep=0.10 cm, + partopsep=0pt, + itemsep=0pt, + after=\vspace{-1\baselineskip}, + leftmargin=0.4 cm + 3pt + ] + }{ + \end{itemize} + } % new environment for highlights + +\newenvironment{header}{ + \setlength{\topsep}{0pt}\par\kern\topsep\centering\color{primaryColor}\linespread{1.5} + }{ + \par\kern\topsep + } % new environment for the header + +\newcommand{\placelastupdatedtext}{% \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>} + \AddToShipoutPictureFG*{% Add <stuff> to current page foreground + \put( + \LenToUnit{\paperwidth-2 cm-0.2 cm+0.05cm}, + \LenToUnit{\paperheight-1.0 cm} + ){\vtop{{\null}\makebox[0pt][c]{ + \small\color{gray}\textit{Last updated in January 2024}\hspace{\widthof{Last updated in January 2024}} + }}}% + }% +}% + +% save the original href command in a new command: +\let\hrefWithoutArrow\href + % new command for external links: +\renewcommand{\href}[2]{\hrefWithoutArrow{#1}{\mbox{\ifthenelse{\equal{#2}{}}{ }{#2 }\raisebox{.15ex}{\footnotesize \faExternalLink*}}}} + +\let\originalTabularx\tabularx +\let\originalEndTabularx\endtabularx + +\renewenvironment{tabularx}{\bgroup\centering\originalTabularx}{\originalEndTabularx\par\egroup} + +% For TextEntrys (see https://tex.stackexchange.com/a/600/287984): +\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1\topsep=0pt\itemsep=0pt\parsep=0pt\parskip=0pt\labelwidth=0pt\itemindent=0pt\labelsep=0pt}\item[]} +\let\endchangemargin=\endlist + +% Ensure that generate pdf is machine readable/ATS parsable +\pdfgentounicode=1 + +\begin{document} + \placelastupdatedtext + + + \section{Test} + + \begin{changemargin}{0.2 cm}{0.2 cm} + test + \end{changemargin} + + + + + + + +\end{document} \ No newline at end of file diff --git a/tests/auxiliary_files/test_generate_latex_file/classic_filled/John_Doe_CV.tex b/tests/auxiliary_files/test_generate_latex_file/classic_filled/John_Doe_CV.tex new file mode 100644 index 0000000..b336570 --- /dev/null +++ b/tests/auxiliary_files/test_generate_latex_file/classic_filled/John_Doe_CV.tex @@ -0,0 +1,333 @@ +\documentclass[10pt, letterpaper]{article} + +% Packages: +\usepackage[ + ignoreheadfoot, % set margins without considering header and footer + top=2 cm, % seperation between body and page edge from the top + bottom=2 cm, % seperation between body and page edge from the bottom + left=2 cm, % seperation between body and page edge from the left + right=2 cm, % seperation between body and page edge from the right + footskip=1.0 cm, % seperation between body and footer + % showframe % for debugging + ]{geometry} % for adjusting page geometry +\usepackage[explicit]{titlesec} % for customizing section titles +\usepackage{tabularx} % for making tables with fixed width columns +\usepackage{array} % tabularx requires this +\usepackage[dvipsnames]{xcolor} % for coloring text +\definecolor{primaryColor}{RGB}{0, 79, 144} % define primary color +\usepackage{enumitem} % for customizing lists +\usepackage{fontawesome5} % for using icons +\usepackage{amsmath} % for math +\usepackage[ + pdftitle={John Doe's CV}, + pdfauthor={John Doe}, + colorlinks=true, + urlcolor=primaryColor +]{hyperref} % for links, metadata and bookmarks +\usepackage[pscoord]{eso-pic} % for floating text on the page +\usepackage{calc} % for calculating lengths +\usepackage{bookmark} % for bookmarks +\usepackage{lastpage} % for getting the total number of pages +\usepackage[default, type1]{sourcesanspro} % for using source sans 3 font +\usepackage{ifthen} + +% Some settings: +\pagestyle{empty} % no header or footer +\setcounter{secnumdepth}{0} % no section numbering +\setlength{\parindent}{0pt} % no indentation +\setlength{\topskip}{0pt} % no top skip +\makeatletter +\let\ps@customFooterStyle\ps@plain % Copy the plain style to customFooterStyle +\patchcmd{\ps@customFooterStyle}{\thepage}{ + \color{gray}\textit{\small John Doe - Page \thepage{} of \pageref*{LastPage}} +}{}{} % replace number by desired string +\makeatother +\pagestyle{customFooterStyle} + +\titleformat{\section}{ + % make the font size of the section title large and color it with the primary color + \Large\color{primaryColor} + }{ + }{ + }{ + % print bold title, give 0.15 cm space and draw a line of 0.8 pt thickness + % from the end of the title to the end of the body + \textbf{#1}\hspace{0.15cm}\titlerule[0.8pt]\hspace{-0.1cm} + }[] % section title formatting + +\titlespacing{\section}{ + % left space: + 0pt + }{ + % top space: + 0.3 cm + }{ + % bottom space: + 0.2 cm + } % section title spacing + +\newcolumntype{L}[1]{ + >{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1} +} % left-aligned fixed width column type +\newcolumntype{R}[1]{ + >{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1} +} % right-aligned fixed width column type +\newcolumntype{K}[1]{ + >{\let\newline\\\arraybackslash\hspace{0pt}}X +} % justified flexible width column type +\setlength\tabcolsep{-1.5pt} % no space between columns +\newenvironment{highlights}{ + \begin{itemize}[ + topsep=0pt, + parsep=0.10 cm, + partopsep=0pt, + itemsep=0pt, + after=\vspace{-1\baselineskip}, + leftmargin=0.4 cm + 3pt + ] + }{ + \end{itemize} + } % new environment for highlights + +\newenvironment{header}{ + \setlength{\topsep}{0pt}\par\kern\topsep\centering\color{primaryColor}\linespread{1.5} + }{ + \par\kern\topsep + } % new environment for the header + +\newcommand{\placelastupdatedtext}{% \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>} + \AddToShipoutPictureFG*{% Add <stuff> to current page foreground + \put( + \LenToUnit{\paperwidth-2 cm-0.2 cm+0.05cm}, + \LenToUnit{\paperheight-1.0 cm} + ){\vtop{{\null}\makebox[0pt][c]{ + \small\color{gray}\textit{Last updated in January 2024}\hspace{\widthof{Last updated in January 2024}} + }}}% + }% +}% + +% save the original href command in a new command: +\let\hrefWithoutArrow\href + % new command for external links: +\renewcommand{\href}[2]{\hrefWithoutArrow{#1}{\mbox{\ifthenelse{\equal{#2}{}}{ }{#2 }\raisebox{.15ex}{\footnotesize \faExternalLink*}}}} + +\let\originalTabularx\tabularx +\let\originalEndTabularx\endtabularx + +\renewenvironment{tabularx}{\bgroup\centering\originalTabularx}{\originalEndTabularx\par\egroup} + +% For TextEntrys (see https://tex.stackexchange.com/a/600/287984): +\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1\topsep=0pt\itemsep=0pt\parsep=0pt\parskip=0pt\labelwidth=0pt\itemindent=0pt\labelsep=0pt}\item[]} +\let\endchangemargin=\endlist + +% Ensure that generate pdf is machine readable/ATS parsable +\pdfgentounicode=1 + +\begin{document} + \placelastupdatedtext + \begin{header} + \fontsize{30 pt}{30 pt} + \hrefWithoutArrow{https://orcid.org/0000-0000-0000-0000}{\textbf{John Doe}} + + \vspace{0.3 cm} + + \normalsize + \mbox{\hrefWithoutArrow{tel:+905419999999}{{\footnotesize\faPhone*}\hspace*{0.13cm}+90 541 999 99 99}} + \hspace*{0.5 cm} + \mbox{\hrefWithoutArrow{mailto:johndoe@example.com}{{\small\faEnvelope[regular]}\hspace*{0.13cm}johndoe@example.com}} + \hspace*{0.5 cm} + \mbox{{\small\faMapMarker*}\hspace*{0.13cm}Istanbul, Turkey} + \hspace*{0.5 cm} + \mbox{\hrefWithoutArrow{https://example.com/}{{\small\faLink}\hspace*{0.13cm}example.com}} + \hspace*{0.5 cm} + \mbox{\hrefWithoutArrow{https://linkedin.com/in/johndoe}{{\small\faLinkedinIn}\hspace*{0.13cm}johndoe}} + \hspace*{0.5 cm} + \mbox{\hrefWithoutArrow{https://github.com/johndoe}{{\small\faGithub}\hspace*{0.13cm}johndoe}} + \hspace*{0.5 cm} + \mbox{\hrefWithoutArrow{https://instagram.com/johndoe}{{\small\faInstagram}\hspace*{0.13cm}johndoe}} + \hspace*{0.5 cm} + \mbox{\hrefWithoutArrow{https://mastodon.social/@johndoe@example}{{\small\faMastodon}\hspace*{0.13cm}@johndoe@example}} + \hspace*{0.5 cm} + \end{header} + + \vspace{0.3 cm} + + + \section{Section1} + + \begin{changemargin}{0.2 cm}{0.2 cm} + My Text Entry + \end{changemargin} + + + + + \vspace{0.2 cm} + \begin{changemargin}{0.2 cm}{0.2 cm} + My Text Entry + \end{changemargin} + + + + + + + \section{Section2} + + \begin{tabularx}{\textwidth-0.4 cm-0.13cm}{K{0.2 cm} R{4.1 cm}} + \textbf{My Title} + + \vspace{0.10 cm} + + \mbox{\textbf{\textit{J. Doe}}}, \mbox{\textbf{\textit{J. Doe}}} + + \vspace{0.10 cm} + + \href{https://doi.org/10.1109/TASC.2023.3340648}{10.1109/TASC.2023.3340648} () & + Dec. 2023 + \end{tabularx} + + \vspace{0.2 cm} + \begin{tabularx}{\textwidth-0.4 cm-0.13cm}{K{0.2 cm} R{4.1 cm}} + \textbf{My Title} + + \vspace{0.10 cm} + + \mbox{\textbf{\textit{J. Doe}}}, \mbox{\textbf{\textit{J. Doe}}} + + \vspace{0.10 cm} + + \href{https://doi.org/10.1109/TASC.2023.3340648}{10.1109/TASC.2023.3340648} () & + Dec. 2023 + \end{tabularx} + + + + \section{Section3} + + \begin{tabularx}{ + \textwidth-0.4 cm-0.13cm + }{ + K{0.2 cm} + R{4.1 cm} + } + \textbf{CERN}, Researcher + + \vspace{0.10 cm} + + & + + + + \end{tabularx} + + \vspace{0.2 cm} + \begin{tabularx}{ + \textwidth-0.4 cm-0.13cm + }{ + K{0.2 cm} + R{4.1 cm} + } + \textbf{CERN}, Researcher + + \vspace{0.10 cm} + + & + + + + \end{tabularx} + + + + \section{Section4} + + \begin{tabularx}{ + \textwidth-0.4 cm-0.13cm + }{ + L{0.85cm} + K{0.2 cm} + R{4.1 cm} + } + \textbf{BS} + & + \textbf{Boğaziçi University}, Mechanical Engineering + + \vspace{0.10 cm} + + & + + + + \end{tabularx} + + \vspace{0.2 cm} + \begin{tabularx}{ + \textwidth-0.4 cm-0.13cm + }{ + L{0.85cm} + K{0.2 cm} + R{4.1 cm} + } + \textbf{BS} + & + \textbf{Boğaziçi University}, Mechanical Engineering + + \vspace{0.10 cm} + + & + + + + \end{tabularx} + + + + \section{Section5} + + \begin{tabularx}{ + \textwidth-0.4 cm-0.13cm + }{ + K{0.2 cm} + } + \textbf{My Entry} + + \vspace{0.10 cm} + + \end{tabularx} + + + \vspace{0.2 cm} + \begin{tabularx}{ + \textwidth-0.4 cm-0.13cm + }{ + K{0.2 cm} + } + \textbf{My Entry} + + \vspace{0.10 cm} + + \end{tabularx} + + + + + \section{Section6} + + \begingroup\leftskip=0.2 cm + \advance\csname @rightskip\endcsname 0.2 cm + \advance\rightskip 0.2 cm + + \textbf{My One Line Entry:} My Details and some math $a=6^4 \frac{3}{5}$ \par\endgroup + + \vspace{0.2 cm} + \begingroup\leftskip=0.2 cm + \advance\csname @rightskip\endcsname 0.2 cm + \advance\rightskip 0.2 cm + + \textbf{My One Line Entry:} My Details and some math $a=6^4 \frac{3}{5}$ \par\endgroup + + + + +\end{document} \ No newline at end of file diff --git a/tests/auxiliary_files/test_generate_latex_file/moderncv_empty/None_CV.tex b/tests/auxiliary_files/test_generate_latex_file/moderncv_empty/None_CV.tex new file mode 100644 index 0000000..aa658df --- /dev/null +++ b/tests/auxiliary_files/test_generate_latex_file/moderncv_empty/None_CV.tex @@ -0,0 +1,78 @@ +%% start of file `template.tex'. +%% Copyright 2006-2015 Xavier Danaux (xdanaux@gmail.com), 2020-2022 moderncv maintainers (github.com/moderncv). +% +% This work may be distributed and/or modified under the +% conditions of the LaTeX Project Public License version 1.3c, +% available at http://www.latex-project.org/lppl/. + +\documentclass[10pt,letterpaper,sans]{moderncv} % possible options include font size ('10pt', '11pt' and '12pt'), paper size ('a4paper', 'letterpaper', 'a5paper', 'legalpaper', 'executivepaper' and 'landscape') and font family ('sans' and 'roman') + +% moderncv themes +\moderncvstyle{classic} % style options are 'casual' (default), 'classic', 'banking', 'oldstyle' and 'fancy' +\moderncvcolor{blue} % color options 'black', 'blue' (default), 'burgundy', 'green', 'grey', 'orange', 'purple' and 'red' +%\renewcommand{\familydefault}{\sfdefault} % to set the default font; use '\sfdefault' for the default sans serif font, '\rmdefault' for the default roman one, or any tex font name + +\usepackage{amsmath} % for math + +% adjust the page margins +\usepackage[scale=0.75]{geometry} +\setlength{\hintscolumnwidth}{3.8 cm} % if you want to change the width of the column with the dates +%\setlength{\makecvheadnamewidth}{10cm} % for the 'classic' style, if you want to force the width allocated to your name and avoid line breaks. be careful though, the length is normally calculated to avoid any overlap with your personal info; use this at your own typographical risks... + +% font loading +% for luatex and xetex, do not use inputenc and fontenc +% see https://tex.stackexchange.com/a/496643 +\ifxetexorluatex + \usepackage{fontspec} + \usepackage{unicode-math} + \defaultfontfeatures{Ligatures=TeX} + \setmainfont{Latin Modern Roman} + \setsansfont{Latin Modern Sans} + \setmonofont{Latin Modern Mono} + \setmathfont{Latin Modern Math} +\else + \usepackage[T1]{fontenc} + \usepackage{lmodern} +\fi + +% document language +\usepackage[english]{babel} % FIXME: using spanish breaks moderncv + +% personal data +\name{None}{} +% \familyname{} + +% Social icons +% \social[linkedin]{john.doe} % optional, remove / comment the line if not wanted +% \social[xing]{john\_doe} % optional, remove / comment the line if not wanted +% \social[twitter]{ji\_doe} % optional, remove / comment the line if not wanted +% \social[github]{jdoe} % optional, remove / comment the line if not wanted +% \social[gitlab]{jdoe} % optional, remove / comment the line if not wanted +% \social[stackoverflow]{0000000/johndoe} % optional, remove / comment the line if not wanted +% \social[bitbucket]{jdoe} % optional, remove / comment the line if not wanted +% \social[skype]{jdoe} % optional, remove / comment the line if not wanted +% \social[orcid]{0000-0000-000-000} % optional, remove / comment the line if not wanted +% \social[researchgate]{jdoe} % optional, remove / comment the line if not wanted +% \social[researcherid]{jdoe} % optional, remove / comment the line if not wanted +% \social[telegram]{jdoe} % optional, remove / comment the line if not wanted +% \social[whatsapp]{12345678901} % optional, remove / comment the line if not wanted +% \social[signal]{12345678901} % optional, remove / comment the line if not wanted +% \social[matrix]{@johndoe:matrix.org} % optional, remove / comment the line if not wanted +% \social[googlescholar]{googlescholarid} % optional, remove / comment the line if not wanted + +\begin{document} + + + % save the original href command in a new command: + \let\hrefWithoutArrow\href + % new command for external links: + \renewcommand{\href}[2]{\hrefWithoutArrow{#1}{\mbox{\color{color1} #2 \raisebox{.15ex}{\footnotesize \faExternalLink*}}}} + + \section{Test} + + \cvlistitem{test} + + + + +\end{document} \ No newline at end of file diff --git a/tests/auxiliary_files/test_generate_latex_file/moderncv_filled/John_Doe_CV.tex b/tests/auxiliary_files/test_generate_latex_file/moderncv_filled/John_Doe_CV.tex new file mode 100644 index 0000000..b554fa3 --- /dev/null +++ b/tests/auxiliary_files/test_generate_latex_file/moderncv_filled/John_Doe_CV.tex @@ -0,0 +1,137 @@ +%% start of file `template.tex'. +%% Copyright 2006-2015 Xavier Danaux (xdanaux@gmail.com), 2020-2022 moderncv maintainers (github.com/moderncv). +% +% This work may be distributed and/or modified under the +% conditions of the LaTeX Project Public License version 1.3c, +% available at http://www.latex-project.org/lppl/. + +\documentclass[10pt,letterpaper,sans]{moderncv} % possible options include font size ('10pt', '11pt' and '12pt'), paper size ('a4paper', 'letterpaper', 'a5paper', 'legalpaper', 'executivepaper' and 'landscape') and font family ('sans' and 'roman') + +% moderncv themes +\moderncvstyle{classic} % style options are 'casual' (default), 'classic', 'banking', 'oldstyle' and 'fancy' +\moderncvcolor{blue} % color options 'black', 'blue' (default), 'burgundy', 'green', 'grey', 'orange', 'purple' and 'red' +%\renewcommand{\familydefault}{\sfdefault} % to set the default font; use '\sfdefault' for the default sans serif font, '\rmdefault' for the default roman one, or any tex font name + +\usepackage{amsmath} % for math + +% adjust the page margins +\usepackage[scale=0.75]{geometry} +\setlength{\hintscolumnwidth}{3.8 cm} % if you want to change the width of the column with the dates +%\setlength{\makecvheadnamewidth}{10cm} % for the 'classic' style, if you want to force the width allocated to your name and avoid line breaks. be careful though, the length is normally calculated to avoid any overlap with your personal info; use this at your own typographical risks... + +% font loading +% for luatex and xetex, do not use inputenc and fontenc +% see https://tex.stackexchange.com/a/496643 +\ifxetexorluatex + \usepackage{fontspec} + \usepackage{unicode-math} + \defaultfontfeatures{Ligatures=TeX} + \setmainfont{Latin Modern Roman} + \setsansfont{Latin Modern Sans} + \setmonofont{Latin Modern Mono} + \setmathfont{Latin Modern Math} +\else + \usepackage[T1]{fontenc} + \usepackage{lmodern} +\fi + +% document language +\usepackage[english]{babel} % FIXME: using spanish breaks moderncv + +% personal data +\name{John Doe}{} +\title{Mechanical Engineer} % optional, remove / comment the line if not wanted +% \familyname{} +\address{Istanbul, Turkey}{} +\phone[mobile]{+90 541 999 99 99} +\email{johndoe@example.com} +\homepage{example.com} + +\social[linkedin]{johndoe} +\social[github]{johndoe} +\social[orcid]{0000-0000-0000-0000} +% Social icons +% \social[linkedin]{john.doe} % optional, remove / comment the line if not wanted +% \social[xing]{john\_doe} % optional, remove / comment the line if not wanted +% \social[twitter]{ji\_doe} % optional, remove / comment the line if not wanted +% \social[github]{jdoe} % optional, remove / comment the line if not wanted +% \social[gitlab]{jdoe} % optional, remove / comment the line if not wanted +% \social[stackoverflow]{0000000/johndoe} % optional, remove / comment the line if not wanted +% \social[bitbucket]{jdoe} % optional, remove / comment the line if not wanted +% \social[skype]{jdoe} % optional, remove / comment the line if not wanted +% \social[orcid]{0000-0000-000-000} % optional, remove / comment the line if not wanted +% \social[researchgate]{jdoe} % optional, remove / comment the line if not wanted +% \social[researcherid]{jdoe} % optional, remove / comment the line if not wanted +% \social[telegram]{jdoe} % optional, remove / comment the line if not wanted +% \social[whatsapp]{12345678901} % optional, remove / comment the line if not wanted +% \social[signal]{12345678901} % optional, remove / comment the line if not wanted +% \social[matrix]{@johndoe:matrix.org} % optional, remove / comment the line if not wanted +% \social[googlescholar]{googlescholarid} % optional, remove / comment the line if not wanted + +\begin{document} + \maketitle + + + % save the original href command in a new command: + \let\hrefWithoutArrow\href + % new command for external links: + \renewcommand{\href}[2]{\hrefWithoutArrow{#1}{\mbox{\color{color1} #2 \raisebox{.15ex}{\footnotesize \faExternalLink*}}}} + + \section{Section1} + + \cvlistitem{My Text Entry} + + \cvlistitem{My Text Entry} + + + + \section{Section2} + + \cventry{Dec. 2023}{My Title}{}{\href{https://doi.org/10.1109/TASC.2023.3340648}{10.1109/TASC.2023.3340648}}{}{} + \cvline{}{\small \mbox{\textbf{\textit{J. Doe}}}, \mbox{\textbf{\textit{J. Doe}}}} + + \cventry{Dec. 2023}{My Title}{}{\href{https://doi.org/10.1109/TASC.2023.3340648}{10.1109/TASC.2023.3340648}}{}{} + \cvline{}{\small \mbox{\textbf{\textit{J. Doe}}}, \mbox{\textbf{\textit{J. Doe}}}} + + + + \section{Section3} + + \cventry{}{Researcher}{CERN}{}{}{} + + + \cventry{}{Researcher}{CERN}{}{}{} + + + + + \section{Section4} + + \cventry{}{BS, Mechanical Engineering}{Boğaziçi University}{}{}{} + + + \cventry{}{BS, Mechanical Engineering}{Boğaziçi University}{}{}{} + + + + + \section{Section5} + + \cventry{}{My Entry}{}{}{}{} + + + \cventry{}{My Entry}{}{}{}{} + + + + + \section{Section6} + + \cvline{My One Line Entry}{My Details and some math $a=6^4 \frac{3}{5}$} + + \cvline{My One Line Entry}{My Details and some math $a=6^4 \frac{3}{5}$} + + + + +\end{document} \ No newline at end of file diff --git a/tests/auxiliary_files/test_generate_latex_file/sb2nov_empty/None_CV.tex b/tests/auxiliary_files/test_generate_latex_file/sb2nov_empty/None_CV.tex new file mode 100644 index 0000000..ec98ec0 --- /dev/null +++ b/tests/auxiliary_files/test_generate_latex_file/sb2nov_empty/None_CV.tex @@ -0,0 +1,141 @@ +%------------------------- +% Resume in Latex +% Author : Sourabh Bajaj +% License : MIT +%------------------------ + +\documentclass[10pt, letterpaper]{article} + +\usepackage[ + ignoreheadfoot, % set margins without considering header and footer + top=2 cm, % seperation between body and page edge from the top + bottom=2 cm, % seperation between body and page edge from the bottom + left=2 cm, % seperation between body and page edge from the left + right=2 cm, % seperation between body and page edge from the right + footskip=1.0 cm, % seperation between body and footer + % showframe % for debugging + ]{geometry} % for adjusting page geometry +\usepackage{latexsym} +\usepackage[nobottomtitles*]{titlesec} +\usepackage{marvosym} +\usepackage{verbatim} +\usepackage{setspace} +\usepackage{xcolor} +\usepackage{enumitem} +\usepackage[ + hidelinks, + pdftitle={None's CV}, + pdfauthor={None} +]{hyperref} +\usepackage{fancyhdr} +\usepackage[english]{babel} +\usepackage{tabularx} +\usepackage{ifthen} +\usepackage{fontawesome5} +\usepackage{calc} % for calculating lengths +\usepackage[pscoord]{eso-pic} % for floating text on the page +\usepackage{lastpage} % for getting the total number of pages +\input{glyphtounicode} + +\pagestyle{fancy} +\fancyhf{} % clear all header and footer fields +\fancyfoot[CO]{\color{gray}\textit{\small None - Page \thepage{} of \pageref*{LastPage}}} +\renewcommand{\headrulewidth}{0pt} +\renewcommand{\footrulewidth}{0pt} + +\definecolor{primaryColor}{RGB}{0, 79, 144} % define primary color + +\urlstyle{same} + +\setcounter{secnumdepth}{0} % no section numbering +\setlength{\parindent}{0pt} % no indentation +\setlength{\topskip}{0pt} % no top skip + +% \raggedbottom +\setlength{\tabcolsep}{0in} + +% Sections formatting +\titleformat{\section}{ + \scshape\raggedright\large +}{}{0em}{}[\color{black}\titlerule] + +% Ensure that generate pdf is machine readable/ATS parsable +\pdfgentounicode=1 + + +\newcolumntype{R}[1]{ + >{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1} +} % right-aligned fixed width column type + +\titlespacing{\section}{ + % left space: + 0pt + }{ + % top space: + 0.3 cm - 0.1cm + }{ + % bottom space: + 0.2 cm + } % section title spacing + +%------------------------- +% Custom commands +\newcommand{\placelastupdatedtext}{% \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>} + \AddToShipoutPictureFG*{% Add <stuff> to current page foreground + \put( + \LenToUnit{\paperwidth-2 cm-0.2 cm+0.05cm}, + \LenToUnit{\paperheight-1.0 cm} + ){\vtop{{\null}\makebox[0pt][c]{ + \small\color{gray}\textit{Last updated in January 2024}\hspace{\widthof{Last updated in January 2024}} + }}}% + }% +}% + +\newcommand{\resumeItem}[2]{ + \item\small{ + \ifthenelse{\equal{#1}{}}{#2}{\textbf{#1}{: #2}} + } +} + +\newcommand{\resumeSubheading}[4]{ + \item + \begin{tabularx}{0.98\textwidth-0.4 cm}[t]{X R{4.1 cm}} + \textbf{#1} & \textit{\small\ifthenelse{\equal{#2}{}}{#4}{#2}} \\ + \textit{\small#3} & \textit{\small\ifthenelse{\equal{#2}{}}{}{#4}} \\ + \end{tabularx} +} + +\newcommand{\resumeNormalSubheading}[2]{ + \item + \begin{tabularx}{0.98\textwidth-0.4 cm}[t]{X R{4.1 cm}} + \textbf{#1} & \textit{\small #2} + \end{tabularx} +} + +\newcommand{\resumeSubItem}[2]{\resumeItem{#1}{#2}} + +\renewcommand{\labelitemii}{$\circ$} + +\newcommand{\resumeSubHeadingListStart}{\begin{itemize}[left=0.2 cm, topsep=0pt, parsep=0.2 cm, partopsep=0pt, rightmargin=0.2 cm]} +\newcommand{\resumeSubHeadingListEnd}{\end{itemize}} +\newcommand{\resumeItemListStart}{\vspace{0.10 cm}\begin{itemize}[left=0.4 cm, topsep=-0.2 cm, itemsep=0.10 cm, partopsep=0pt, rightmargin=0cm]} +\newcommand{\resumeItemListEnd}{\end{itemize}} + +\begin{document} + \placelastupdatedtext + + + % save the original href command in a new command: + \let\hrefWithoutArrow\href + % new command for external links: + \renewcommand{\href}[2]{\hrefWithoutArrow{#1}{\color{primaryColor}\mbox{\ifthenelse{\equal{#2}{}}{}{#2 }\raisebox{.15ex}{\footnotesize \faExternalLink*}}}} + + \section{Test} + \resumeSubHeadingListStart + + \resumeSubItem{}{test} + + + \resumeSubHeadingListEnd + +\end{document} \ No newline at end of file diff --git a/tests/auxiliary_files/test_generate_latex_file/sb2nov_filled/John_Doe_CV.tex b/tests/auxiliary_files/test_generate_latex_file/sb2nov_filled/John_Doe_CV.tex new file mode 100644 index 0000000..4c4eecd --- /dev/null +++ b/tests/auxiliary_files/test_generate_latex_file/sb2nov_filled/John_Doe_CV.tex @@ -0,0 +1,248 @@ +%------------------------- +% Resume in Latex +% Author : Sourabh Bajaj +% License : MIT +%------------------------ + +\documentclass[10pt, letterpaper]{article} + +\usepackage[ + ignoreheadfoot, % set margins without considering header and footer + top=2 cm, % seperation between body and page edge from the top + bottom=2 cm, % seperation between body and page edge from the bottom + left=2 cm, % seperation between body and page edge from the left + right=2 cm, % seperation between body and page edge from the right + footskip=1.0 cm, % seperation between body and footer + % showframe % for debugging + ]{geometry} % for adjusting page geometry +\usepackage{latexsym} +\usepackage[nobottomtitles*]{titlesec} +\usepackage{marvosym} +\usepackage{verbatim} +\usepackage{setspace} +\usepackage{xcolor} +\usepackage{enumitem} +\usepackage[ + hidelinks, + pdftitle={John Doe's CV}, + pdfauthor={John Doe} +]{hyperref} +\usepackage{fancyhdr} +\usepackage[english]{babel} +\usepackage{tabularx} +\usepackage{ifthen} +\usepackage{fontawesome5} +\usepackage{calc} % for calculating lengths +\usepackage[pscoord]{eso-pic} % for floating text on the page +\usepackage{lastpage} % for getting the total number of pages +\input{glyphtounicode} + +\pagestyle{fancy} +\fancyhf{} % clear all header and footer fields +\fancyfoot[CO]{\color{gray}\textit{\small John Doe - Page \thepage{} of \pageref*{LastPage}}} +\renewcommand{\headrulewidth}{0pt} +\renewcommand{\footrulewidth}{0pt} + +\definecolor{primaryColor}{RGB}{0, 79, 144} % define primary color + +\urlstyle{same} + +\setcounter{secnumdepth}{0} % no section numbering +\setlength{\parindent}{0pt} % no indentation +\setlength{\topskip}{0pt} % no top skip + +% \raggedbottom +\setlength{\tabcolsep}{0in} + +% Sections formatting +\titleformat{\section}{ + \scshape\raggedright\large +}{}{0em}{}[\color{black}\titlerule] + +% Ensure that generate pdf is machine readable/ATS parsable +\pdfgentounicode=1 + + +\newcolumntype{R}[1]{ + >{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1} +} % right-aligned fixed width column type + +\titlespacing{\section}{ + % left space: + 0pt + }{ + % top space: + 0.3 cm - 0.1cm + }{ + % bottom space: + 0.2 cm + } % section title spacing + +%------------------------- +% Custom commands +\newcommand{\placelastupdatedtext}{% \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>} + \AddToShipoutPictureFG*{% Add <stuff> to current page foreground + \put( + \LenToUnit{\paperwidth-2 cm-0.2 cm+0.05cm}, + \LenToUnit{\paperheight-1.0 cm} + ){\vtop{{\null}\makebox[0pt][c]{ + \small\color{gray}\textit{Last updated in January 2024}\hspace{\widthof{Last updated in January 2024}} + }}}% + }% +}% + +\newcommand{\resumeItem}[2]{ + \item\small{ + \ifthenelse{\equal{#1}{}}{#2}{\textbf{#1}{: #2}} + } +} + +\newcommand{\resumeSubheading}[4]{ + \item + \begin{tabularx}{0.98\textwidth-0.4 cm}[t]{X R{4.1 cm}} + \textbf{#1} & \textit{\small\ifthenelse{\equal{#2}{}}{#4}{#2}} \\ + \textit{\small#3} & \textit{\small\ifthenelse{\equal{#2}{}}{}{#4}} \\ + \end{tabularx} +} + +\newcommand{\resumeNormalSubheading}[2]{ + \item + \begin{tabularx}{0.98\textwidth-0.4 cm}[t]{X R{4.1 cm}} + \textbf{#1} & \textit{\small #2} + \end{tabularx} +} + +\newcommand{\resumeSubItem}[2]{\resumeItem{#1}{#2}} + +\renewcommand{\labelitemii}{$\circ$} + +\newcommand{\resumeSubHeadingListStart}{\begin{itemize}[left=0.2 cm, topsep=0pt, parsep=0.2 cm, partopsep=0pt, rightmargin=0.2 cm]} +\newcommand{\resumeSubHeadingListEnd}{\end{itemize}} +\newcommand{\resumeItemListStart}{\vspace{0.10 cm}\begin{itemize}[left=0.4 cm, topsep=-0.2 cm, itemsep=0.10 cm, partopsep=0pt, rightmargin=0cm]} +\newcommand{\resumeItemListEnd}{\end{itemize}} + +\begin{document} + \placelastupdatedtext + + { + \centering + \textbf{\fontsize{24 pt}{24 pt}\selectfont + \href{https://orcid.org/0000-0000-0000-0000}{John Doe} + } \\ \vspace{3pt} + \small + + \vspace{0.3 cm} + + \begin{spacing}{1.6} + \mbox{\href{tel:+905419999999}{{\footnotesize\faPhone*}\hspace{4pt}+90 541 999 99 99}} + \hspace{0.5 cm} + \mbox{\href{mailto:johndoe@example.com}{{\small\faEnvelope[regular]}\hspace{4pt}johndoe@example.com}} + \hspace{0.5 cm} + \mbox{{\small\faMapMarker*}\hspace{4pt}Istanbul, Turkey} + \hspace{0.5 cm} + \mbox{\href{https://example.com/}{{\small\faLink}\hspace{4pt}example.com}} + \hspace{0.5 cm} + \mbox{\href{https://linkedin.com/in/johndoe}{{\small\faLinkedinIn}\hspace{4pt}johndoe}} + \hspace*{0.5 cm} + \mbox{\href{https://github.com/johndoe}{{\small\faGithub}\hspace{4pt}johndoe}} + \hspace*{0.5 cm} + \mbox{\href{https://instagram.com/johndoe}{{\small\faInstagram}\hspace{4pt}johndoe}} + \hspace*{0.5 cm} + \mbox{\href{https://mastodon.social/@johndoe@example}{{\small\faMastodon}\hspace{4pt}@johndoe@example}} + \hspace*{0.5 cm} + \end{spacing} + \par + } + + \vspace{0.3 cm} + + % save the original href command in a new command: + \let\hrefWithoutArrow\href + % new command for external links: + \renewcommand{\href}[2]{\hrefWithoutArrow{#1}{\color{primaryColor}\mbox{\ifthenelse{\equal{#2}{}}{}{#2 }\raisebox{.15ex}{\footnotesize \faExternalLink*}}}} + + \section{Section1} + \resumeSubHeadingListStart + + \resumeSubItem{}{My Text Entry} + + \resumeSubItem{}{My Text Entry} + + + \resumeSubHeadingListEnd + \section{Section2} + \resumeSubHeadingListStart + + \resumeSubheading + {My Title}{Dec. 2023} + {\href{https://doi.org/10.1109/TASC.2023.3340648}{10.1109/TASC.2023.3340648}}{} + \resumeItemListStart + \resumeItem{}{\raggedright \mbox{\textbf{\textit{J. Doe}}}, \mbox{\textbf{\textit{J. Doe}}} \par} + \resumeItemListEnd + + \resumeSubheading + {My Title}{Dec. 2023} + {\href{https://doi.org/10.1109/TASC.2023.3340648}{10.1109/TASC.2023.3340648}}{} + \resumeItemListStart + \resumeItem{}{\raggedright \mbox{\textbf{\textit{J. Doe}}}, \mbox{\textbf{\textit{J. Doe}}} \par} + \resumeItemListEnd + + + \resumeSubHeadingListEnd + \section{Section3} + \resumeSubHeadingListStart + + \resumeSubheading + {CERN}{} + {Researcher}{} + + + \resumeSubheading + {CERN}{} + {Researcher}{} + + + + \resumeSubHeadingListEnd + \section{Section4} + \resumeSubHeadingListStart + + \resumeSubheading + {Boğaziçi University}{} + {BS in Mechanical Engineering}{} + + + \resumeSubheading + {Boğaziçi University}{} + {BS in Mechanical Engineering}{} + + + + \resumeSubHeadingListEnd + \section{Section5} + \resumeSubHeadingListStart + + \resumeNormalSubheading + {My Entry}{} + + + \resumeNormalSubheading + {My Entry}{} + + + + \resumeSubHeadingListEnd + \section{Section6} + \resumeSubHeadingListStart + + \vspace{0.08cm} + \resumeSubItem{My One Line Entry} + {My Details and some math $a=6^4 \frac{3}{5}$} + + \resumeSubItem{My One Line Entry} + {My Details and some math $a=6^4 \frac{3}{5}$} + + + \resumeSubHeadingListEnd + +\end{document} \ No newline at end of file diff --git a/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/classic_empty/None_CV.tex b/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/classic_empty/None_CV.tex new file mode 100644 index 0000000..cdf6845 --- /dev/null +++ b/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/classic_empty/None_CV.tex @@ -0,0 +1,142 @@ +\documentclass[10pt, letterpaper]{article} + +% Packages: +\usepackage[ + ignoreheadfoot, % set margins without considering header and footer + top=2 cm, % seperation between body and page edge from the top + bottom=2 cm, % seperation between body and page edge from the bottom + left=2 cm, % seperation between body and page edge from the left + right=2 cm, % seperation between body and page edge from the right + footskip=1.0 cm, % seperation between body and footer + % showframe % for debugging + ]{geometry} % for adjusting page geometry +\usepackage[explicit]{titlesec} % for customizing section titles +\usepackage{tabularx} % for making tables with fixed width columns +\usepackage{array} % tabularx requires this +\usepackage[dvipsnames]{xcolor} % for coloring text +\definecolor{primaryColor}{RGB}{0, 79, 144} % define primary color +\usepackage{enumitem} % for customizing lists +\usepackage{fontawesome5} % for using icons +\usepackage{amsmath} % for math +\usepackage[ + pdftitle={None's CV}, + pdfauthor={None}, + colorlinks=true, + urlcolor=primaryColor +]{hyperref} % for links, metadata and bookmarks +\usepackage[pscoord]{eso-pic} % for floating text on the page +\usepackage{calc} % for calculating lengths +\usepackage{bookmark} % for bookmarks +\usepackage{lastpage} % for getting the total number of pages +\usepackage[default, type1]{sourcesanspro} % for using source sans 3 font +\usepackage{ifthen} + +% Some settings: +\pagestyle{empty} % no header or footer +\setcounter{secnumdepth}{0} % no section numbering +\setlength{\parindent}{0pt} % no indentation +\setlength{\topskip}{0pt} % no top skip +\makeatletter +\let\ps@customFooterStyle\ps@plain % Copy the plain style to customFooterStyle +\patchcmd{\ps@customFooterStyle}{\thepage}{ + \color{gray}\textit{\small None - Page \thepage{} of \pageref*{LastPage}} +}{}{} % replace number by desired string +\makeatother +\pagestyle{customFooterStyle} + +\titleformat{\section}{ + % make the font size of the section title large and color it with the primary color + \Large\color{primaryColor} + }{ + }{ + }{ + % print bold title, give 0.15 cm space and draw a line of 0.8 pt thickness + % from the end of the title to the end of the body + \textbf{#1}\hspace{0.15cm}\titlerule[0.8pt]\hspace{-0.1cm} + }[] % section title formatting + +\titlespacing{\section}{ + % left space: + 0pt + }{ + % top space: + 0.3 cm + }{ + % bottom space: + 0.2 cm + } % section title spacing + +\newcolumntype{L}[1]{ + >{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1} +} % left-aligned fixed width column type +\newcolumntype{R}[1]{ + >{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1} +} % right-aligned fixed width column type +\newcolumntype{K}[1]{ + >{\let\newline\\\arraybackslash\hspace{0pt}}X +} % justified flexible width column type +\setlength\tabcolsep{-1.5pt} % no space between columns +\newenvironment{highlights}{ + \begin{itemize}[ + topsep=0pt, + parsep=0.10 cm, + partopsep=0pt, + itemsep=0pt, + after=\vspace{-1\baselineskip}, + leftmargin=0.4 cm + 3pt + ] + }{ + \end{itemize} + } % new environment for highlights + +\newenvironment{header}{ + \setlength{\topsep}{0pt}\par\kern\topsep\centering\color{primaryColor}\linespread{1.5} + }{ + \par\kern\topsep + } % new environment for the header + +\newcommand{\placelastupdatedtext}{% \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>} + \AddToShipoutPictureFG*{% Add <stuff> to current page foreground + \put( + \LenToUnit{\paperwidth-2 cm-0.2 cm+0.05cm}, + \LenToUnit{\paperheight-1.0 cm} + ){\vtop{{\null}\makebox[0pt][c]{ + \small\color{gray}\textit{Last updated in January 2024}\hspace{\widthof{Last updated in January 2024}} + }}}% + }% +}% + +% save the original href command in a new command: +\let\hrefWithoutArrow\href + % new command for external links: +\renewcommand{\href}[2]{\hrefWithoutArrow{#1}{\mbox{\ifthenelse{\equal{#2}{}}{ }{#2 }\raisebox{.15ex}{\footnotesize \faExternalLink*}}}} + +\let\originalTabularx\tabularx +\let\originalEndTabularx\endtabularx + +\renewenvironment{tabularx}{\bgroup\centering\originalTabularx}{\originalEndTabularx\par\egroup} + +% For TextEntrys (see https://tex.stackexchange.com/a/600/287984): +\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1\topsep=0pt\itemsep=0pt\parsep=0pt\parskip=0pt\labelwidth=0pt\itemindent=0pt\labelsep=0pt}\item[]} +\let\endchangemargin=\endlist + +% Ensure that generate pdf is machine readable/ATS parsable +\pdfgentounicode=1 + +\begin{document} + \placelastupdatedtext + + + \section{Test} + + \begin{changemargin}{0.2 cm}{0.2 cm} + test + \end{changemargin} + + + + + + + +\end{document} \ No newline at end of file diff --git a/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/classic_filled/John_Doe_CV.tex b/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/classic_filled/John_Doe_CV.tex new file mode 100644 index 0000000..b336570 --- /dev/null +++ b/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/classic_filled/John_Doe_CV.tex @@ -0,0 +1,333 @@ +\documentclass[10pt, letterpaper]{article} + +% Packages: +\usepackage[ + ignoreheadfoot, % set margins without considering header and footer + top=2 cm, % seperation between body and page edge from the top + bottom=2 cm, % seperation between body and page edge from the bottom + left=2 cm, % seperation between body and page edge from the left + right=2 cm, % seperation between body and page edge from the right + footskip=1.0 cm, % seperation between body and footer + % showframe % for debugging + ]{geometry} % for adjusting page geometry +\usepackage[explicit]{titlesec} % for customizing section titles +\usepackage{tabularx} % for making tables with fixed width columns +\usepackage{array} % tabularx requires this +\usepackage[dvipsnames]{xcolor} % for coloring text +\definecolor{primaryColor}{RGB}{0, 79, 144} % define primary color +\usepackage{enumitem} % for customizing lists +\usepackage{fontawesome5} % for using icons +\usepackage{amsmath} % for math +\usepackage[ + pdftitle={John Doe's CV}, + pdfauthor={John Doe}, + colorlinks=true, + urlcolor=primaryColor +]{hyperref} % for links, metadata and bookmarks +\usepackage[pscoord]{eso-pic} % for floating text on the page +\usepackage{calc} % for calculating lengths +\usepackage{bookmark} % for bookmarks +\usepackage{lastpage} % for getting the total number of pages +\usepackage[default, type1]{sourcesanspro} % for using source sans 3 font +\usepackage{ifthen} + +% Some settings: +\pagestyle{empty} % no header or footer +\setcounter{secnumdepth}{0} % no section numbering +\setlength{\parindent}{0pt} % no indentation +\setlength{\topskip}{0pt} % no top skip +\makeatletter +\let\ps@customFooterStyle\ps@plain % Copy the plain style to customFooterStyle +\patchcmd{\ps@customFooterStyle}{\thepage}{ + \color{gray}\textit{\small John Doe - Page \thepage{} of \pageref*{LastPage}} +}{}{} % replace number by desired string +\makeatother +\pagestyle{customFooterStyle} + +\titleformat{\section}{ + % make the font size of the section title large and color it with the primary color + \Large\color{primaryColor} + }{ + }{ + }{ + % print bold title, give 0.15 cm space and draw a line of 0.8 pt thickness + % from the end of the title to the end of the body + \textbf{#1}\hspace{0.15cm}\titlerule[0.8pt]\hspace{-0.1cm} + }[] % section title formatting + +\titlespacing{\section}{ + % left space: + 0pt + }{ + % top space: + 0.3 cm + }{ + % bottom space: + 0.2 cm + } % section title spacing + +\newcolumntype{L}[1]{ + >{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1} +} % left-aligned fixed width column type +\newcolumntype{R}[1]{ + >{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1} +} % right-aligned fixed width column type +\newcolumntype{K}[1]{ + >{\let\newline\\\arraybackslash\hspace{0pt}}X +} % justified flexible width column type +\setlength\tabcolsep{-1.5pt} % no space between columns +\newenvironment{highlights}{ + \begin{itemize}[ + topsep=0pt, + parsep=0.10 cm, + partopsep=0pt, + itemsep=0pt, + after=\vspace{-1\baselineskip}, + leftmargin=0.4 cm + 3pt + ] + }{ + \end{itemize} + } % new environment for highlights + +\newenvironment{header}{ + \setlength{\topsep}{0pt}\par\kern\topsep\centering\color{primaryColor}\linespread{1.5} + }{ + \par\kern\topsep + } % new environment for the header + +\newcommand{\placelastupdatedtext}{% \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>} + \AddToShipoutPictureFG*{% Add <stuff> to current page foreground + \put( + \LenToUnit{\paperwidth-2 cm-0.2 cm+0.05cm}, + \LenToUnit{\paperheight-1.0 cm} + ){\vtop{{\null}\makebox[0pt][c]{ + \small\color{gray}\textit{Last updated in January 2024}\hspace{\widthof{Last updated in January 2024}} + }}}% + }% +}% + +% save the original href command in a new command: +\let\hrefWithoutArrow\href + % new command for external links: +\renewcommand{\href}[2]{\hrefWithoutArrow{#1}{\mbox{\ifthenelse{\equal{#2}{}}{ }{#2 }\raisebox{.15ex}{\footnotesize \faExternalLink*}}}} + +\let\originalTabularx\tabularx +\let\originalEndTabularx\endtabularx + +\renewenvironment{tabularx}{\bgroup\centering\originalTabularx}{\originalEndTabularx\par\egroup} + +% For TextEntrys (see https://tex.stackexchange.com/a/600/287984): +\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1\topsep=0pt\itemsep=0pt\parsep=0pt\parskip=0pt\labelwidth=0pt\itemindent=0pt\labelsep=0pt}\item[]} +\let\endchangemargin=\endlist + +% Ensure that generate pdf is machine readable/ATS parsable +\pdfgentounicode=1 + +\begin{document} + \placelastupdatedtext + \begin{header} + \fontsize{30 pt}{30 pt} + \hrefWithoutArrow{https://orcid.org/0000-0000-0000-0000}{\textbf{John Doe}} + + \vspace{0.3 cm} + + \normalsize + \mbox{\hrefWithoutArrow{tel:+905419999999}{{\footnotesize\faPhone*}\hspace*{0.13cm}+90 541 999 99 99}} + \hspace*{0.5 cm} + \mbox{\hrefWithoutArrow{mailto:johndoe@example.com}{{\small\faEnvelope[regular]}\hspace*{0.13cm}johndoe@example.com}} + \hspace*{0.5 cm} + \mbox{{\small\faMapMarker*}\hspace*{0.13cm}Istanbul, Turkey} + \hspace*{0.5 cm} + \mbox{\hrefWithoutArrow{https://example.com/}{{\small\faLink}\hspace*{0.13cm}example.com}} + \hspace*{0.5 cm} + \mbox{\hrefWithoutArrow{https://linkedin.com/in/johndoe}{{\small\faLinkedinIn}\hspace*{0.13cm}johndoe}} + \hspace*{0.5 cm} + \mbox{\hrefWithoutArrow{https://github.com/johndoe}{{\small\faGithub}\hspace*{0.13cm}johndoe}} + \hspace*{0.5 cm} + \mbox{\hrefWithoutArrow{https://instagram.com/johndoe}{{\small\faInstagram}\hspace*{0.13cm}johndoe}} + \hspace*{0.5 cm} + \mbox{\hrefWithoutArrow{https://mastodon.social/@johndoe@example}{{\small\faMastodon}\hspace*{0.13cm}@johndoe@example}} + \hspace*{0.5 cm} + \end{header} + + \vspace{0.3 cm} + + + \section{Section1} + + \begin{changemargin}{0.2 cm}{0.2 cm} + My Text Entry + \end{changemargin} + + + + + \vspace{0.2 cm} + \begin{changemargin}{0.2 cm}{0.2 cm} + My Text Entry + \end{changemargin} + + + + + + + \section{Section2} + + \begin{tabularx}{\textwidth-0.4 cm-0.13cm}{K{0.2 cm} R{4.1 cm}} + \textbf{My Title} + + \vspace{0.10 cm} + + \mbox{\textbf{\textit{J. Doe}}}, \mbox{\textbf{\textit{J. Doe}}} + + \vspace{0.10 cm} + + \href{https://doi.org/10.1109/TASC.2023.3340648}{10.1109/TASC.2023.3340648} () & + Dec. 2023 + \end{tabularx} + + \vspace{0.2 cm} + \begin{tabularx}{\textwidth-0.4 cm-0.13cm}{K{0.2 cm} R{4.1 cm}} + \textbf{My Title} + + \vspace{0.10 cm} + + \mbox{\textbf{\textit{J. Doe}}}, \mbox{\textbf{\textit{J. Doe}}} + + \vspace{0.10 cm} + + \href{https://doi.org/10.1109/TASC.2023.3340648}{10.1109/TASC.2023.3340648} () & + Dec. 2023 + \end{tabularx} + + + + \section{Section3} + + \begin{tabularx}{ + \textwidth-0.4 cm-0.13cm + }{ + K{0.2 cm} + R{4.1 cm} + } + \textbf{CERN}, Researcher + + \vspace{0.10 cm} + + & + + + + \end{tabularx} + + \vspace{0.2 cm} + \begin{tabularx}{ + \textwidth-0.4 cm-0.13cm + }{ + K{0.2 cm} + R{4.1 cm} + } + \textbf{CERN}, Researcher + + \vspace{0.10 cm} + + & + + + + \end{tabularx} + + + + \section{Section4} + + \begin{tabularx}{ + \textwidth-0.4 cm-0.13cm + }{ + L{0.85cm} + K{0.2 cm} + R{4.1 cm} + } + \textbf{BS} + & + \textbf{Boğaziçi University}, Mechanical Engineering + + \vspace{0.10 cm} + + & + + + + \end{tabularx} + + \vspace{0.2 cm} + \begin{tabularx}{ + \textwidth-0.4 cm-0.13cm + }{ + L{0.85cm} + K{0.2 cm} + R{4.1 cm} + } + \textbf{BS} + & + \textbf{Boğaziçi University}, Mechanical Engineering + + \vspace{0.10 cm} + + & + + + + \end{tabularx} + + + + \section{Section5} + + \begin{tabularx}{ + \textwidth-0.4 cm-0.13cm + }{ + K{0.2 cm} + } + \textbf{My Entry} + + \vspace{0.10 cm} + + \end{tabularx} + + + \vspace{0.2 cm} + \begin{tabularx}{ + \textwidth-0.4 cm-0.13cm + }{ + K{0.2 cm} + } + \textbf{My Entry} + + \vspace{0.10 cm} + + \end{tabularx} + + + + + \section{Section6} + + \begingroup\leftskip=0.2 cm + \advance\csname @rightskip\endcsname 0.2 cm + \advance\rightskip 0.2 cm + + \textbf{My One Line Entry:} My Details and some math $a=6^4 \frac{3}{5}$ \par\endgroup + + \vspace{0.2 cm} + \begingroup\leftskip=0.2 cm + \advance\csname @rightskip\endcsname 0.2 cm + \advance\rightskip 0.2 cm + + \textbf{My One Line Entry:} My Details and some math $a=6^4 \frac{3}{5}$ \par\endgroup + + + + +\end{document} \ No newline at end of file diff --git a/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/moderncv_empty/None_CV.tex b/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/moderncv_empty/None_CV.tex new file mode 100644 index 0000000..aa658df --- /dev/null +++ b/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/moderncv_empty/None_CV.tex @@ -0,0 +1,78 @@ +%% start of file `template.tex'. +%% Copyright 2006-2015 Xavier Danaux (xdanaux@gmail.com), 2020-2022 moderncv maintainers (github.com/moderncv). +% +% This work may be distributed and/or modified under the +% conditions of the LaTeX Project Public License version 1.3c, +% available at http://www.latex-project.org/lppl/. + +\documentclass[10pt,letterpaper,sans]{moderncv} % possible options include font size ('10pt', '11pt' and '12pt'), paper size ('a4paper', 'letterpaper', 'a5paper', 'legalpaper', 'executivepaper' and 'landscape') and font family ('sans' and 'roman') + +% moderncv themes +\moderncvstyle{classic} % style options are 'casual' (default), 'classic', 'banking', 'oldstyle' and 'fancy' +\moderncvcolor{blue} % color options 'black', 'blue' (default), 'burgundy', 'green', 'grey', 'orange', 'purple' and 'red' +%\renewcommand{\familydefault}{\sfdefault} % to set the default font; use '\sfdefault' for the default sans serif font, '\rmdefault' for the default roman one, or any tex font name + +\usepackage{amsmath} % for math + +% adjust the page margins +\usepackage[scale=0.75]{geometry} +\setlength{\hintscolumnwidth}{3.8 cm} % if you want to change the width of the column with the dates +%\setlength{\makecvheadnamewidth}{10cm} % for the 'classic' style, if you want to force the width allocated to your name and avoid line breaks. be careful though, the length is normally calculated to avoid any overlap with your personal info; use this at your own typographical risks... + +% font loading +% for luatex and xetex, do not use inputenc and fontenc +% see https://tex.stackexchange.com/a/496643 +\ifxetexorluatex + \usepackage{fontspec} + \usepackage{unicode-math} + \defaultfontfeatures{Ligatures=TeX} + \setmainfont{Latin Modern Roman} + \setsansfont{Latin Modern Sans} + \setmonofont{Latin Modern Mono} + \setmathfont{Latin Modern Math} +\else + \usepackage[T1]{fontenc} + \usepackage{lmodern} +\fi + +% document language +\usepackage[english]{babel} % FIXME: using spanish breaks moderncv + +% personal data +\name{None}{} +% \familyname{} + +% Social icons +% \social[linkedin]{john.doe} % optional, remove / comment the line if not wanted +% \social[xing]{john\_doe} % optional, remove / comment the line if not wanted +% \social[twitter]{ji\_doe} % optional, remove / comment the line if not wanted +% \social[github]{jdoe} % optional, remove / comment the line if not wanted +% \social[gitlab]{jdoe} % optional, remove / comment the line if not wanted +% \social[stackoverflow]{0000000/johndoe} % optional, remove / comment the line if not wanted +% \social[bitbucket]{jdoe} % optional, remove / comment the line if not wanted +% \social[skype]{jdoe} % optional, remove / comment the line if not wanted +% \social[orcid]{0000-0000-000-000} % optional, remove / comment the line if not wanted +% \social[researchgate]{jdoe} % optional, remove / comment the line if not wanted +% \social[researcherid]{jdoe} % optional, remove / comment the line if not wanted +% \social[telegram]{jdoe} % optional, remove / comment the line if not wanted +% \social[whatsapp]{12345678901} % optional, remove / comment the line if not wanted +% \social[signal]{12345678901} % optional, remove / comment the line if not wanted +% \social[matrix]{@johndoe:matrix.org} % optional, remove / comment the line if not wanted +% \social[googlescholar]{googlescholarid} % optional, remove / comment the line if not wanted + +\begin{document} + + + % save the original href command in a new command: + \let\hrefWithoutArrow\href + % new command for external links: + \renewcommand{\href}[2]{\hrefWithoutArrow{#1}{\mbox{\color{color1} #2 \raisebox{.15ex}{\footnotesize \faExternalLink*}}}} + + \section{Test} + + \cvlistitem{test} + + + + +\end{document} \ No newline at end of file diff --git a/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/moderncv_filled/John_Doe_CV.tex b/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/moderncv_filled/John_Doe_CV.tex new file mode 100644 index 0000000..b554fa3 --- /dev/null +++ b/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/moderncv_filled/John_Doe_CV.tex @@ -0,0 +1,137 @@ +%% start of file `template.tex'. +%% Copyright 2006-2015 Xavier Danaux (xdanaux@gmail.com), 2020-2022 moderncv maintainers (github.com/moderncv). +% +% This work may be distributed and/or modified under the +% conditions of the LaTeX Project Public License version 1.3c, +% available at http://www.latex-project.org/lppl/. + +\documentclass[10pt,letterpaper,sans]{moderncv} % possible options include font size ('10pt', '11pt' and '12pt'), paper size ('a4paper', 'letterpaper', 'a5paper', 'legalpaper', 'executivepaper' and 'landscape') and font family ('sans' and 'roman') + +% moderncv themes +\moderncvstyle{classic} % style options are 'casual' (default), 'classic', 'banking', 'oldstyle' and 'fancy' +\moderncvcolor{blue} % color options 'black', 'blue' (default), 'burgundy', 'green', 'grey', 'orange', 'purple' and 'red' +%\renewcommand{\familydefault}{\sfdefault} % to set the default font; use '\sfdefault' for the default sans serif font, '\rmdefault' for the default roman one, or any tex font name + +\usepackage{amsmath} % for math + +% adjust the page margins +\usepackage[scale=0.75]{geometry} +\setlength{\hintscolumnwidth}{3.8 cm} % if you want to change the width of the column with the dates +%\setlength{\makecvheadnamewidth}{10cm} % for the 'classic' style, if you want to force the width allocated to your name and avoid line breaks. be careful though, the length is normally calculated to avoid any overlap with your personal info; use this at your own typographical risks... + +% font loading +% for luatex and xetex, do not use inputenc and fontenc +% see https://tex.stackexchange.com/a/496643 +\ifxetexorluatex + \usepackage{fontspec} + \usepackage{unicode-math} + \defaultfontfeatures{Ligatures=TeX} + \setmainfont{Latin Modern Roman} + \setsansfont{Latin Modern Sans} + \setmonofont{Latin Modern Mono} + \setmathfont{Latin Modern Math} +\else + \usepackage[T1]{fontenc} + \usepackage{lmodern} +\fi + +% document language +\usepackage[english]{babel} % FIXME: using spanish breaks moderncv + +% personal data +\name{John Doe}{} +\title{Mechanical Engineer} % optional, remove / comment the line if not wanted +% \familyname{} +\address{Istanbul, Turkey}{} +\phone[mobile]{+90 541 999 99 99} +\email{johndoe@example.com} +\homepage{example.com} + +\social[linkedin]{johndoe} +\social[github]{johndoe} +\social[orcid]{0000-0000-0000-0000} +% Social icons +% \social[linkedin]{john.doe} % optional, remove / comment the line if not wanted +% \social[xing]{john\_doe} % optional, remove / comment the line if not wanted +% \social[twitter]{ji\_doe} % optional, remove / comment the line if not wanted +% \social[github]{jdoe} % optional, remove / comment the line if not wanted +% \social[gitlab]{jdoe} % optional, remove / comment the line if not wanted +% \social[stackoverflow]{0000000/johndoe} % optional, remove / comment the line if not wanted +% \social[bitbucket]{jdoe} % optional, remove / comment the line if not wanted +% \social[skype]{jdoe} % optional, remove / comment the line if not wanted +% \social[orcid]{0000-0000-000-000} % optional, remove / comment the line if not wanted +% \social[researchgate]{jdoe} % optional, remove / comment the line if not wanted +% \social[researcherid]{jdoe} % optional, remove / comment the line if not wanted +% \social[telegram]{jdoe} % optional, remove / comment the line if not wanted +% \social[whatsapp]{12345678901} % optional, remove / comment the line if not wanted +% \social[signal]{12345678901} % optional, remove / comment the line if not wanted +% \social[matrix]{@johndoe:matrix.org} % optional, remove / comment the line if not wanted +% \social[googlescholar]{googlescholarid} % optional, remove / comment the line if not wanted + +\begin{document} + \maketitle + + + % save the original href command in a new command: + \let\hrefWithoutArrow\href + % new command for external links: + \renewcommand{\href}[2]{\hrefWithoutArrow{#1}{\mbox{\color{color1} #2 \raisebox{.15ex}{\footnotesize \faExternalLink*}}}} + + \section{Section1} + + \cvlistitem{My Text Entry} + + \cvlistitem{My Text Entry} + + + + \section{Section2} + + \cventry{Dec. 2023}{My Title}{}{\href{https://doi.org/10.1109/TASC.2023.3340648}{10.1109/TASC.2023.3340648}}{}{} + \cvline{}{\small \mbox{\textbf{\textit{J. Doe}}}, \mbox{\textbf{\textit{J. Doe}}}} + + \cventry{Dec. 2023}{My Title}{}{\href{https://doi.org/10.1109/TASC.2023.3340648}{10.1109/TASC.2023.3340648}}{}{} + \cvline{}{\small \mbox{\textbf{\textit{J. Doe}}}, \mbox{\textbf{\textit{J. Doe}}}} + + + + \section{Section3} + + \cventry{}{Researcher}{CERN}{}{}{} + + + \cventry{}{Researcher}{CERN}{}{}{} + + + + + \section{Section4} + + \cventry{}{BS, Mechanical Engineering}{Boğaziçi University}{}{}{} + + + \cventry{}{BS, Mechanical Engineering}{Boğaziçi University}{}{}{} + + + + + \section{Section5} + + \cventry{}{My Entry}{}{}{}{} + + + \cventry{}{My Entry}{}{}{}{} + + + + + \section{Section6} + + \cvline{My One Line Entry}{My Details and some math $a=6^4 \frac{3}{5}$} + + \cvline{My One Line Entry}{My Details and some math $a=6^4 \frac{3}{5}$} + + + + +\end{document} \ No newline at end of file diff --git a/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/sb2nov_empty/LICENSE b/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/sb2nov_empty/LICENSE new file mode 100644 index 0000000..4d4f656 --- /dev/null +++ b/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/sb2nov_empty/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 Sourabh Bajaj + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/sb2nov_empty/None_CV.tex b/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/sb2nov_empty/None_CV.tex new file mode 100644 index 0000000..ec98ec0 --- /dev/null +++ b/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/sb2nov_empty/None_CV.tex @@ -0,0 +1,141 @@ +%------------------------- +% Resume in Latex +% Author : Sourabh Bajaj +% License : MIT +%------------------------ + +\documentclass[10pt, letterpaper]{article} + +\usepackage[ + ignoreheadfoot, % set margins without considering header and footer + top=2 cm, % seperation between body and page edge from the top + bottom=2 cm, % seperation between body and page edge from the bottom + left=2 cm, % seperation between body and page edge from the left + right=2 cm, % seperation between body and page edge from the right + footskip=1.0 cm, % seperation between body and footer + % showframe % for debugging + ]{geometry} % for adjusting page geometry +\usepackage{latexsym} +\usepackage[nobottomtitles*]{titlesec} +\usepackage{marvosym} +\usepackage{verbatim} +\usepackage{setspace} +\usepackage{xcolor} +\usepackage{enumitem} +\usepackage[ + hidelinks, + pdftitle={None's CV}, + pdfauthor={None} +]{hyperref} +\usepackage{fancyhdr} +\usepackage[english]{babel} +\usepackage{tabularx} +\usepackage{ifthen} +\usepackage{fontawesome5} +\usepackage{calc} % for calculating lengths +\usepackage[pscoord]{eso-pic} % for floating text on the page +\usepackage{lastpage} % for getting the total number of pages +\input{glyphtounicode} + +\pagestyle{fancy} +\fancyhf{} % clear all header and footer fields +\fancyfoot[CO]{\color{gray}\textit{\small None - Page \thepage{} of \pageref*{LastPage}}} +\renewcommand{\headrulewidth}{0pt} +\renewcommand{\footrulewidth}{0pt} + +\definecolor{primaryColor}{RGB}{0, 79, 144} % define primary color + +\urlstyle{same} + +\setcounter{secnumdepth}{0} % no section numbering +\setlength{\parindent}{0pt} % no indentation +\setlength{\topskip}{0pt} % no top skip + +% \raggedbottom +\setlength{\tabcolsep}{0in} + +% Sections formatting +\titleformat{\section}{ + \scshape\raggedright\large +}{}{0em}{}[\color{black}\titlerule] + +% Ensure that generate pdf is machine readable/ATS parsable +\pdfgentounicode=1 + + +\newcolumntype{R}[1]{ + >{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1} +} % right-aligned fixed width column type + +\titlespacing{\section}{ + % left space: + 0pt + }{ + % top space: + 0.3 cm - 0.1cm + }{ + % bottom space: + 0.2 cm + } % section title spacing + +%------------------------- +% Custom commands +\newcommand{\placelastupdatedtext}{% \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>} + \AddToShipoutPictureFG*{% Add <stuff> to current page foreground + \put( + \LenToUnit{\paperwidth-2 cm-0.2 cm+0.05cm}, + \LenToUnit{\paperheight-1.0 cm} + ){\vtop{{\null}\makebox[0pt][c]{ + \small\color{gray}\textit{Last updated in January 2024}\hspace{\widthof{Last updated in January 2024}} + }}}% + }% +}% + +\newcommand{\resumeItem}[2]{ + \item\small{ + \ifthenelse{\equal{#1}{}}{#2}{\textbf{#1}{: #2}} + } +} + +\newcommand{\resumeSubheading}[4]{ + \item + \begin{tabularx}{0.98\textwidth-0.4 cm}[t]{X R{4.1 cm}} + \textbf{#1} & \textit{\small\ifthenelse{\equal{#2}{}}{#4}{#2}} \\ + \textit{\small#3} & \textit{\small\ifthenelse{\equal{#2}{}}{}{#4}} \\ + \end{tabularx} +} + +\newcommand{\resumeNormalSubheading}[2]{ + \item + \begin{tabularx}{0.98\textwidth-0.4 cm}[t]{X R{4.1 cm}} + \textbf{#1} & \textit{\small #2} + \end{tabularx} +} + +\newcommand{\resumeSubItem}[2]{\resumeItem{#1}{#2}} + +\renewcommand{\labelitemii}{$\circ$} + +\newcommand{\resumeSubHeadingListStart}{\begin{itemize}[left=0.2 cm, topsep=0pt, parsep=0.2 cm, partopsep=0pt, rightmargin=0.2 cm]} +\newcommand{\resumeSubHeadingListEnd}{\end{itemize}} +\newcommand{\resumeItemListStart}{\vspace{0.10 cm}\begin{itemize}[left=0.4 cm, topsep=-0.2 cm, itemsep=0.10 cm, partopsep=0pt, rightmargin=0cm]} +\newcommand{\resumeItemListEnd}{\end{itemize}} + +\begin{document} + \placelastupdatedtext + + + % save the original href command in a new command: + \let\hrefWithoutArrow\href + % new command for external links: + \renewcommand{\href}[2]{\hrefWithoutArrow{#1}{\color{primaryColor}\mbox{\ifthenelse{\equal{#2}{}}{}{#2 }\raisebox{.15ex}{\footnotesize \faExternalLink*}}}} + + \section{Test} + \resumeSubHeadingListStart + + \resumeSubItem{}{test} + + + \resumeSubHeadingListEnd + +\end{document} \ No newline at end of file diff --git a/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/sb2nov_filled/John_Doe_CV.tex b/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/sb2nov_filled/John_Doe_CV.tex new file mode 100644 index 0000000..4c4eecd --- /dev/null +++ b/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/sb2nov_filled/John_Doe_CV.tex @@ -0,0 +1,248 @@ +%------------------------- +% Resume in Latex +% Author : Sourabh Bajaj +% License : MIT +%------------------------ + +\documentclass[10pt, letterpaper]{article} + +\usepackage[ + ignoreheadfoot, % set margins without considering header and footer + top=2 cm, % seperation between body and page edge from the top + bottom=2 cm, % seperation between body and page edge from the bottom + left=2 cm, % seperation between body and page edge from the left + right=2 cm, % seperation between body and page edge from the right + footskip=1.0 cm, % seperation between body and footer + % showframe % for debugging + ]{geometry} % for adjusting page geometry +\usepackage{latexsym} +\usepackage[nobottomtitles*]{titlesec} +\usepackage{marvosym} +\usepackage{verbatim} +\usepackage{setspace} +\usepackage{xcolor} +\usepackage{enumitem} +\usepackage[ + hidelinks, + pdftitle={John Doe's CV}, + pdfauthor={John Doe} +]{hyperref} +\usepackage{fancyhdr} +\usepackage[english]{babel} +\usepackage{tabularx} +\usepackage{ifthen} +\usepackage{fontawesome5} +\usepackage{calc} % for calculating lengths +\usepackage[pscoord]{eso-pic} % for floating text on the page +\usepackage{lastpage} % for getting the total number of pages +\input{glyphtounicode} + +\pagestyle{fancy} +\fancyhf{} % clear all header and footer fields +\fancyfoot[CO]{\color{gray}\textit{\small John Doe - Page \thepage{} of \pageref*{LastPage}}} +\renewcommand{\headrulewidth}{0pt} +\renewcommand{\footrulewidth}{0pt} + +\definecolor{primaryColor}{RGB}{0, 79, 144} % define primary color + +\urlstyle{same} + +\setcounter{secnumdepth}{0} % no section numbering +\setlength{\parindent}{0pt} % no indentation +\setlength{\topskip}{0pt} % no top skip + +% \raggedbottom +\setlength{\tabcolsep}{0in} + +% Sections formatting +\titleformat{\section}{ + \scshape\raggedright\large +}{}{0em}{}[\color{black}\titlerule] + +% Ensure that generate pdf is machine readable/ATS parsable +\pdfgentounicode=1 + + +\newcolumntype{R}[1]{ + >{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1} +} % right-aligned fixed width column type + +\titlespacing{\section}{ + % left space: + 0pt + }{ + % top space: + 0.3 cm - 0.1cm + }{ + % bottom space: + 0.2 cm + } % section title spacing + +%------------------------- +% Custom commands +\newcommand{\placelastupdatedtext}{% \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>} + \AddToShipoutPictureFG*{% Add <stuff> to current page foreground + \put( + \LenToUnit{\paperwidth-2 cm-0.2 cm+0.05cm}, + \LenToUnit{\paperheight-1.0 cm} + ){\vtop{{\null}\makebox[0pt][c]{ + \small\color{gray}\textit{Last updated in January 2024}\hspace{\widthof{Last updated in January 2024}} + }}}% + }% +}% + +\newcommand{\resumeItem}[2]{ + \item\small{ + \ifthenelse{\equal{#1}{}}{#2}{\textbf{#1}{: #2}} + } +} + +\newcommand{\resumeSubheading}[4]{ + \item + \begin{tabularx}{0.98\textwidth-0.4 cm}[t]{X R{4.1 cm}} + \textbf{#1} & \textit{\small\ifthenelse{\equal{#2}{}}{#4}{#2}} \\ + \textit{\small#3} & \textit{\small\ifthenelse{\equal{#2}{}}{}{#4}} \\ + \end{tabularx} +} + +\newcommand{\resumeNormalSubheading}[2]{ + \item + \begin{tabularx}{0.98\textwidth-0.4 cm}[t]{X R{4.1 cm}} + \textbf{#1} & \textit{\small #2} + \end{tabularx} +} + +\newcommand{\resumeSubItem}[2]{\resumeItem{#1}{#2}} + +\renewcommand{\labelitemii}{$\circ$} + +\newcommand{\resumeSubHeadingListStart}{\begin{itemize}[left=0.2 cm, topsep=0pt, parsep=0.2 cm, partopsep=0pt, rightmargin=0.2 cm]} +\newcommand{\resumeSubHeadingListEnd}{\end{itemize}} +\newcommand{\resumeItemListStart}{\vspace{0.10 cm}\begin{itemize}[left=0.4 cm, topsep=-0.2 cm, itemsep=0.10 cm, partopsep=0pt, rightmargin=0cm]} +\newcommand{\resumeItemListEnd}{\end{itemize}} + +\begin{document} + \placelastupdatedtext + + { + \centering + \textbf{\fontsize{24 pt}{24 pt}\selectfont + \href{https://orcid.org/0000-0000-0000-0000}{John Doe} + } \\ \vspace{3pt} + \small + + \vspace{0.3 cm} + + \begin{spacing}{1.6} + \mbox{\href{tel:+905419999999}{{\footnotesize\faPhone*}\hspace{4pt}+90 541 999 99 99}} + \hspace{0.5 cm} + \mbox{\href{mailto:johndoe@example.com}{{\small\faEnvelope[regular]}\hspace{4pt}johndoe@example.com}} + \hspace{0.5 cm} + \mbox{{\small\faMapMarker*}\hspace{4pt}Istanbul, Turkey} + \hspace{0.5 cm} + \mbox{\href{https://example.com/}{{\small\faLink}\hspace{4pt}example.com}} + \hspace{0.5 cm} + \mbox{\href{https://linkedin.com/in/johndoe}{{\small\faLinkedinIn}\hspace{4pt}johndoe}} + \hspace*{0.5 cm} + \mbox{\href{https://github.com/johndoe}{{\small\faGithub}\hspace{4pt}johndoe}} + \hspace*{0.5 cm} + \mbox{\href{https://instagram.com/johndoe}{{\small\faInstagram}\hspace{4pt}johndoe}} + \hspace*{0.5 cm} + \mbox{\href{https://mastodon.social/@johndoe@example}{{\small\faMastodon}\hspace{4pt}@johndoe@example}} + \hspace*{0.5 cm} + \end{spacing} + \par + } + + \vspace{0.3 cm} + + % save the original href command in a new command: + \let\hrefWithoutArrow\href + % new command for external links: + \renewcommand{\href}[2]{\hrefWithoutArrow{#1}{\color{primaryColor}\mbox{\ifthenelse{\equal{#2}{}}{}{#2 }\raisebox{.15ex}{\footnotesize \faExternalLink*}}}} + + \section{Section1} + \resumeSubHeadingListStart + + \resumeSubItem{}{My Text Entry} + + \resumeSubItem{}{My Text Entry} + + + \resumeSubHeadingListEnd + \section{Section2} + \resumeSubHeadingListStart + + \resumeSubheading + {My Title}{Dec. 2023} + {\href{https://doi.org/10.1109/TASC.2023.3340648}{10.1109/TASC.2023.3340648}}{} + \resumeItemListStart + \resumeItem{}{\raggedright \mbox{\textbf{\textit{J. Doe}}}, \mbox{\textbf{\textit{J. Doe}}} \par} + \resumeItemListEnd + + \resumeSubheading + {My Title}{Dec. 2023} + {\href{https://doi.org/10.1109/TASC.2023.3340648}{10.1109/TASC.2023.3340648}}{} + \resumeItemListStart + \resumeItem{}{\raggedright \mbox{\textbf{\textit{J. Doe}}}, \mbox{\textbf{\textit{J. Doe}}} \par} + \resumeItemListEnd + + + \resumeSubHeadingListEnd + \section{Section3} + \resumeSubHeadingListStart + + \resumeSubheading + {CERN}{} + {Researcher}{} + + + \resumeSubheading + {CERN}{} + {Researcher}{} + + + + \resumeSubHeadingListEnd + \section{Section4} + \resumeSubHeadingListStart + + \resumeSubheading + {Boğaziçi University}{} + {BS in Mechanical Engineering}{} + + + \resumeSubheading + {Boğaziçi University}{} + {BS in Mechanical Engineering}{} + + + + \resumeSubHeadingListEnd + \section{Section5} + \resumeSubHeadingListStart + + \resumeNormalSubheading + {My Entry}{} + + + \resumeNormalSubheading + {My Entry}{} + + + + \resumeSubHeadingListEnd + \section{Section6} + \resumeSubHeadingListStart + + \vspace{0.08cm} + \resumeSubItem{My One Line Entry} + {My Details and some math $a=6^4 \frac{3}{5}$} + + \resumeSubItem{My One Line Entry} + {My Details and some math $a=6^4 \frac{3}{5}$} + + + \resumeSubHeadingListEnd + +\end{document} \ No newline at end of file diff --git a/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/sb2nov_filled/LICENSE b/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/sb2nov_filled/LICENSE new file mode 100644 index 0000000..4d4f656 --- /dev/null +++ b/tests/auxiliary_files/test_generate_latex_file_and_copy_theme_files/sb2nov_filled/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 Sourabh Bajaj + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/tests/auxiliary_files/test_generate_markdown_file/classic_empty/None_CV.md b/tests/auxiliary_files/test_generate_markdown_file/classic_empty/None_CV.md new file mode 100644 index 0000000..49fbab0 --- /dev/null +++ b/tests/auxiliary_files/test_generate_markdown_file/classic_empty/None_CV.md @@ -0,0 +1,7 @@ +# None's CV + + + +# Test + +test diff --git a/tests/auxiliary_files/test_generate_markdown_file/classic_filled/John_Doe_CV.md b/tests/auxiliary_files/test_generate_markdown_file/classic_filled/John_Doe_CV.md new file mode 100644 index 0000000..7a7e9f0 --- /dev/null +++ b/tests/auxiliary_files/test_generate_markdown_file/classic_filled/John_Doe_CV.md @@ -0,0 +1,66 @@ +# John Doe's CV + +- Phone: +90 541 999 99 99 +- Email: [johndoe@example.com](mailto:johndoe@example.com) +- Location: Istanbul, Turkey +- Website: [example.com](https://example.com/) +- LinkedIn: [johndoe](https://linkedin.com/in/johndoe) +- GitHub: [johndoe](https://github.com/johndoe) +- Instagram: [johndoe](https://instagram.com/johndoe) +- Orcid: [0000-0000-0000-0000](https://orcid.org/0000-0000-0000-0000) +- Mastodon: [@johndoe@example](https://mastodon.social/@johndoe@example) +- Twitter: [johndoe](https://twitter.com/johndoe) + + +# Section1 + +My Text Entry +My Text Entry +# Section2 + +## My Title ([10.1109/TASC.2023.3340648](https://doi.org/10.1109/TASC.2023.3340648)) + +- Dec. 2023 +- J. Doe, J. Doe + +## My Title ([10.1109/TASC.2023.3340648](https://doi.org/10.1109/TASC.2023.3340648)) + +- Dec. 2023 +- J. Doe, J. Doe + +# Section3 + +## CERN, Researcher + + + + +## CERN, Researcher + + + + +# Section4 + +## Boğaziçi University, BS in Mechanical Engineering + + + + +## Boğaziçi University, BS in Mechanical Engineering + + + + +# Section5 + +## My Entry + + +## My Entry + + +# Section6 + +- My One Line Entry: My Details and some math $a=6^4 \frac{3}{5}$ +- My One Line Entry: My Details and some math $a=6^4 \frac{3}{5}$ diff --git a/tests/auxiliary_files/test_generate_markdown_file/moderncv_empty/None_CV.md b/tests/auxiliary_files/test_generate_markdown_file/moderncv_empty/None_CV.md new file mode 100644 index 0000000..49fbab0 --- /dev/null +++ b/tests/auxiliary_files/test_generate_markdown_file/moderncv_empty/None_CV.md @@ -0,0 +1,7 @@ +# None's CV + + + +# Test + +test diff --git a/tests/auxiliary_files/test_generate_markdown_file/moderncv_filled/John_Doe_CV.md b/tests/auxiliary_files/test_generate_markdown_file/moderncv_filled/John_Doe_CV.md new file mode 100644 index 0000000..7a7e9f0 --- /dev/null +++ b/tests/auxiliary_files/test_generate_markdown_file/moderncv_filled/John_Doe_CV.md @@ -0,0 +1,66 @@ +# John Doe's CV + +- Phone: +90 541 999 99 99 +- Email: [johndoe@example.com](mailto:johndoe@example.com) +- Location: Istanbul, Turkey +- Website: [example.com](https://example.com/) +- LinkedIn: [johndoe](https://linkedin.com/in/johndoe) +- GitHub: [johndoe](https://github.com/johndoe) +- Instagram: [johndoe](https://instagram.com/johndoe) +- Orcid: [0000-0000-0000-0000](https://orcid.org/0000-0000-0000-0000) +- Mastodon: [@johndoe@example](https://mastodon.social/@johndoe@example) +- Twitter: [johndoe](https://twitter.com/johndoe) + + +# Section1 + +My Text Entry +My Text Entry +# Section2 + +## My Title ([10.1109/TASC.2023.3340648](https://doi.org/10.1109/TASC.2023.3340648)) + +- Dec. 2023 +- J. Doe, J. Doe + +## My Title ([10.1109/TASC.2023.3340648](https://doi.org/10.1109/TASC.2023.3340648)) + +- Dec. 2023 +- J. Doe, J. Doe + +# Section3 + +## CERN, Researcher + + + + +## CERN, Researcher + + + + +# Section4 + +## Boğaziçi University, BS in Mechanical Engineering + + + + +## Boğaziçi University, BS in Mechanical Engineering + + + + +# Section5 + +## My Entry + + +## My Entry + + +# Section6 + +- My One Line Entry: My Details and some math $a=6^4 \frac{3}{5}$ +- My One Line Entry: My Details and some math $a=6^4 \frac{3}{5}$ diff --git a/tests/auxiliary_files/test_generate_markdown_file/sb2nov_empty/None_CV.md b/tests/auxiliary_files/test_generate_markdown_file/sb2nov_empty/None_CV.md new file mode 100644 index 0000000..49fbab0 --- /dev/null +++ b/tests/auxiliary_files/test_generate_markdown_file/sb2nov_empty/None_CV.md @@ -0,0 +1,7 @@ +# None's CV + + + +# Test + +test diff --git a/tests/auxiliary_files/test_generate_markdown_file/sb2nov_filled/John_Doe_CV.md b/tests/auxiliary_files/test_generate_markdown_file/sb2nov_filled/John_Doe_CV.md new file mode 100644 index 0000000..7a7e9f0 --- /dev/null +++ b/tests/auxiliary_files/test_generate_markdown_file/sb2nov_filled/John_Doe_CV.md @@ -0,0 +1,66 @@ +# John Doe's CV + +- Phone: +90 541 999 99 99 +- Email: [johndoe@example.com](mailto:johndoe@example.com) +- Location: Istanbul, Turkey +- Website: [example.com](https://example.com/) +- LinkedIn: [johndoe](https://linkedin.com/in/johndoe) +- GitHub: [johndoe](https://github.com/johndoe) +- Instagram: [johndoe](https://instagram.com/johndoe) +- Orcid: [0000-0000-0000-0000](https://orcid.org/0000-0000-0000-0000) +- Mastodon: [@johndoe@example](https://mastodon.social/@johndoe@example) +- Twitter: [johndoe](https://twitter.com/johndoe) + + +# Section1 + +My Text Entry +My Text Entry +# Section2 + +## My Title ([10.1109/TASC.2023.3340648](https://doi.org/10.1109/TASC.2023.3340648)) + +- Dec. 2023 +- J. Doe, J. Doe + +## My Title ([10.1109/TASC.2023.3340648](https://doi.org/10.1109/TASC.2023.3340648)) + +- Dec. 2023 +- J. Doe, J. Doe + +# Section3 + +## CERN, Researcher + + + + +## CERN, Researcher + + + + +# Section4 + +## Boğaziçi University, BS in Mechanical Engineering + + + + +## Boğaziçi University, BS in Mechanical Engineering + + + + +# Section5 + +## My Entry + + +## My Entry + + +# Section6 + +- My One Line Entry: My Details and some math $a=6^4 \frac{3}{5}$ +- My One Line Entry: My Details and some math $a=6^4 \frac{3}{5}$ diff --git a/tests/auxiliary_files/test_latex_to_pdf/classic_empty/None_CV.pdf b/tests/auxiliary_files/test_latex_to_pdf/classic_empty/None_CV.pdf new file mode 100644 index 0000000..5f19446 Binary files /dev/null and b/tests/auxiliary_files/test_latex_to_pdf/classic_empty/None_CV.pdf differ diff --git a/tests/auxiliary_files/test_latex_to_pdf/classic_filled/John_Doe_CV.pdf b/tests/auxiliary_files/test_latex_to_pdf/classic_filled/John_Doe_CV.pdf new file mode 100644 index 0000000..c2c8e51 Binary files /dev/null and b/tests/auxiliary_files/test_latex_to_pdf/classic_filled/John_Doe_CV.pdf differ diff --git a/tests/auxiliary_files/test_latex_to_pdf/moderncv_empty/None_CV.pdf b/tests/auxiliary_files/test_latex_to_pdf/moderncv_empty/None_CV.pdf new file mode 100644 index 0000000..fb72e06 Binary files /dev/null and b/tests/auxiliary_files/test_latex_to_pdf/moderncv_empty/None_CV.pdf differ diff --git a/tests/auxiliary_files/test_latex_to_pdf/moderncv_filled/John_Doe_CV.pdf b/tests/auxiliary_files/test_latex_to_pdf/moderncv_filled/John_Doe_CV.pdf new file mode 100644 index 0000000..6534058 Binary files /dev/null and b/tests/auxiliary_files/test_latex_to_pdf/moderncv_filled/John_Doe_CV.pdf differ diff --git a/tests/auxiliary_files/test_latex_to_pdf/sb2nov_empty/None_CV.pdf b/tests/auxiliary_files/test_latex_to_pdf/sb2nov_empty/None_CV.pdf new file mode 100644 index 0000000..8971179 Binary files /dev/null and b/tests/auxiliary_files/test_latex_to_pdf/sb2nov_empty/None_CV.pdf differ diff --git a/tests/auxiliary_files/test_latex_to_pdf/sb2nov_filled/John_Doe_CV.pdf b/tests/auxiliary_files/test_latex_to_pdf/sb2nov_filled/John_Doe_CV.pdf new file mode 100644 index 0000000..90312a9 Binary files /dev/null and b/tests/auxiliary_files/test_latex_to_pdf/sb2nov_filled/John_Doe_CV.pdf differ diff --git a/tests/auxiliary_files/test_markdown_to_html/classic_empty/None_CV_PASTETOGRAMMARLY.html b/tests/auxiliary_files/test_markdown_to_html/classic_empty/None_CV_PASTETOGRAMMARLY.html new file mode 100644 index 0000000..f966c13 --- /dev/null +++ b/tests/auxiliary_files/test_markdown_to_html/classic_empty/None_CV_PASTETOGRAMMARLY.html @@ -0,0 +1,3 @@ +<h1>None's CV</h1> +<h1>Test</h1> +<p>test</p> \ No newline at end of file diff --git a/tests/auxiliary_files/test_markdown_to_html/classic_filled/John_Doe_CV_PASTETOGRAMMARLY.html b/tests/auxiliary_files/test_markdown_to_html/classic_filled/John_Doe_CV_PASTETOGRAMMARLY.html new file mode 100644 index 0000000..80d0779 --- /dev/null +++ b/tests/auxiliary_files/test_markdown_to_html/classic_filled/John_Doe_CV_PASTETOGRAMMARLY.html @@ -0,0 +1,41 @@ +<h1>John Doe's CV</h1> +<ul> +<li>Phone: +90 541 999 99 99</li> +<li>Email: <a href="mailto:johndoe@example.com">johndoe@example.com</a></li> +<li>Location: Istanbul, Turkey</li> +<li>Website: <a href="https://example.com/">example.com</a></li> +<li>LinkedIn: <a href="https://linkedin.com/in/johndoe">johndoe</a></li> +<li>GitHub: <a href="https://github.com/johndoe">johndoe</a></li> +<li>Instagram: <a href="https://instagram.com/johndoe">johndoe</a></li> +<li>Orcid: <a href="https://orcid.org/0000-0000-0000-0000">0000-0000-0000-0000</a></li> +<li>Mastodon: <a href="https://mastodon.social/@johndoe@example">@johndoe@example</a></li> +<li>Twitter: <a href="https://twitter.com/johndoe">johndoe</a></li> +</ul> +<h1>Section1</h1> +<p>My Text Entry +My Text Entry</p> +<h1>Section2</h1> +<h2>My Title (<a href="https://doi.org/10.1109/TASC.2023.3340648">10.1109/TASC.2023.3340648</a>)</h2> +<ul> +<li>Dec. 2023</li> +<li>J. Doe, J. Doe</li> +</ul> +<h2>My Title (<a href="https://doi.org/10.1109/TASC.2023.3340648">10.1109/TASC.2023.3340648</a>)</h2> +<ul> +<li>Dec. 2023</li> +<li>J. Doe, J. Doe</li> +</ul> +<h1>Section3</h1> +<h2>CERN, Researcher</h2> +<h2>CERN, Researcher</h2> +<h1>Section4</h1> +<h2>Boğaziçi University, BS in Mechanical Engineering</h2> +<h2>Boğaziçi University, BS in Mechanical Engineering</h2> +<h1>Section5</h1> +<h2>My Entry</h2> +<h2>My Entry</h2> +<h1>Section6</h1> +<ul> +<li>My One Line Entry: My Details and some math $a=6^4 \frac{3}{5}$</li> +<li>My One Line Entry: My Details and some math $a=6^4 \frac{3}{5}$</li> +</ul> \ No newline at end of file diff --git a/tests/auxiliary_files/test_markdown_to_html/moderncv_empty/None_CV_PASTETOGRAMMARLY.html b/tests/auxiliary_files/test_markdown_to_html/moderncv_empty/None_CV_PASTETOGRAMMARLY.html new file mode 100644 index 0000000..f966c13 --- /dev/null +++ b/tests/auxiliary_files/test_markdown_to_html/moderncv_empty/None_CV_PASTETOGRAMMARLY.html @@ -0,0 +1,3 @@ +<h1>None's CV</h1> +<h1>Test</h1> +<p>test</p> \ No newline at end of file diff --git a/tests/auxiliary_files/test_markdown_to_html/moderncv_filled/John_Doe_CV_PASTETOGRAMMARLY.html b/tests/auxiliary_files/test_markdown_to_html/moderncv_filled/John_Doe_CV_PASTETOGRAMMARLY.html new file mode 100644 index 0000000..80d0779 --- /dev/null +++ b/tests/auxiliary_files/test_markdown_to_html/moderncv_filled/John_Doe_CV_PASTETOGRAMMARLY.html @@ -0,0 +1,41 @@ +<h1>John Doe's CV</h1> +<ul> +<li>Phone: +90 541 999 99 99</li> +<li>Email: <a href="mailto:johndoe@example.com">johndoe@example.com</a></li> +<li>Location: Istanbul, Turkey</li> +<li>Website: <a href="https://example.com/">example.com</a></li> +<li>LinkedIn: <a href="https://linkedin.com/in/johndoe">johndoe</a></li> +<li>GitHub: <a href="https://github.com/johndoe">johndoe</a></li> +<li>Instagram: <a href="https://instagram.com/johndoe">johndoe</a></li> +<li>Orcid: <a href="https://orcid.org/0000-0000-0000-0000">0000-0000-0000-0000</a></li> +<li>Mastodon: <a href="https://mastodon.social/@johndoe@example">@johndoe@example</a></li> +<li>Twitter: <a href="https://twitter.com/johndoe">johndoe</a></li> +</ul> +<h1>Section1</h1> +<p>My Text Entry +My Text Entry</p> +<h1>Section2</h1> +<h2>My Title (<a href="https://doi.org/10.1109/TASC.2023.3340648">10.1109/TASC.2023.3340648</a>)</h2> +<ul> +<li>Dec. 2023</li> +<li>J. Doe, J. Doe</li> +</ul> +<h2>My Title (<a href="https://doi.org/10.1109/TASC.2023.3340648">10.1109/TASC.2023.3340648</a>)</h2> +<ul> +<li>Dec. 2023</li> +<li>J. Doe, J. Doe</li> +</ul> +<h1>Section3</h1> +<h2>CERN, Researcher</h2> +<h2>CERN, Researcher</h2> +<h1>Section4</h1> +<h2>Boğaziçi University, BS in Mechanical Engineering</h2> +<h2>Boğaziçi University, BS in Mechanical Engineering</h2> +<h1>Section5</h1> +<h2>My Entry</h2> +<h2>My Entry</h2> +<h1>Section6</h1> +<ul> +<li>My One Line Entry: My Details and some math $a=6^4 \frac{3}{5}$</li> +<li>My One Line Entry: My Details and some math $a=6^4 \frac{3}{5}$</li> +</ul> \ No newline at end of file diff --git a/tests/auxiliary_files/test_markdown_to_html/sb2nov_empty/None_CV_PASTETOGRAMMARLY.html b/tests/auxiliary_files/test_markdown_to_html/sb2nov_empty/None_CV_PASTETOGRAMMARLY.html new file mode 100644 index 0000000..f966c13 --- /dev/null +++ b/tests/auxiliary_files/test_markdown_to_html/sb2nov_empty/None_CV_PASTETOGRAMMARLY.html @@ -0,0 +1,3 @@ +<h1>None's CV</h1> +<h1>Test</h1> +<p>test</p> \ No newline at end of file diff --git a/tests/auxiliary_files/test_markdown_to_html/sb2nov_filled/John_Doe_CV_PASTETOGRAMMARLY.html b/tests/auxiliary_files/test_markdown_to_html/sb2nov_filled/John_Doe_CV_PASTETOGRAMMARLY.html new file mode 100644 index 0000000..80d0779 --- /dev/null +++ b/tests/auxiliary_files/test_markdown_to_html/sb2nov_filled/John_Doe_CV_PASTETOGRAMMARLY.html @@ -0,0 +1,41 @@ +<h1>John Doe's CV</h1> +<ul> +<li>Phone: +90 541 999 99 99</li> +<li>Email: <a href="mailto:johndoe@example.com">johndoe@example.com</a></li> +<li>Location: Istanbul, Turkey</li> +<li>Website: <a href="https://example.com/">example.com</a></li> +<li>LinkedIn: <a href="https://linkedin.com/in/johndoe">johndoe</a></li> +<li>GitHub: <a href="https://github.com/johndoe">johndoe</a></li> +<li>Instagram: <a href="https://instagram.com/johndoe">johndoe</a></li> +<li>Orcid: <a href="https://orcid.org/0000-0000-0000-0000">0000-0000-0000-0000</a></li> +<li>Mastodon: <a href="https://mastodon.social/@johndoe@example">@johndoe@example</a></li> +<li>Twitter: <a href="https://twitter.com/johndoe">johndoe</a></li> +</ul> +<h1>Section1</h1> +<p>My Text Entry +My Text Entry</p> +<h1>Section2</h1> +<h2>My Title (<a href="https://doi.org/10.1109/TASC.2023.3340648">10.1109/TASC.2023.3340648</a>)</h2> +<ul> +<li>Dec. 2023</li> +<li>J. Doe, J. Doe</li> +</ul> +<h2>My Title (<a href="https://doi.org/10.1109/TASC.2023.3340648">10.1109/TASC.2023.3340648</a>)</h2> +<ul> +<li>Dec. 2023</li> +<li>J. Doe, J. Doe</li> +</ul> +<h1>Section3</h1> +<h2>CERN, Researcher</h2> +<h2>CERN, Researcher</h2> +<h1>Section4</h1> +<h2>Boğaziçi University, BS in Mechanical Engineering</h2> +<h2>Boğaziçi University, BS in Mechanical Engineering</h2> +<h1>Section5</h1> +<h2>My Entry</h2> +<h2>My Entry</h2> +<h1>Section6</h1> +<ul> +<li>My One Line Entry: My Details and some math $a=6^4 \frac{3}{5}$</li> +<li>My One Line Entry: My Details and some math $a=6^4 \frac{3}{5}$</li> +</ul> \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..6840326 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,149 @@ +import pathlib + +import jinja2 +import pytest + +from rendercv import data_models as dm +import rendercv.renderer as r + +update_auxiliary_files = False + +folder_name_dictionary = { + "rendercv_empty_curriculum_vitae_data_model": "empty", + "rendercv_filled_curriculum_vitae_data_model": "filled", +} + + +@pytest.fixture +def publication_entry() -> dict[str, str | list[str]]: + return { + "title": "My Title", + "authors": ["John Doe", "Jane Doe"], + "doi": "10.1109/TASC.2023.3340648", + "date": "2023-12-08", + } + + +@pytest.fixture +def experience_entry() -> dict[str, str]: + return { + "company": "CERN", + "position": "Researcher", + } + + +@pytest.fixture +def education_entry() -> dict[str, str]: + return { + "institution": "Boğaziçi University", + "area": "Mechanical Engineering", + "degree": "BS", + } + + +@pytest.fixture +def normal_entry() -> dict[str, str]: + return { + "name": "My Entry", + } + + +@pytest.fixture +def one_line_entry() -> dict[str, str]: + return { + "name": "My One Line Entry", + "details": "My Details and some math $a=6^4 \\frac{3}{5}$", + } + + +@pytest.fixture +def text_entry() -> str: + return "My Text Entry" + + +@pytest.fixture +def rendercv_data_model() -> dm.RenderCVDataModel: + return dm.get_a_sample_data_model() + + +@pytest.fixture +def rendercv_empty_curriculum_vitae_data_model() -> dm.CurriculumVitae: + return dm.CurriculumVitae(sections={"test": ["test"]}) + + +@pytest.fixture +def rendercv_filled_curriculum_vitae_data_model( + text_entry, + publication_entry, + experience_entry, + education_entry, + normal_entry, + one_line_entry, +) -> dm.CurriculumVitae: + return dm.CurriculumVitae( + name="John Doe", + label="Mechanical Engineer", + location="Istanbul, Turkey", + email="johndoe@example.com", + phone="+905419999999", # type: ignore + website="https://example.com", # type: ignore + social_networks=[ + dm.SocialNetwork(network="LinkedIn", username="johndoe"), + dm.SocialNetwork(network="GitHub", username="johndoe"), + dm.SocialNetwork(network="Instagram", username="johndoe"), + dm.SocialNetwork(network="Orcid", username="0000-0000-0000-0000"), + dm.SocialNetwork(network="Mastodon", username="@johndoe@example"), + dm.SocialNetwork(network="Twitter", username="johndoe"), + ], + sections={ + "section1": [ + text_entry, + text_entry, + ], + "section2": [ + publication_entry, + publication_entry, + ], + "section3": [ + experience_entry, + experience_entry, + ], + "section4": [ + education_entry, + education_entry, + ], + "section5": [ + normal_entry, + normal_entry, + ], + "section6": [ + one_line_entry, + one_line_entry, + ], + }, + ) + + +@pytest.fixture +def jinja2_environment() -> jinja2.Environment: + return r.setup_jinja2_environment() + + +@pytest.fixture +def tests_directory_path() -> pathlib.Path: + return pathlib.Path(__file__).parent + + +@pytest.fixture +def root_directory_path(tests_directory_path) -> pathlib.Path: + return tests_directory_path.parent + + +@pytest.fixture +def auxiliary_files_directory_path(tests_directory_path) -> pathlib.Path: + return tests_directory_path / "auxiliary_files" + + +@pytest.fixture +def input_file_path(auxiliary_files_directory_path) -> pathlib.Path: + return auxiliary_files_directory_path / "John_Doe_CV.yaml" diff --git a/tests/reference_files/John_Doe_CV_pdf_reference.pdf b/tests/reference_files/John_Doe_CV_pdf_reference.pdf deleted file mode 100644 index fb6425f..0000000 Binary files a/tests/reference_files/John_Doe_CV_pdf_reference.pdf and /dev/null differ diff --git a/tests/reference_files/John_Doe_CV_tex_reference.tex b/tests/reference_files/John_Doe_CV_tex_reference.tex deleted file mode 100644 index 3d70384..0000000 --- a/tests/reference_files/John_Doe_CV_tex_reference.tex +++ /dev/null @@ -1,439 +0,0 @@ - -\documentclass[10pt, a4paper]{article} - -% Packages: -\usepackage[ - ignoreheadfoot, % set margins without considering header and footer - top=2 cm, % seperation between body and page edge from the top - bottom=2 cm, % seperation between body and page edge from the bottom - left=1.24 cm, % seperation between body and page edge from the left - right=1.24 cm, % seperation between body and page edge from the right - footskip=1.0 cm, % seperation between body and footer - % showframe % for debugging - ]{geometry} % for adjusting page geometry -\usepackage{fontspec} % for loading fonts -\usepackage[explicit]{titlesec} % for customizing section titles -\usepackage{tabularx} % for making tables with fixed width columns -\usepackage{array} % tabularx requires this -\usepackage[dvipsnames]{xcolor} % for coloring text -\definecolor{primaryColor}{RGB}{0, 79, 144} % define primary color -\usepackage{enumitem} % for customizing lists -\usepackage{fontawesome5} % for using icons -\usepackage[ - pdftitle={John Doe's CV}, - pdfauthor={John Doe}, - colorlinks=true, - urlcolor=primaryColor -]{hyperref} % for links, metadata and bookmarks -\usepackage[pscoord]{eso-pic} % for floating text on the page -\usepackage{calc} % for calculating lengths -\usepackage{bookmark} % for bookmarks -\usepackage{lastpage} % for getting the total number of pages - -% Some settings: -\pagestyle{empty} % no header or footer -\setcounter{secnumdepth}{0} % no section numbering -\setlength{\parindent}{0pt} % no indentation -\setlength{\topskip}{0pt} % no top skip -\makeatletter -\let\ps@customFooterStyle\ps@plain % Copy the plain style to customFooterStyle -\patchcmd{\ps@customFooterStyle}{\thepage}{ - \color{gray}\textit{\small John Doe | Page \thepage{} of \pageref*{LastPage}} -}{}{} % replace number by desired string -\makeatother -\pagestyle{customFooterStyle} - -\setmainfont{SourceSans3}[ - Path= fonts/, - Extension = .ttf, - UprightFont = *-Regular, - ItalicFont = *-Italic, - BoldFont = *-Bold, - BoldItalicFont = *-BoldItalic -] - -\titleformat{\section}{ - % make the font size of the section title large and color it with the primary color - \Large\color{primaryColor} - }{ - }{ - }{ - % print bold title, give 0.15 cm space and draw a line of 0.8 pt thickness - % from the end of the title to the end of the body - \textbf{#1}\hspace{0.15cm}\titlerule[0.8pt]\hspace{-0.1cm} - }[] % section title formatting - -\titlespacing{\section}{ - % left space: - 0pt - }{ - % top space: - 0.2 cm - }{ - % bottom space: - 0.2 cm - } % section title spacing - -\newcolumntype{L}[1]{ - >{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1} -} % left-aligned fixed width column type -\newcolumntype{R}[1]{ - >{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1} -} % right-aligned fixed width column type -\newcolumntype{K}[1]{ - >{\let\newline\\\arraybackslash\hspace{0pt}}X -} % justified flexible width column type -\setlength\tabcolsep{-1.5pt} % no space between columns -\newenvironment{highlights}{ - \begin{itemize}[ - topsep=0pt, - parsep=0.10 cm, - partopsep=0pt, - itemsep=0pt, - after=\vspace{-1\baselineskip}, - leftmargin=0.4 cm + 3pt - ] - }{ - \end{itemize} - } % new environment for highlights - -\newenvironment{header}{ - \setlength{\topsep}{0pt}\par\kern\topsep\centering\color{primaryColor}\linespread{1.5} - }{ - \par\kern\topsep - } % new environment for the header - -\newcommand{\placelastupdatedtext}{% \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>} - \AddToShipoutPictureFG*{% Add <stuff> to current page foreground - \put( - \LenToUnit{\paperwidth-1.24 cm-0.2 cm+0.05cm}, - \LenToUnit{\paperheight-1.0 cm} - ){\vtop{{\null}\makebox[0pt][c]{ - \small\color{gray}\textit{Last updated in January 2024}\hspace{\widthof{Last updated in January 2024}} - }}}% - }% -}% - -% save the original href command in a new command: -\let\hrefWithoutArrow\href - % new command for external links: -\renewcommand{\href}[2]{\hrefWithoutArrow{#1}{#2 \raisebox{.15ex}{\footnotesize \faExternalLink*}}} - -\begin{document} - \placelastupdatedtext - - \begin{header} - \fontsize{30 pt}{30 pt} - \textbf{John Doe} - - \vspace{0.2 cm} - - \normalsize - \mbox{{\small\faMapMarker*}\hspace{0.13cm}TX, USA} - \hspace{0.5cm} - \mbox{\hrefWithoutArrow{tel:+33749882538}{{\footnotesize\faPhone*}\hspace{0.13cm}+33 7 49 88 25 38}} - \hspace{0.5cm} - \mbox{\hrefWithoutArrow{mailto:johndoe@example.com}{{\small\faEnvelope[regular]}\hspace{0.13cm}johndoe@example.com}} - \hspace{0.5cm} - \mbox{\hrefWithoutArrow{https://example.com/}{{\small\faLink}\hspace{0.13cm}example.com}} - \hspace{0.5cm} - \mbox{\hrefWithoutArrow{https://www.github.com/johndoe}{{\small\faGithub}\hspace{0.13cm}johndoe}} - \hspace{0.5cm} - \mbox{\hrefWithoutArrow{https://www.linkedin.com/in/johndoe}{{\small\faLinkedinIn}\hspace{0.13cm}johndoe}} - \end{header} - - \vspace{0.2 cm} - - - \section{Summary} - { - \setlength{\leftskip}{0.2 cm} - \setlength{\rightskip}{0.2 cm} - - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque porta vitae dolor vel placerat. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Phasellus ullamcorper, neque id varius dignissim, tellus sem maximus risus, at lobortis nisl sem id ligula. - - \setlength{\leftskip}{0cm} - \setlength{\rightskip}{0cm} - } - - \centering - \section{Education} - - \begin{tabularx}{\textwidth-0.4 cm-0.13cm}{L{0.85cm} K{0.2 cm} R{3.6 cm}} - \textbf{BS} - & - \textbf{My University}, Mechanical Engineering - \vspace{0.10 cm} - \begin{highlights} - \item GPA: 3.99/4.00 (\href{https://example.com/}{Transcript}) - \item Class rank: 1 of 62 \hspace*{-0.2cm} - \end{highlights} - & - Ankara, Türkiye \newline - Sept. 2017 to Jan. 2023 - \end{tabularx} - - \vspace{0.2 cm} - \begin{tabularx}{\textwidth-0.4 cm-0.13cm}{L{0.85cm} K{0.2 cm} R{3.6 cm}} - \textbf{} - & - \textbf{The University of Texas at Austin}, Mechanical Engineering, Student Exchange Program - \vspace{0.10 cm} - \begin{highlights} - \item GPA: 4.00/4.00 (\href{https://example.com/}{Transcript}) \hspace*{-0.2cm} - \end{highlights} - & - Austin, TX, USA \newline - Aug. 2021 to Jan. 2022 - \end{tabularx} - - - - \section{Work Experience} - - \begin{tabularx}{\textwidth-0.4 cm-0.13cm}{K{0.2 cm} R{3.6 cm}} - \textbf{CERN}, Mechanical Engineer - \vspace{0.10 cm} - \begin{highlights} - \item CERN is a research organization that operates the world's largest and most powerful particle accelerator. - \item Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. - \item Id leo in vitae turpis massa sed, posuere aliquam ultrices sagittis orci a scelerisque, lorem ipsum dolor sit amet. \hspace*{-0.2cm} - \end{highlights} - & - Geneva, Switzerland \newline - Feb. 2023 to present \newline - 12 months - \end{tabularx} - - \vspace{0.2 cm} - \begin{tabularx}{\textwidth-0.4 cm-0.13cm}{K{0.2 cm} R{3.6 cm}} - \textbf{AmIACompany}, Summer Intern - \vspace{0.10 cm} - \begin{highlights} - \item AmIACompany is a technology company that provides web-based engineering applications that enable the simulation and optimization of products and manufacturing tools. - \item Modeled and simulated a metal-forming process deep drawing using finite element analysis with open-source software called CalculiX. \hspace*{-0.2cm} - \end{highlights} - & - Istanbul, Türkiye \newline - June 2022 to Aug. 2022 \newline - 2 months - \end{tabularx} - - - - \section{Academic Projects} - - \begin{tabularx}{\textwidth-0.4 cm-0.13cm}{K{0.2 cm} R{3.6 cm}} - \textbf{Design and Construction of a Robot}, \href{https://example.com/}{view on my website} - \vspace{0.10 cm} - \begin{highlights} - \item Designed and constructed a controllable robot that measures a car's torque and power output at different speeds for my senior design project. \hspace*{-0.2cm} - \end{highlights} - & - Istanbul, Türkiye \newline - Fall 2022 - \end{tabularx} - - \vspace{0.2 cm} - \begin{tabularx}{\textwidth-0.4 cm-0.13cm}{K{0.2 cm} R{3.6 cm}} - \textbf{Design and Construction of an Another Robot}, \href{https://example.com/}{view on my website} - \vspace{0.10 cm} - \begin{highlights} - \item Designed, built, and programmed a microcontroller-based device that plays a guitar with DC motors as part of a mechatronics course term project. \hspace*{-0.2cm} - \end{highlights} - & - Istanbul, Türkiye \newline - Fall 2020 - \end{tabularx} - - - - \section{Certificates} - - \begin{tabularx}{\textwidth-0.4 cm-0.13cm}{K{0.2 cm} R{3.6 cm}} - \textbf{Machine Learning by Stanford University}, \href{https://example.com/}{Certificate} - \vspace{0.10 cm} - & - Sept. 2022 - \end{tabularx} - - - - \section{Personal Projects} - - \begin{tabularx}{\textwidth-0.4 cm-0.13cm}{K{0.2 cm} R{3.6 cm}} - \textbf{Ray Tracing in C++}, \href{https://example.com/}{view on my website} - \vspace{0.10 cm} - \begin{highlights} - \item Coded a ray tracer in C++ that can render scenes with multiple light sources, spheres, and planes with reflection and refraction properties. \hspace*{-0.2cm} - \end{highlights} - & - Spring 2021 - \end{tabularx} - - - - \section{Skills} - - \begingroup \leftskip=0.2 cm - \advance\csname @rightskip\endcsname 0.2 cm - \advance\rightskip 0.2 cm - - \textbf{Programming:} C++, C, Python, JavaScript, MATLAB, Lua, LaTeX - - \par\endgroup - - \vspace{0.2 cm} - \begingroup \leftskip=0.2 cm - \advance\csname @rightskip\endcsname 0.2 cm - \advance\rightskip 0.2 cm - - \textbf{OS:} Windows, Ubuntu - - \par\endgroup - - \vspace{0.2 cm} - \begingroup \leftskip=0.2 cm - \advance\csname @rightskip\endcsname 0.2 cm - \advance\rightskip 0.2 cm - - \textbf{Other tools:} Git, Premake, HTML, CSS, React - - \par\endgroup - - \vspace{0.2 cm} - \begingroup \leftskip=0.2 cm - \advance\csname @rightskip\endcsname 0.2 cm - \advance\rightskip 0.2 cm - - \textbf{Languages:} English (Advanced), French (Lower Intermediate), Turkish (Native) - - \par\endgroup - - - - \section{Test Scores} - - \begingroup \leftskip=0.2 cm - \advance\csname @rightskip\endcsname 0.2 cm - \advance\rightskip 0.2 cm - - \textbf{TOEFL:} 113/120 — Reading: 29/30, Listening: 30/30, Speaking: 27/30, Writing: 27/30 (\href{https://example.com/}{Score Report}) - - \par\endgroup - - \vspace{0.2 cm} - \begingroup \leftskip=0.2 cm - \advance\csname @rightskip\endcsname 0.2 cm - \advance\rightskip 0.2 cm - - \textbf{GRE:} Verbal Reasoning: 160/170, Quantitative Reasoning: 170/170, Analytical Writing: 5.5/6 (\href{https://example.com/}{Score Report}) - - \par\endgroup - - - - \section{Extracurricular Activities} - - \begin{tabularx}{\textwidth-0.4 cm-0.13cm}{K{0.2 cm} R{3.6 cm}} - \textbf{Dumanlikiz Skiing Club}, Co-founder / Skiing Instructor - \vspace{0.10 cm} - \begin{highlights} - \item Taught skiing during winters as a certified skiing instructor. \hspace*{-0.2cm} - \end{highlights} - & - Chamonix, France \newline - Summer 2017 and 2018 - \end{tabularx} - - - - \section{Publications} - - \begin{tabularx}{\textwidth-0.4 cm-0.13cm}{K{0.2 cm} R{3.6 cm}} - \textbf{Phononic band gaps induced by inertial amplification in periodic media} - - \vspace{0.10 cm} - - \mbox{A. 1}, \mbox{\textbf{\textit{J. Doe}}}, \mbox{A. 3} - - \vspace{0.10 cm} - - \href{https://doi.org/10.1103/PhysRevB.76.054309}{10.1103/PhysRevB.76.054309} (Physical Review B) - & - Aug. 2007 - - \end{tabularx} - - - - \section{My Custom Section} - - \begingroup \leftskip=0.2 cm - \advance\csname @rightskip\endcsname 0.2 cm - \advance\rightskip 0.2 cm - - \textbf{Testing custom sections:} Wohooo! - - \par\endgroup - - \vspace{0.2 cm} - \begingroup \leftskip=0.2 cm - \advance\csname @rightskip\endcsname 0.2 cm - \advance\rightskip 0.2 cm - - \textbf{This is a:} OneLineEntry! - - \par\endgroup - - - - \section{My Other Custom Section} - - \begin{tabularx}{\textwidth-0.4 cm-0.13cm}{L{0.85cm} K{0.2 cm} R{3.6 cm}} - \textbf{HA} - & - \textbf{Hop!}, Hop! - \vspace{0.10 cm} - \begin{highlights} - \item There are only five types of entries: \textit{EducationEntry}, \textit{ExperienceEntry}, \textit{NormalEntry}, \textit{OneLineEntry}, and \textit{PublicationEntry}. - \item This is an EducationEntry! \hspace*{-0.2cm} - \end{highlights} - & - June 2022 to Aug. 2022 \newline - 2 months - \end{tabularx} - - - - \section{My Third Custom Section} - - \begin{tabularx}{\textwidth-0.4 cm-0.13cm}{K{0.2 cm} R{3.6 cm}} - \textbf{Hop!}, Hop! - \vspace{0.10 cm} - \begin{highlights} - \item I think this is really working. This is an \textit{ExperienceEntry}! \hspace*{-0.2cm} - \end{highlights} - & - My Location \newline - My Date - \end{tabularx} - - - - \section{My Final Custom Section} - - \begin{tabularx}{\textwidth-0.4 cm-0.13cm}{K{0.2 cm}} - \textbf{This is a normal entry!}, \href{https://example.com/}{My Link Text} - \vspace{0.10 cm} - \begin{highlights} - \item You don't have to specify a \textit{date} or \textbf{location} every time. - \item You can use \textit{Markdown} in the \textbf{highlights}! - \item Special characters test: üğç \hspace*{-0.2cm} - \end{highlights} - \end{tabularx} - - - - -\end{document} \ No newline at end of file diff --git a/tests/reference_files/John_Doe_CV_yaml_reference.yaml b/tests/reference_files/John_Doe_CV_yaml_reference.yaml deleted file mode 100644 index fc409c6..0000000 --- a/tests/reference_files/John_Doe_CV_yaml_reference.yaml +++ /dev/null @@ -1,218 +0,0 @@ -cv: - name: John Doe - label: Mechanical Engineer - location: TX, USA - email: johndoe@example.com - phone: "+33749882538" - website: https://example.com - social_networks: - - network: GitHub - username: johndoe - - network: LinkedIn - username: johndoe - summary: - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque porta - vitae dolor vel placerat. Class aptent taciti sociosqu ad litora torquent per conubia - nostra, per inceptos himenaeos. Phasellus ullamcorper, neque id varius dignissim, - tellus sem maximus risus, at lobortis nisl sem id ligula. - section_order: - - Education - - Work Experience - - Academic Projects - - Certificates - - Personal Projects - - Skills - - Test Scores - - Extracurricular Activities - - Publications - - My Custom Section - - My Other Custom Section - - My Third Custom Section - - My Final Custom Section - education: - - institution: My University - url: https://boun.edu.tr - area: Mechanical Engineering - study_type: BS - location: Ankara, Türkiye - start_date: "2017-09-01" - end_date: "2023-01-01" - transcript_url: https://example.com - gpa: 3.99/4.00 - highlights: - - "Class rank: 1 of 62" - - institution: The University of Texas at Austin - url: https://utexas.edu - area: Mechanical Engineering, Student Exchange Program - location: Austin, TX, USA - start_date: "2021-08-01" - end_date: "2022-01-15" - transcript_url: https://example.com - gpa: 4.00/4.00 - work_experience: - - company: CERN - position: Mechanical Engineer - location: Geneva, Switzerland - url: https://home.cern - start_date: "2023-02-01" - end_date: present - highlights: - - CERN is a research organization that operates the world's largest and most - powerful particle accelerator. - - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor - incididunt ut labore et dolore magna aliqua. - - Id leo in vitae turpis massa sed, posuere aliquam ultrices sagittis orci a - scelerisque, lorem ipsum dolor sit amet. - - company: AmIACompany - position: Summer Intern - location: Istanbul, Türkiye - url: https://example.com - start_date: "2022-06-15" - end_date: "2022-08-01" - highlights: - - AmIACompany is a technology company that provides web-based engineering - applications that enable the simulation and optimization of products and - manufacturing tools. - - Modeled and simulated a metal-forming process deep drawing using finite element - analysis with open-source software called CalculiX. - academic_projects: - - name: Design and Construction of a Robot - location: Istanbul, Türkiye - date: Fall 2022 - highlights: - - Designed and constructed a controllable robot that measures a car's torque and - power output at different speeds for my senior design project. - url: https://example.com - - name: Design and Construction of an Another Robot - location: Istanbul, Türkiye - date: Fall 2020 - highlights: - - Designed, built, and programmed a microcontroller-based device that plays a - guitar with DC motors as part of a mechatronics course term project. - url: https://example.com - publications: - - title: Phononic band gaps induced by inertial amplification in periodic media - authors: - - Author 1 - - John Doe - - Author 3 - journal: Physical Review B - doi: 10.1103/PhysRevB.76.054309 - date: "2007-08-01" - cited_by: 243 - certificates: - - name: Machine Learning by Stanford University - date: "2022-09-01" - url: https://example.com - skills: - - name: Programming - details: C++, C, Python, JavaScript, MATLAB, Lua, LaTeX - - name: OS - details: Windows, Ubuntu - - name: Other tools - details: Git, Premake, HTML, CSS, React - - name: Languages - details: English (Advanced), French (Lower Intermediate), Turkish (Native) - test_scores: - - name: TOEFL - date: "2022-10-01" - details: - "113/120 — Reading: 29/30, Listening: 30/30, Speaking: 27/30, Writing: - 27/30" - url: https://example.com - - name: GRE - details: "Verbal Reasoning: 160/170, Quantitative Reasoning: 170/170, Analytical - Writing: 5.5/6" - url: https://example.com - personal_projects: - - name: Ray Tracing in C++ - date: Spring 2021 - highlights: - - Coded a ray tracer in C++ that can render scenes with multiple light sources, - spheres, and planes with reflection and refraction properties. - url: https://example.com - extracurricular_activities: - - company: Dumanlikiz Skiing Club - position: Co-founder / Skiing Instructor - location: Chamonix, France - date: Summer 2017 and 2018 - highlights: - - Taught skiing during winters as a certified skiing instructor. - custom_sections: - - title: My Custom Section - entry_type: OneLineEntry - entries: - - name: Testing custom sections - details: Wohooo! - - name: This is a - details: OneLineEntry! - - title: My Other Custom Section - entry_type: EducationEntry - entries: - - institution: Hop! - area: Hop! - study_type: HA - highlights: - - "There are only five types of entries: *EducationEntry*, *ExperienceEntry*, - *NormalEntry*, *OneLineEntry*, and *PublicationEntry*." - - This is an EducationEntry! - start_date: "2022-06-15" - end_date: "2022-08-01" - - title: My Third Custom Section - entry_type: ExperienceEntry - entries: - - company: Hop! - position: Hop! - date: My Date - location: My Location - highlights: - - I think this is really working. This is an *ExperienceEntry*! - - - title: My Final Custom Section - entry_type: NormalEntry - link_text: My Link Text - entries: - - name: This is a normal entry! - url: https://example.com - highlights: - - You don't have to specify a *date* or **location** every time. - - You can use *Markdown* in the **highlights**! - - "Special characters test: üğç" - -design: - theme: classic - font: SourceSans3 - font_size: 10pt - page_size: a4paper - options: - primary_color: rgb(0,79,144) - date_and_location_width: 3.6 cm - show_timespan_in: - - Work Experience - - My Other Custom Section - show_last_updated_date: True - text_alignment: justified - header_font_size: 30 pt - - margins: - page: - top: 2 cm - bottom: 2 cm - left: 1.24 cm - right: 1.24 cm - section_title: - top: 0.2 cm - bottom: 0.2 cm - - entry_area: - left_and_right: 0.2 cm - vertical_between: 0.2 cm - - highlights_area: - top: 0.10 cm - left: 0.4 cm - vertical_between_bullet_points: 0.10 cm - - header: - vertical_between_name_and_connections: 0.2 cm - bottom: 0.2 cm \ No newline at end of file diff --git a/tests/reference_files/fonts/SourceSans3-Bold.ttf b/tests/reference_files/fonts/SourceSans3-Bold.ttf deleted file mode 100644 index 55f6138..0000000 Binary files a/tests/reference_files/fonts/SourceSans3-Bold.ttf and /dev/null differ diff --git a/tests/reference_files/fonts/SourceSans3-BoldItalic.ttf b/tests/reference_files/fonts/SourceSans3-BoldItalic.ttf deleted file mode 100644 index ddeed16..0000000 Binary files a/tests/reference_files/fonts/SourceSans3-BoldItalic.ttf and /dev/null differ diff --git a/tests/reference_files/fonts/SourceSans3-Italic.ttf b/tests/reference_files/fonts/SourceSans3-Italic.ttf deleted file mode 100644 index 8ea9acf..0000000 Binary files a/tests/reference_files/fonts/SourceSans3-Italic.ttf and /dev/null differ diff --git a/tests/reference_files/fonts/SourceSans3-Regular.ttf b/tests/reference_files/fonts/SourceSans3-Regular.ttf deleted file mode 100644 index 803d4da..0000000 Binary files a/tests/reference_files/fonts/SourceSans3-Regular.ttf and /dev/null differ diff --git a/tests/test_cli.py b/tests/test_cli.py index 3c516ed..b02b7c0 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,76 +1,192 @@ -import unittest import os import shutil -import subprocess -import sys -from rendercv import data_model +import rendercv.cli as cli +import rendercv.data_models as dm + +import pydantic +import ruamel.yaml +import pytest +import typer.testing +import time_machine -class TestCLI(unittest.TestCase): - def test_render(self): - # Change the working directory to the root of the project: - workspace_path = os.path.dirname(os.path.dirname(__file__)) +def test_welcome(): + cli.welcome() - with self.subTest(msg="Correct input"): - test_input_file_path = os.path.join( - workspace_path, - "tests", - "reference_files", - "John_Doe_CV_yaml_reference.yaml", - ) - subprocess.run( - [sys.executable, "-m", "rendercv", "render", test_input_file_path], - check=True, - ) - # Read the necessary information and remove the output directory: - output_file_path = os.path.join(workspace_path, "output", "John_Doe_CV.pdf") - pdf_file_size = os.path.getsize(output_file_path) - file_exists = os.path.exists(output_file_path) - shutil.rmtree(os.path.join(workspace_path, "output")) +def test_warning(): + cli.warning("This is a warning message.") - # Check if the output file exists: - self.assertTrue(file_exists, msg="PDF file couldn't be generated.") - # Compare the pdf file with the reference pdf file: - reference_pdf_file = os.path.join( - workspace_path, - "tests", - "reference_files", - "John_Doe_CV_pdf_reference.pdf", - ) - reference_pdf_file_size = os.path.getsize(reference_pdf_file) - ratio = min(reference_pdf_file_size, pdf_file_size) / max( - reference_pdf_file_size, pdf_file_size - ) - self.assertTrue(ratio > 0.98, msg="PDF file didn't match the reference.") +def test_error(): + cli.error("This is an error message.") - # Wrong input: - with self.subTest(msg="Wrong input"): - with self.assertRaises(subprocess.CalledProcessError): - subprocess.run( - [ - sys.executable, - "-m", - "rendercv", - "wrong_input.yaml", - ], - check=True, - ) - def test_new(self): - # Change the working directory to the root of the project: - workspace_path = os.path.dirname(os.path.dirname(__file__)) +def test_information(): + cli.information("This is an information message.") - subprocess.run( - [sys.executable, "-m", "rendercv", "new", "John Doe"], - check=True, - ) - output_file_path = os.path.join(workspace_path, "John_Doe_CV.yaml") - model: data_model.RenderCVDataModel = data_model.read_input_file( - output_file_path - ) +def test_get_error_message_and_location_and_value_from_a_custom_error(): + error_string = "('error message', 'location', 'value')" + result = cli.get_error_message_and_location_and_value_from_a_custom_error( + error_string + ) + assert result == ("error message", "location", "value") - self.assertTrue(model.cv.name == "John Doe") + error_string = """("er'ror message", 'location', 'value')""" + result = cli.get_error_message_and_location_and_value_from_a_custom_error( + error_string + ) + assert result == ("er'ror message", "location", "value") + + error_string = "error message" + result = cli.get_error_message_and_location_and_value_from_a_custom_error( + error_string + ) + assert result == (None, None, None) + + +@pytest.mark.parametrize( + "data_model_class, invalid_model", + [ + ( + dm.EducationEntry, + { + "institution": "Boğaziçi University", + "area": "Mechanical Engineering", + "degree": "BS", + "date": "2028-12-08", + }, + ), + ( + dm.EducationEntry, + { + "area": "Mechanical Engineering", + "extra": "Extra", + }, + ), + ( + dm.ExperienceEntry, + { + "company": "CERN", + }, + ), + ( + dm.ExperienceEntry, + { + "position": "Researcher", + }, + ), + ( + dm.ExperienceEntry, + { + "company": "CERN", + "position": "Researcher", + "stat_date": "2023-12-08", + "end_date": "INVALID END DATE", + }, + ), + ( + dm.PublicationEntry, + { + "doi": "10.1109/TASC.2023.3340648", + }, + ), + ( + dm.ExperienceEntry, + { + "authors": ["John Doe", "Jane Doe"], + }, + ), + ( + dm.OneLineEntry, + { + "name": "My One Line Entry", + }, + ), + ( + dm.NormalEntry, + { + "name": "My Entry", + }, + ), + ( + dm.CurriculumVitae, + { + "name": "John Doe", + "sections": { + "education": [ + { + "institution": "Boğaziçi University", + "area": "Mechanical Engineering", + "degree": "BS", + "date": "2028-12-08", + }, + { + "degree": "BS", + }, + ] + }, + }, + ), + ], +) +def test_handle_validation_error(data_model_class, invalid_model): + try: + data_model_class(**invalid_model) + except pydantic.ValidationError as e: + cli.handle_validation_error(e) + + +@pytest.mark.parametrize( + "exception", + [ruamel.yaml.YAMLError, RuntimeError, FileNotFoundError, ValueError], +) +def test_handle_exceptions(exception): + @cli.handle_exceptions + def function_that_raises_exception(): + raise exception("This is an exception!") + + function_that_raises_exception() + + +def test_live_progress_reporter_class(): + with cli.LiveProgressReporter(number_of_steps=3) as progress: + progress.start_a_step("Test step 1") + progress.finish_the_current_step() + + progress.start_a_step("Test step 2") + progress.finish_the_current_step() + + progress.start_a_step("Test step 3") + progress.finish_the_current_step() + + +runner = typer.testing.CliRunner() + + +@time_machine.travel("2024-01-01") +def test_render_command(tmp_path, input_file_path): + # copy input file to the temporary directory to create the output directory there: + input_file_path = shutil.copy(input_file_path, tmp_path) + + result = runner.invoke(cli.app, ["render", str(input_file_path)]) + + assert result.exit_code == 0 + assert "Your CV is rendered!" in result.stdout + + +def test_render_command_with_use_local_latex_option(tmp_path, input_file_path): + # copy input file to the temporary directory to create the output directory there: + input_file_path = shutil.copy(input_file_path, tmp_path) + + runner.invoke(cli.app, ["render", str(input_file_path), "--use-local-latex"]) + + +def test_new_command(tmp_path): + # change the current working directory to the temporary directory: + os.chdir(tmp_path) + result = runner.invoke(cli.app, ["new", "John Doe"]) + assert result.exit_code == 0 + assert "Your RenderCV input file has been created" in result.stdout diff --git a/tests/test_data_model.py b/tests/test_data_model.py deleted file mode 100644 index bd3e492..0000000 --- a/tests/test_data_model.py +++ /dev/null @@ -1,990 +0,0 @@ -import unittest -import os -import json - -from rendercv import data_model - -from datetime import date as Date -from pydantic import ValidationError, HttpUrl - - -class TestDataModel(unittest.TestCase): - def test_escape_latex_characters(self): - tests = [ - { - "input": "This is a string without LaTeX characters.", - "expected": "This is a string without LaTeX characters.", - "msg": "string without LaTeX characters", - }, - { - "input": r"asdf#asdf$asdf%asdf& ~ fd_ \ ^aa aa{ bb}", - "expected": ( - r"asdf\#asdf$asdf\%asdf\& \textasciitilde{} fd_ \ ^aa aa{ bb}" - ), - "msg": "string with LaTeX characters", - }, - ] - - for test in tests: - with self.subTest(msg=test["msg"]): - result = data_model.escape_latex_characters(test["input"]) - self.assertEqual(result, test["expected"]) - - def test_compute_time_span_string(self): - # Valid inputs: - tests = [ - { - "start_date": Date(year=2020, month=1, day=1), - "end_date": Date(year=2021, month=1, day=1), - "expected": "1 year 1 month", - "msg": "1 year 1 month", - }, - { - "start_date": Date(year=2020, month=1, day=1), - "end_date": Date(year=2020, month=2, day=1), - "expected": "1 month", - "msg": "1 month", - }, - { - "start_date": Date(year=2020, month=1, day=1), - "end_date": Date(year=2023, month=3, day=2), - "expected": "3 years 2 months", - "msg": "3 years 2 months", - }, - { - "start_date": Date(year=2020, month=1, day=1), - "end_date": 2021, - "expected": "1 year 1 month", - "msg": "start_date and YYYY end_date", - }, - { - "start_date": 2020, - "end_date": Date(year=2021, month=1, day=1), - "expected": "1 year 1 month", - "msg": "YYYY start_date and end_date", - }, - { - "start_date": 2020, - "end_date": 2021, - "expected": "1 year 1 month", - "msg": "YYYY start_date and YYYY end_date", - }, - { - "start_date": None, - "end_date": Date(year=2023, month=3, day=2), - "expected": TypeError, - "msg": "start_date is None", - }, - { - "start_date": Date(year=2020, month=1, day=1), - "end_date": None, - "expected": TypeError, - "msg": "end_date is None", - }, - { - "start_date": 324, - "end_date": "test", - "expected": TypeError, - "msg": "start_date and end_date are not dates", - }, - ] - - for test in tests: - with self.subTest(msg=test["msg"]): - if isinstance(test["expected"], type): - if issubclass(test["expected"], Exception): - with self.assertRaises(test["expected"]): - data_model.compute_time_span_string( - test["start_date"], test["end_date"] - ) - else: - result = data_model.compute_time_span_string( - test["start_date"], test["end_date"] - ) - self.assertEqual(result, test["expected"]) - - def test_format_date(self): - tests = [ - { - "date": Date(year=2020, month=1, day=1), - "expected": "Jan. 2020", - "msg": "Jan. 2020", - }, - { - "date": Date(year=1983, month=12, day=1), - "expected": "Dec. 1983", - "msg": "Dec. 1983", - }, - { - "date": Date(year=2045, month=6, day=1), - "expected": "June 2045", - "msg": "June 2045", - }, - ] - - for test in tests: - with self.subTest(msg=test["msg"]): - result = data_model.format_date(test["date"]) - self.assertEqual(result, test["expected"]) - - def test_data_design_font(self): - tests = [ - {"input": "SourceSans3", "expected": "SourceSans3", "msg": "valid font"}, - { - "input": "InvalidFont", - "expected": ValidationError, - "msg": "invalid font", - }, - ] - - for test in tests: - with self.subTest(msg=test["msg"]): - if isinstance(test["expected"], type): - if issubclass(test["expected"], Exception): - with self.assertRaises(test["expected"]): - data_model.Design(font=test["input"]) - else: - design = data_model.Design(font=test["input"]) - self.assertEqual(design.font, test["expected"]) - - def test_data_design_theme(self): - tests = [ - {"input": "classic", "expected": "classic", "msg": "valid theme"}, - { - "input": "InvalidTheme", - "expected": ValidationError, - "msg": "invalid theme", - }, - ] - - for test in tests: - with self.subTest(msg=test["msg"]): - if isinstance(test["expected"], type): - if issubclass(test["expected"], Exception): - with self.assertRaises(test["expected"]): - data_model.Design(theme=test["input"]) - else: - design = data_model.Design(theme=test["input"]) - self.assertEqual(design.theme, test["expected"]) - - def test_data_design_show_timespan_in(self): - # Valid show_timespan_in: - input = { - "design": { - "options": { - "show_timespan_in": ["Work Experience"], - } - }, - "cv": { - "name": "John Doe", - "work_experience": [ - { - "company": "My Company", - "position": "My Position", - "start_date": "2020-01-01", - "end_date": "2021-01-01", - } - ], - }, - } - with self.subTest(msg="valid show_timespan_in"): - data_model.RenderCVDataModel(**input) - - # Nonexistent show_timespan_in: - del input["cv"]["work_experience"] - with self.subTest(msg="nonexistent show_timespan_in"): - with self.assertRaises(ValidationError): - data_model.RenderCVDataModel(**input) - - def test_data_event_check_dates(self): - # Inputs with valid dates: - # All the combinations are tried. In valid dates: - # Start dates can be 4 different things: YYYY-MM-DD, YYYY-MM, YYYY. - # End dates can be 5 different things: YYYY-MM-DD, YYYY-MM, YYYY, or "present" or None. - start_dates = [ - { - "input": "2020-01-01", - "expected": Date.fromisoformat("2020-01-01"), - }, - { - "input": "2020-01", - "expected": Date.fromisoformat("2020-01-01"), - }, - { - "input": "2020", - "expected": 2020, - }, - ] - - end_dates = [ - { - "input": "2021-01-01", - "expected": Date.fromisoformat("2021-01-01"), - }, - { - "input": "2021-01", - "expected": Date.fromisoformat("2021-01-01"), - }, - { - "input": "2021", - "expected": 2021, - }, - { - "input": "present", - "expected": "present", - }, - { - "input": None, - "expected": "present", - }, - ] - - combinations = [ - (start_date, end_date) - for start_date in start_dates - for end_date in end_dates - ] - for start_date, end_date in combinations: - with self.subTest( - msg=f"valid: {start_date['expected']} to {end_date['expected']}" - ): - event = data_model.Event( - start_date=start_date["input"], end_date=end_date["input"] - ) - self.assertEqual(event.start_date, start_date["expected"]) - self.assertEqual(event.end_date, end_date["expected"]) - - # Valid dates but edge cases: - tests = [ - { - "input": { - "start_date": None, - "end_date": None, - "date": "My Birthday", - }, - "expected": { - "start_date": None, - "end_date": None, - "date": "My Birthday", - }, - "msg": "valid: custom date only", - }, - { - "input": { - "start_date": None, - "end_date": None, - "date": "2020-01-01", - }, - "expected": { - "start_date": None, - "end_date": None, - "date": Date.fromisoformat("2020-01-01"), - }, - "msg": "valid: YYYY-MM-DD date only", - }, - { - "input": { - "start_date": "2020-01-01", - "end_date": "present", - "date": "My Birthday", - }, - "expected": { - "start_date": Date.fromisoformat("2020-01-01"), - "end_date": "present", - "date": None, - }, - "msg": "valid: start_date, end_date, and date", - }, - { - "input": { - "start_date": "2020-01-01", - "end_date": None, - "date": "My Birthday", - }, - "expected": { - "start_date": None, - "end_date": None, - "date": "My Birthday", - }, - "msg": "valid: start_date and date", - }, - { - "input": { - "start_date": None, - "end_date": "2020-01-01", - "date": "My Birthday", - }, - "expected": { - "start_date": None, - "end_date": None, - "date": "My Birthday", - }, - "msg": "valid: end_date and date", - }, - ] - - for test in tests: - with self.subTest(msg=test["msg"]): - event = data_model.Event(**test["input"]) - self.assertEqual(event.start_date, test["expected"]["start_date"]) - self.assertEqual(event.end_date, test["expected"]["end_date"]) - self.assertEqual(event.date, test["expected"]["date"]) - - # Inputs without dates: - with self.subTest(msg="no dates"): - event = data_model.Event(**{}) - self.assertEqual(event.start_date, None, msg="Start date is not correct.") - self.assertEqual(event.end_date, None, msg="End date is not correct.") - self.assertEqual(event.date, None, msg="Date is not correct.") - - # Invalid dates: - tests = [ - { - "input": { - "start_date": "2020-01-01", - "end_date": "2019-01-01", - }, - "expected": ValidationError, - "msg": "start_date > end_date", - }, - { - "input": { - "start_date": "2020-01-01", - "end_date": "2900-01-01", - }, - "expected": ValidationError, - "msg": "end_date > present", - }, - { - "input": { - "start_date": "invalid date", - "end_date": "invalid date", - }, - "expected": ValidationError, - "msg": "invalid start_date and end_date", - }, - { - "input": { - "start_date": "invalid date", - "end_date": "2020-01-01", - }, - "expected": ValidationError, - "msg": "invalid start_date", - }, - { - "input": { - "start_date": "2020-01-01", - "end_date": "invalid date", - }, - "expected": ValidationError, - "msg": "invalid end_date", - }, - ] - - for test in tests: - with self.subTest(msg=test["msg"]): - with self.assertRaises(test["expected"]): - data_model.Event(**test["input"]) - - def test_data_event_date_and_location_strings(self): - tests = [ - { - "input": { - "start_date": "2020-01-01", - "end_date": "2021-01-16", - "location": "My Location", - }, - "expected_with_time_span": [ - "My Location", - "Jan. 2020 to Jan. 2021", - "1 year 1 month", - ], - "expected_without_time_span": [ - "My Location", - "Jan. 2020 to Jan. 2021", - ], - "msg": "start_date, end_date, and location are provided", - }, - { - "input": { - "date": "My Birthday", - "location": "My Location", - }, - "expected_with_time_span": [ - "My Location", - "My Birthday", - ], - "expected_without_time_span": [ - "My Location", - "My Birthday", - ], - "msg": "date and location are provided", - }, - { - "input": { - "date": "2020-01-01", - }, - "expected_with_time_span": [ - "Jan. 2020", - ], - "expected_without_time_span": [ - "Jan. 2020", - ], - "msg": "date is provided", - }, - { - "input": { - "start_date": "2020-01-01", - "end_date": "2021-01-16", - }, - "expected_with_time_span": [ - "Jan. 2020 to Jan. 2021", - "1 year 1 month", - ], - "expected_without_time_span": [ - "Jan. 2020 to Jan. 2021", - ], - "msg": "start_date and end_date are provided", - }, - { - "input": { - "location": "My Location", - }, - "expected_with_time_span": [ - "My Location", - ], - "expected_without_time_span": [ - "My Location", - ], - "msg": "location is provided", - }, - ] - - for test in tests: - with self.subTest(msg=test["msg"]): - event = data_model.Event(**test["input"]) - result = event.date_and_location_strings_with_timespan - self.assertEqual(result, test["expected_with_time_span"]) - - result = event.date_and_location_strings_without_timespan - self.assertEqual(result, test["expected_without_time_span"]) - - def test_data_event_highlight_strings(self): - tests = [ - { - "highlights": [ - "My Highlight 1", - "My Highlight 2", - ], - "expected": [ - "My Highlight 1", - "My Highlight 2", - ], - "msg": "highlights are provided", - }, - { - "highlights": [], - "expected": [], - "msg": "highlights are not provided", - }, - ] - - for test in tests: - with self.subTest(msg=test["msg"]): - event = data_model.Event(highlights=test["highlights"]) - result = event.highlight_strings - self.assertEqual(result, test["expected"]) - - def test_data_event_markdown_url(self): - tests = [ - { - "url": "https://www.linkedin.com/in/username", - "expected": "[view on LinkedIn](https://www.linkedin.com/in/username)", - "msg": "LinkedIn link", - }, - { - "url": "https://www.github.com/sinaatalay", - "expected": "[view on GitHub](https://www.github.com/sinaatalay)", - "msg": "Github link", - }, - { - "url": "https://www.instagram.com/username", - "expected": "[view on Instagram](https://www.instagram.com/username)", - "msg": "Instagram link", - }, - { - "url": "https://www.youtube.com/", - "expected": "[view on YouTube](https://www.youtube.com/)", - "msg": "Youtube link", - }, - { - "url": "https://www.google.com/", - "expected": "[view on my website](https://www.google.com/)", - "msg": "Other links", - }, - ] - - for test in tests: - with self.subTest(msg=test["msg"]): - event = data_model.Event(url=test["url"]) - result = event.markdown_url - self.assertEqual(result, test["expected"]) - - def test_data_event_month_and_year(self): - tests = [ - { - "input": { - "start_date": "2020-01-01", - "end_date": "2021-01-16", - }, - "expected": None, - "msg": "start_date and end_date are provided", - }, - { - "input": { - "date": "My Birthday", - }, - "expected": "My Birthday", - "msg": "custom date is provided", - }, - { - "input": { - "date": "2020-01-01", - }, - "expected": "Jan. 2020", - "msg": "date is provided", - }, - ] - - for test in tests: - with self.subTest(msg=test["msg"]): - event = data_model.Event(**test["input"]) - result = event.month_and_year - self.assertEqual(result, test["expected"]) - - def test_data_education_entry_highlight_strings(self): - tests = [ - { - "input": { - "institution": "My Institution", - "area": "My Area", - "gpa": 3.5, - "highlights": [ - "My Highlight 1", - "My Highlight 2", - ], - }, - "expected": [ - "GPA: 3.5", - "My Highlight 1", - "My Highlight 2", - ], - "msg": "gpa and highlights are provided", - }, - { - "input": { - "institution": "My Institution", - "area": "My Area", - "gpa": None, - "highlights": [ - "My Highlight 1", - "My Highlight 2", - ], - }, - "expected": [ - "My Highlight 1", - "My Highlight 2", - ], - "msg": "gpa is not provided, but highlights are", - }, - { - "input": { - "institution": "My Institution", - "area": "My Area", - "gpa": 3.5, - "highlights": [], - }, - "expected": [ - "GPA: 3.5", - ], - "msg": "gpa is provided, but highlights are not", - }, - { - "input": { - "institution": "My Institution", - "area": "My Area", - "gpa": None, - "highlights": [], - }, - "expected": [], - "msg": "neither gpa nor highlights are provided", - }, - { - "input": { - "institution": "My Institution", - "area": "My Area", - "gpa": 3.5, - "transcript_url": "https://www.example.com/", - "highlights": None, - }, - "expected": [ - "GPA: 3.5 ([Transcript](https://www.example.com/))", - ], - "msg": "gpa and transcript_url are provided, but highlights are not", - }, - { - "input": { - "institution": "My Institution", - "area": "My Area", - "gpa": "3.5", - "transcript_url": "https://www.example.com/", - "highlights": [ - "My Highlight 1", - "My Highlight 2", - ], - }, - "expected": [ - "GPA: 3.5 ([Transcript](https://www.example.com/))", - "My Highlight 1", - "My Highlight 2", - ], - "msg": "gpa, transcript_url, and highlights are provided", - }, - ] - - for test in tests: - with self.subTest(msg=test["msg"]): - education = data_model.EducationEntry(**test["input"]) - result = education.highlight_strings - self.assertEqual(result, test["expected"]) - - def test_data_publication_entry_check_doi(self): - # Invalid DOI: - input = { - "title": "My Publication", - "authors": [ - "Author 1", - "Author 2", - ], - "doi": "invalidDoi", - "date": "2020-01-01", - } - with self.subTest(msg="invalid doi"): - with self.assertRaises(ValidationError): - data_model.PublicationEntry(**input) - - # Valid DOI: - input = { - "title": "My Publication", - "authors": [ - "Author 1", - "Author 2", - ], - "doi": "10.1103/PhysRevB.76.054309", - "date": "2007-08-01", - } - with self.subTest(msg="valid doi"): - publication_entry = data_model.PublicationEntry(**input) - self.assertEqual(publication_entry.doi, input["doi"]) - - def test_data_publication_entry_doi_url(self): - input = { - "title": "My Publication", - "authors": [ - "Author 1", - "Author 2", - ], - "doi": "10.1103/PhysRevB.76.054309", - "date": "2007-08-01", - } - expected = "https://doi.org/10.1103/PhysRevB.76.054309" - publication = data_model.PublicationEntry(**input) - result = publication.doi_url - self.assertEqual(result, expected) - - def test_data_connection_url(self): - tests = [ - { - "input": { - "name": "LinkedIn", - "value": "username", - }, - "expected": "https://www.linkedin.com/in/username", - }, - { - "input": { - "name": "GitHub", - "value": "sinaatalay", - }, - "expected": "https://www.github.com/sinaatalay", - }, - { - "input": { - "name": "Instagram", - "value": "username", - }, - "expected": "https://www.instagram.com/username", - }, - { - "input": { - "name": "phone", - "value": "+909999999999", - }, - "expected": "+909999999999", - }, - { - "input": { - "name": "email", - "value": "example@example.com", - }, - "expected": "mailto:example@example.com", - }, - { - "input": { - "name": "website", - "value": "https://www.example.com/", - }, - "expected": "https://www.example.com/", - }, - { - "input": { - "name": "location", - "value": "My Location", - }, - "expected": None, - }, - ] - - for test in tests: - with self.subTest(msg=test["input"]["name"]): - connection = data_model.Connection(**test["input"]) - result = connection.url - self.assertEqual(result, test["expected"]) - - def test_data_curriculum_vitae_connections(self): - input = { - "name": "John Doe", - "location": "My Location", - "phone": "+905559876543", - "email": "john@doe.com", - "website": "https://www.example.com/", - } - exptected_length = 4 - cv = data_model.CurriculumVitae(**input) # type: ignore - result = len(cv.connections) - with self.subTest(msg="without social networks"): - self.assertEqual(result, exptected_length) - - input = { - "name": "John Doe", - "location": "My Location", - "phone": "+905559876543", - "email": "john@doe.com", - "website": "https://www.example.com/", - "social_networks": [ - {"network": "LinkedIn", "username": "username"}, - {"network": "GitHub", "username": "sinaatalay"}, - {"network": "Instagram", "username": "username"}, - ], - } - exptected_length = 7 - cv = data_model.CurriculumVitae(**input) - result = len(cv.connections) - with self.subTest(msg="with social networks"): - self.assertEqual(result, exptected_length) - - def test_data_curriculum_vitae_custom_sections(self): - # Valid custom sections: - input = { - "name": "John Doe", - "custom_sections": [ - { - "title": "My Custom Section 1", - "entry_type": "OneLineEntry", - "entries": [ - { - "name": "My Custom Entry Name", - "details": "My Custom Entry Value", - }, - { - "name": "My Custom Entry Name", - "details": "My Custom Entry Value", - }, - ], - }, - { - "title": "My Custom Section 2", - "entry_type": "NormalEntry", - "link_text": "My Custom Link Text", - "entries": [ - {"name": "My Custom Entry Name"}, - {"name": "My Custom Entry Name"}, - ], - }, - { - "title": "My Custom Section 3", - "entry_type": "ExperienceEntry", - "entries": [ - { - "company": "My Custom Entry Name", - "position": "My Custom Entry Value", - }, - { - "company": "My Custom Entry Name", - "position": "My Custom Entry Value", - }, - ], - }, - { - "title": "My Custom Section 4", - "entry_type": "EducationEntry", - "entries": [ - { - "institution": "My Custom Entry Name", - "area": "My Custom Entry Value", - }, - { - "institution": "My Custom Entry Name", - "area": "My Custom Entry Value", - }, - ], - }, - { - "title": "My Custom Section 5", - "entry_type": "PublicationEntry", - "entries": [ - { - "title": "My Publication", - "authors": [ - "Author 1", - "Author 2", - ], - "doi": "10.1103/PhysRevB.76.054309", - "date": "2020-01-01", - }, - { - "title": "My Publication", - "authors": [ - "Author 1", - "Author 2", - ], - "doi": "10.1103/PhysRevB.76.054309", - "date": "2020-01-01", - }, - ], - }, - ], - } - - with self.subTest(msg="valid custom sections"): - cv = data_model.CurriculumVitae(**input) - self.assertEqual(len(cv.sections), 5) - - with self.subTest(msg="check link_text"): - cv = data_model.CurriculumVitae(**input) - self.assertEqual(cv.sections[1].link_text, "My Custom Link Text") - - # Invalid section_order: - input["section_order"] = ["invalid section"] - with self.subTest(msg="invalid section_order"): - data = data_model.CurriculumVitae(**input) - with self.assertRaises(ValueError): - data.sections - del input["section_order"] - - # Custom sections with duplicate titles: - input["custom_sections"][1]["title"] = "My Custom Section 1" - with self.subTest(msg="custom sections with duplicate titles"): - with self.assertRaises(ValidationError): - data_model.CurriculumVitae(**input) - - def test_if_json_schema_is_the_latest(self): - tests_directory = os.path.dirname(__file__) - path_to_generated_schema = data_model.generate_json_schema(tests_directory) - - # Read the generated JSON schema: - with open(path_to_generated_schema, "r") as f: - generated_json_schema = json.load(f) - - # Remove the generated JSON schema: - os.remove(path_to_generated_schema) - - # Read the repository's current JSON schema: - path_to_schema = os.path.join(os.path.dirname(tests_directory), "schema.json") - with open(path_to_schema, "r") as f: - current_json_schema = json.load(f) - - # Compare the two JSON schemas: - self.assertEqual(generated_json_schema, current_json_schema) - - def test_read_input_file(self): - test_input = { - "cv": { - "name": "John Doe", - } - } - - # write dictionary to a file as json: - input_file_path = os.path.join(os.path.dirname(__file__), "test_input.json") - json_string = json.dumps(test_input) - with open(input_file_path, "w") as file: - file.write(json_string) - - # read the file: - result = data_model.read_input_file(input_file_path) - - # remove the file: - os.remove(input_file_path) - - with self.subTest(msg="read input file"): - self.assertEqual( - result.cv.name, - test_input["cv"]["name"], - ) - - with self.subTest(msg="nonexistent file"): - with self.assertRaises(FileNotFoundError): - data_model.read_input_file("nonexistent.json") - - def test_mastodon_parsing(self): - mastodon_name = "a_tooter@example.exchange" - expected = HttpUrl("https://example.exchange/@a_tooter") - result = data_model.Connection.MastodonUname2Url(mastodon_name) - with self.subTest("Without '@' prefix"): - self.assertEqual(result, expected) - - mastodon_name = "@a_tooter@example.exchange" - expected = HttpUrl("https://example.exchange/@a_tooter") - result = data_model.Connection.MastodonUname2Url(mastodon_name) - with self.subTest("With '@' prefix"): - self.assertEqual(result, expected) - - mastodon_name = "@too@many@symbols" - with self.subTest("Too many '@' symbols"): - with self.assertRaises(ValueError): - data_model.Connection.MastodonUname2Url(mastodon_name) - - mastodon_name = "@not_enough_at_symbols" - with self.subTest("Missing '@' separator"): - with self.assertRaises(ValueError): - data_model.Connection.MastodonUname2Url(mastodon_name) - - mastodon_name = "user@bad_domain.example" - with self.subTest("Underscore in domain portion"): - with self.assertRaises(ValueError): - data_model.Connection.MastodonUname2Url(mastodon_name) - - mastodon_name = "user@bad.numeric.tld.123" - with self.subTest("All digit TLD"): - with self.assertRaises(ValueError): - data_model.Connection.MastodonUname2Url(mastodon_name) - - mastodon_name = "a_tooter@example.exchange." - expected = HttpUrl("https://example.exchange./@a_tooter") - result = data_model.Connection.MastodonUname2Url(mastodon_name) - with self.subTest("With FQDN root '.'"): - self.assertEqual(result, expected) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_data_models.py b/tests/test_data_models.py new file mode 100644 index 0000000..ffcf59d --- /dev/null +++ b/tests/test_data_models.py @@ -0,0 +1,505 @@ +from datetime import date as Date +import json +import pathlib +import os +import shutil + +import pydantic +import pytest +import time_machine +import ruamel.yaml + +from rendercv import data_models as dm + +from .conftest import update_auxiliary_files + + +@pytest.mark.parametrize( + "date, expected_date_object, expected_error", + [ + ("2020-01-01", Date(2020, 1, 1), None), + ("2020-01", Date(2020, 1, 1), None), + ("2020", Date(2020, 1, 1), None), + (2020, Date(2020, 1, 1), None), + ("present", Date(2024, 1, 1), None), + ("invalid", None, ValueError), + ("20222", None, ValueError), + ("202222-20200", None, ValueError), + ("202222-12-20", None, ValueError), + ("2022-20-20", None, ValueError), + ], +) +@time_machine.travel("2024-01-01") +def test_get_date_object(date, expected_date_object, expected_error): + if expected_error: + with pytest.raises(expected_error): + dm.get_date_object(date) + else: + assert dm.get_date_object(date) == expected_date_object + + +@pytest.mark.parametrize( + "date, expected_date_string", + [ + (Date(2020, 1, 1), "Jan. 2020"), + (Date(2020, 2, 1), "Feb. 2020"), + (Date(2020, 3, 1), "Mar. 2020"), + (Date(2020, 4, 1), "Apr. 2020"), + (Date(2020, 5, 1), "May 2020"), + (Date(2020, 6, 1), "June 2020"), + (Date(2020, 7, 1), "July 2020"), + (Date(2020, 8, 1), "Aug. 2020"), + (Date(2020, 9, 1), "Sept. 2020"), + (Date(2020, 10, 1), "Oct. 2020"), + (Date(2020, 11, 1), "Nov. 2020"), + (Date(2020, 12, 1), "Dec. 2020"), + ], +) +def test_format_date(date, expected_date_string): + assert dm.format_date(date) == expected_date_string + + +def test_read_input_file(input_file_path): + # Update the auxiliary files if update_auxiliary_files is True + if update_auxiliary_files: + input_dictionary = { + "cv": { + "name": "John Doe", + }, + "design": { + "theme": "classic", + }, + } + + # dump the dictionary to a yaml file + yaml = ruamel.yaml.YAML() + yaml.dump(input_dictionary, input_file_path) + + data_model = dm.read_input_file(input_file_path) + + assert isinstance(data_model, dm.RenderCVDataModel) + + +def test_read_input_file_not_found(): + with pytest.raises(FileNotFoundError): + invalid_path = pathlib.Path("doesntexist.yaml") + dm.read_input_file(invalid_path) + + +def test_read_input_file_invalid_file(tmp_path): + invalid_file_path = tmp_path / "invalid.extension" + invalid_file_path.write_text("dummy content", encoding="utf-8") + with pytest.raises(ValueError): + dm.read_input_file(invalid_file_path) + + +def test_get_a_sample_data_model(): + data_model = dm.get_a_sample_data_model("John Doe") + assert isinstance(data_model, dm.RenderCVDataModel) + + +def test_generate_json_schema(): + schema = dm.generate_json_schema() + assert isinstance(schema, dict) + + +def test_generate_json_schema_file(tmp_path): + schema_file_path = tmp_path / "schema.json" + dm.generate_json_schema_file(schema_file_path) + + assert schema_file_path.exists() + + schema_text = schema_file_path.read_text(encoding="utf-8") + schema = json.loads(schema_text) + + assert isinstance(schema, dict) + + +def test_if_the_schema_is_the_latest(root_directory_path): + original_schema_file_path = root_directory_path / "schema.json" + original_schema_text = original_schema_file_path.read_text() + original_schema = json.loads(original_schema_text) + + new_schema = dm.generate_json_schema() + + assert original_schema == new_schema + + +@pytest.mark.parametrize( + "start_date, end_date, date, expected_date_string, expected_date_string_only_years," + " expected_time_span", + [ + ( + "2020-01-01", + "2021-01-01", + None, + "Jan. 2020 to Jan. 2021", + "2020 to 2021", + "1 year 1 month", + ), + ( + "2020-01", + "2021-01", + None, + "Jan. 2020 to Jan. 2021", + "2020 to 2021", + "1 year 1 month", + ), + ( + "2020-01", + "2021-01-01", + None, + "Jan. 2020 to Jan. 2021", + "2020 to 2021", + "1 year 1 month", + ), + ( + "2020-01-01", + "2021-01", + None, + "Jan. 2020 to Jan. 2021", + "2020 to 2021", + "1 year 1 month", + ), + ( + "2020-01-01", + None, + None, + "Jan. 2020 to present", + "2020 to present", + "4 years 1 month", + ), + ( + "2020-02-01", + "present", + None, + "Feb. 2020 to present", + "2020 to present", + "3 years 11 months", + ), + ("2020-01-01", "2021-01-01", "2023-02-01", "Feb. 2023", "Feb. 2023", ""), + ("2020", "2021", None, "2020 to 2021", "2020 to 2021", "1 year"), + ("2020", None, None, "2020 to present", "2020 to present", "4 years"), + ("2020-10-10", "2022", None, "Oct. 2020 to 2022", "2020 to 2022", "2 years"), + ( + "2020-10-10", + "2020-11-05", + None, + "Oct. 2020 to Nov. 2020", + "2020 to 2020", + "1 month", + ), + ("2022", "2023-10-10", None, "2022 to Oct. 2023", "2022 to 2023", "1 year"), + ( + "2020-01-01", + "present", + "My Custom Date", + "My Custom Date", + "My Custom Date", + "", + ), + ( + "2020-01-01", + None, + "My Custom Date", + "My Custom Date", + "My Custom Date", + "", + ), + ( + None, + None, + "My Custom Date", + "My Custom Date", + "My Custom Date", + "", + ), + ( + None, + "2020-01-01", + "My Custom Date", + "My Custom Date", + "My Custom Date", + "", + ), + (None, None, "2020-01-01", "Jan. 2020", "Jan. 2020", ""), + (None, None, None, "", "", ""), + ], +) +@time_machine.travel("2024-01-01") +def test_dates( + start_date, + end_date, + date, + expected_date_string, + expected_date_string_only_years, + expected_time_span, +): + entry_base = dm.EntryBase(start_date=start_date, end_date=end_date, date=date) + + assert entry_base.date_string == expected_date_string + assert entry_base.date_string_only_years == expected_date_string_only_years + assert entry_base.time_span_string == expected_time_span + + +@pytest.mark.parametrize( + "date, expected_date_string", + [ + ("2020-01-01", "Jan. 2020"), + ("2020-01", "Jan. 2020"), + ("2020", "2020"), + ], +) +def test_publication_dates(publication_entry, date, expected_date_string): + publication_entry["date"] = date + publication_entry = dm.PublicationEntry(**publication_entry) + assert publication_entry.date_string == expected_date_string + + +@pytest.mark.parametrize("date", ["aaa", None, "2025"]) +def test_invalid_publication_dates(publication_entry, date): + with pytest.raises(pydantic.ValidationError): + publication_entry["date"] = date + dm.PublicationEntry(**publication_entry) + + +@pytest.mark.parametrize( + "start_date, end_date, date", + [ + ("aaa", "2021-01-01", None), + ("2020-01-01", "aaa", None), + (None, "2020-01-01", None), + ("2023-01-01", "2021-01-01", None), + ("2999-01-01", None, None), + ("2020-01-01", "2999-01-01", None), + ("2022", "2021", None), + ("2021", "2060", None), + ("2025", "2021", None), + (None, None, "2028"), + ("2020-01-01", "invalid_end_date", None), + ("invalid_start_date", "2021-01-01", None), + ("2020-99-99", "2021-01-01", None), + ("2020-10-12", "2020-99-99", None), + ], +) +def test_invalid_dates(start_date, end_date, date): + with pytest.raises(pydantic.ValidationError): + dm.EntryBase(start_date=start_date, end_date=end_date, date=date) + + +@pytest.mark.parametrize( + "doi, expected_doi_url", + [ + ("10.1109/TASC.2023.3340648", "https://doi.org/10.1109/TASC.2023.3340648"), + ], +) +def test_doi_url(publication_entry, doi, expected_doi_url): + publication_entry["doi"] = doi + publication_entry = dm.PublicationEntry(**publication_entry) + assert publication_entry.doi_url == expected_doi_url + + +@pytest.mark.parametrize( + "doi", + ["aaa10.1109/TASC.2023.3340648", "aaa"], +) +def test_invalid_doi(publication_entry, doi): + with pytest.raises(pydantic.ValidationError): + publication_entry["doi"] = doi + dm.PublicationEntry(**publication_entry) + + +@pytest.mark.parametrize( + "network, username", + [("Mastodon", "invalidmastodon"), ("Mastodon", "@inva@l@id")], +) +def test_invalid_social_networks(network, username): + with pytest.raises(pydantic.ValidationError): + dm.SocialNetwork(network=network, username=username) + + +@pytest.mark.parametrize( + "network, username, expected_url", + [ + ("LinkedIn", "myusername", "https://linkedin.com/in/myusername"), + ("GitHub", "myusername", "https://github.com/myusername"), + ("Instagram", "myusername", "https://instagram.com/myusername"), + ("Orcid", "myusername", "https://orcid.org/myusername"), + ("Twitter", "myusername", "https://twitter.com/myusername"), + ("Mastodon", "@myusername", "https://mastodon.social/@myusername"), + ], +) +def test_social_network_url(network, username, expected_url): + social_network = dm.SocialNetwork(network=network, username=username) + assert str(social_network.url) == expected_url + + +@pytest.mark.parametrize( + "entry, expected_entry_type, expected_section_type", + [ + ( + "publication_entry", + "PublicationEntry", + dm.SectionWithPublicationEntries, + ), + ( + "experience_entry", + "ExperienceEntry", + dm.SectionWithExperienceEntries, + ), + ( + "education_entry", + "EducationEntry", + dm.SectionWithEducationEntries, + ), + ( + "normal_entry", + "NormalEntry", + dm.SectionWithNormalEntries, + ), + ("one_line_entry", "OneLineEntry", dm.SectionWithOneLineEntries), + ("text_entry", "TextEntry", dm.SectionWithTextEntries), + ], +) +def test_get_entry_and_section_type( + entry, expected_entry_type, expected_section_type, request +): + entry = request.getfixturevalue(entry) + entry_type, section_type = dm.get_entry_and_section_type(entry) + assert entry_type == expected_entry_type + assert section_type == expected_section_type + + # initialize the entry with the entry type + if not entry_type == "TextEntry": + entry = eval(f"dm.{entry_type}(**entry)") + entry_type, section_type = dm.get_entry_and_section_type(entry) + assert entry_type == expected_entry_type + assert section_type == expected_section_type + + +def test_sections( + education_entry, + experience_entry, + publication_entry, + normal_entry, + one_line_entry, + text_entry, +): + input = { + "name": "John Doe", + "sections": { + "arbitrary_title": [ + education_entry, + education_entry, + ], + "arbitrary_title_2": [ + experience_entry, + experience_entry, + ], + "arbitrary_title_3": [ + publication_entry, + publication_entry, + ], + "arbitrary_title_4": [ + normal_entry, + normal_entry, + ], + "arbitrary_title_5": [ + one_line_entry, + one_line_entry, + ], + "arbitrary_title_6": [ + text_entry, + text_entry, + ], + }, + } + + cv = dm.CurriculumVitae(**input) + assert len(cv.sections) == 6 + for section in cv.sections: + assert len(section.entries) == 2 + + +def test_sections_with_invalid_entries(): + input = {"name": "John Doe", "sections": dict()} + input["sections"]["section_title"] = [ + { + "this": "is", + "an": "invalid", + "entry": 10, + } + ] + with pytest.raises(pydantic.ValidationError): + dm.CurriculumVitae(**input) + + +@pytest.mark.parametrize( + "invalid_custom_theme_name", + [ + "pathdoesntexist", + "invalid_theme_name", + ], +) +def test_invalid_custom_theme(invalid_custom_theme_name): + with pytest.raises(pydantic.ValidationError): + dm.RenderCVDataModel( + **{ + "cv": {"name": "John Doe"}, + "design": {"theme": invalid_custom_theme_name}, + } + ) + + +def test_custom_theme_with_missing_files(tmp_path): + custom_theme_path = tmp_path / "customtheme" + custom_theme_path.mkdir() + with pytest.raises(pydantic.ValidationError): + os.chdir(tmp_path) + dm.RenderCVDataModel( + **{ # type: ignore + "cv": {"name": "John Doe"}, + "design": {"theme": "customtheme"}, + } + ) + + +def test_custom_theme(auxiliary_files_directory_path): + os.chdir( + auxiliary_files_directory_path + / "test_copy_theme_files_to_output_directory_custom_theme" + ) + data_model = dm.RenderCVDataModel( + **{ # type: ignore + "cv": {"name": "John Doe"}, + "design": {"theme": "dummytheme"}, + } + ) + + assert data_model.design.theme == "dummytheme" + + +def test_custom_theme_without_init_file(tmp_path, auxiliary_files_directory_path): + reference_custom_theme_path = ( + auxiliary_files_directory_path + / "test_copy_theme_files_to_output_directory_custom_theme" + / "dummytheme" + ) + + # copy the directory to tmp_path: + custom_theme_path = tmp_path / "dummytheme" + shutil.copytree(reference_custom_theme_path, custom_theme_path, dirs_exist_ok=True) + + # remove the __init__.py file: + init_file = custom_theme_path / "__init__.py" + init_file.unlink() + + os.chdir(tmp_path) + data_model = dm.RenderCVDataModel( + **{ # type: ignore + "cv": {"name": "John Doe"}, + "design": {"theme": "dummytheme"}, + } + ) + + assert data_model.design.theme == "dummytheme" diff --git a/tests/test_renderer.py b/tests/test_renderer.py new file mode 100644 index 0000000..3f4de94 --- /dev/null +++ b/tests/test_renderer.py @@ -0,0 +1,609 @@ +import math +import filecmp +import shutil +import os +import pathlib + +import pytest +import jinja2 +import time_machine +import pypdf + +from rendercv import renderer as r +from rendercv import data_models as dm + +from .conftest import update_auxiliary_files, folder_name_dictionary + + +def test_latex_file_class(tmp_path, rendercv_data_model, jinja2_environment): + latex_file = r.LaTeXFile(rendercv_data_model, jinja2_environment) + latex_file.get_latex_code() + latex_file.generate_latex_file(tmp_path / "test.tex") + + +def test_markdown_file_class(tmp_path, rendercv_data_model, jinja2_environment): + latex_file = r.MarkdownFile(rendercv_data_model, jinja2_environment) + latex_file.get_markdown_code() + latex_file.generate_markdown_file(tmp_path / "test.tex") + + +@pytest.mark.parametrize( + "string, expected_string", + [ + ("My Text", "My Text"), + ("My # Text", "My \\# Text"), + ("My % Text", "My \\% Text"), + ("My & Text", "My \\& Text"), + ("My ~ Text", "My \\textasciitilde{} Text"), + ("##%%&&~~", "\\#\\#\\%\\%\\&\\&\\textasciitilde{}\\textasciitilde{}"), + ( + ( + "[link](you shouldn't escape whatever is in here & % # ~) [second" + " link](https://myurl.com)" + ), + ( + "[link](you shouldn't escape whatever is in here & % # ~) [second" + " link](https://myurl.com)" + ), + ), + ], +) +def test_escape_latex_characters(string, expected_string): + assert r.escape_latex_characters(string) == expected_string + + +@pytest.mark.parametrize( + "markdown_string, expected_latex_string", + [ + ("My Text", "My Text"), + ("**My** Text", "\\textbf{My} Text"), + ("*My* Text", "\\textit{My} Text"), + ("***My*** Text", "\\textit{\\textbf{My}} Text"), + ("[My](https://myurl.com) Text", "\\href{https://myurl.com}{My} Text"), + ("`My` Text", "`My` Text"), + ( + "[**My** *Text* ***Is*** `Here`](https://myurl.com)", + ( + "\\href{https://myurl.com}{\\textbf{My} \\textit{Text}" + " \\textit{\\textbf{Is}} `Here`}" + ), + ), + ], +) +def test_markdown_to_latex(markdown_string, expected_latex_string): + assert r.markdown_to_latex(markdown_string) == expected_latex_string + + +def test_transform_markdown_sections_to_latex_sections(rendercv_data_model): + r.transform_markdown_sections_to_latex_sections( + rendercv_data_model.cv.sections_input + ) + assert isinstance(rendercv_data_model, dm.RenderCVDataModel) + assert rendercv_data_model.cv.name == rendercv_data_model.cv.name + assert rendercv_data_model.design == rendercv_data_model.design + + +@pytest.mark.parametrize( + "string, placeholders, expected_string", + [ + ("Hello, {name}!", {"{name}": None}, "Hello, None!"), + ( + "{greeting}, {name}!", + {"{greeting}": "Hello", "{name}": "World"}, + "Hello, World!", + ), + ("No placeholders here.", {}, "No placeholders here."), + ( + "{missing} placeholder.", + {"{not_missing}": "value"}, + "{missing} placeholder.", + ), + ("", {"{placeholder}": "value"}, ""), + ], +) +def test_replace_placeholders_with_actual_values(string, placeholders, expected_string): + result = r.replace_placeholders_with_actual_values(string, placeholders) + assert result == expected_string + + +@pytest.mark.parametrize( + "value, something, match_str, expected", + [ + ("Hello World", "textbf", None, "\\textbf{Hello World}"), + ("Hello World", "textbf", "World", "Hello \\textbf{World}"), + ("Hello World", "textbf", "Universe", "Hello World"), + ("", "textbf", "Universe", ""), + ("Hello World", "textbf", "", "Hello World"), + ], +) +def test_make_matched_part_something(value, something, match_str, expected): + result = r.make_matched_part_something(value, something, match_str) + assert result == expected + + +@pytest.mark.parametrize( + "value, match_str, expected", + [ + ("Hello World", None, "\\textbf{Hello World}"), + ("Hello World", "World", "Hello \\textbf{World}"), + ("Hello World", "Universe", "Hello World"), + ("", "Universe", ""), + ("Hello World", "", "Hello World"), + ], +) +def test_make_matched_part_bold(value, match_str, expected): + result = r.make_matched_part_bold(value, match_str) + assert result == expected + + +@pytest.mark.parametrize( + "value, match_str, expected", + [ + ("Hello World", None, "\\underline{Hello World}"), + ("Hello World", "World", "Hello \\underline{World}"), + ("Hello World", "Universe", "Hello World"), + ("", "Universe", ""), + ("Hello World", "", "Hello World"), + ], +) +def test_make_matched_part_underlined(value, match_str, expected): + result = r.make_matched_part_underlined(value, match_str) + assert result == expected + + +@pytest.mark.parametrize( + "value, match_str, expected", + [ + ("Hello World", None, "\\textit{Hello World}"), + ("Hello World", "World", "Hello \\textit{World}"), + ("Hello World", "Universe", "Hello World"), + ("", "Universe", ""), + ("Hello World", "", "Hello World"), + ], +) +def test_make_matched_part_italic(value, match_str, expected): + result = r.make_matched_part_italic(value, match_str) + assert result == expected + + +@pytest.mark.parametrize( + "value, match_str, expected", + [ + ("Hello World", None, "\\mbox{Hello World}"), + ("Hello World", "World", "Hello \\mbox{World}"), + ("Hello World", "Universe", "Hello World"), + ("", "Universe", ""), + ("Hello World", "", "Hello World"), + ], +) +def test_make_matched_part_non_line_breakable(value, match_str, expected): + result = r.make_matched_part_non_line_breakable(value, match_str) + assert result == expected + + +@pytest.mark.parametrize( + "name, expected", + [ + ("John Doe", "J. Doe"), + ("John Jacob Jingleheimer Schmidt", "J. J. J. Schmidt"), + ("SingleName", "SingleName"), + ("", ""), + (None, ""), + ], +) +def test_abbreviate_name(name, expected): + result = r.abbreviate_name(name) + assert result == expected + + +@pytest.mark.parametrize( + "length, divider, expected", + [ + ("10pt", 2, "5.0pt"), + ("15cm", 3, "5.0cm"), + ("20mm", 4, "5.0mm"), + ("25ex", 5, "5.0ex"), + ("30em", 6, "5.0em"), + ("10pt", 3, "3.33pt"), + ("10pt", 4, "2.5pt"), + ("0pt", 1, "0.0pt"), + ], +) +def test_divide_length_by(length, divider, expected): + result = r.divide_length_by(length, divider) + assert math.isclose( + float(result[:-2]), float(expected[:-2]), rel_tol=1e-2 + ), f"Expected {expected}, but got {result}" + + +@pytest.mark.parametrize( + "length, divider", + [("10pt", 0), ("10pt", -1), ("invalid", 4)], +) +def test_invalid_divide_length_by(length, divider): + with pytest.raises(ValueError): + r.divide_length_by(length, divider) + + +def test_get_an_item_with_a_specific_attribute_value(): + entry_objects = [ + dm.OneLineEntry( + name="Test1", + details="Test2", + ), + dm.OneLineEntry( + name="Test3", + details="Test4", + ), + ] + result = r.get_an_item_with_a_specific_attribute_value( + entry_objects, "name", "Test3" + ) + assert result == entry_objects[1] + result = r.get_an_item_with_a_specific_attribute_value( + entry_objects, "name", "DoesntExist" + ) + assert result is None + + with pytest.raises(AttributeError): + r.get_an_item_with_a_specific_attribute_value(entry_objects, "invalid", "Test5") + + +def test_setup_jinja2_environment(): + env = r.setup_jinja2_environment() + + # Check if the returned object is a jinja2.Environment instance + assert isinstance(env, jinja2.Environment) + + # Check if the custom delimiters are correctly set + assert env.block_start_string == "((*" + assert env.block_end_string == "*))" + assert env.variable_start_string == "<<" + assert env.variable_end_string == ">>" + assert env.comment_start_string == "((#" + assert env.comment_end_string == "#))" + + # Check if the custom filters are correctly set + assert "make_it_bold" in env.filters + assert "make_it_underlined" in env.filters + assert "make_it_italic" in env.filters + assert "make_it_nolinebreak" in env.filters + assert "make_it_something" in env.filters + assert "divide_length_by" in env.filters + assert "abbreviate_name" in env.filters + assert "get_an_item_with_a_specific_attribute_value" in env.filters + + +@pytest.mark.parametrize( + "theme_name", + dm.available_themes, +) +@pytest.mark.parametrize( + "curriculum_vitae_data_model", + [ + "rendercv_empty_curriculum_vitae_data_model", + "rendercv_filled_curriculum_vitae_data_model", + ], +) +@time_machine.travel("2024-01-01") +def test_generate_latex_file( + tmp_path, + auxiliary_files_directory_path, + request, + theme_name, + curriculum_vitae_data_model, +): + reference_directory_path = ( + auxiliary_files_directory_path + / "test_generate_latex_file" + / f"{theme_name}_{folder_name_dictionary[curriculum_vitae_data_model]}" + ) + + cv_data_model = request.getfixturevalue(curriculum_vitae_data_model) + + file_name = f"{str(cv_data_model.name).replace(' ', '_')}_CV.tex" + output_file_path = tmp_path / "make_sure_it_generates_the_directory" / file_name + reference_file_path = reference_directory_path / file_name + + data_model = dm.RenderCVDataModel( + cv=cv_data_model, + design={"theme": theme_name}, + ) + r.generate_latex_file(data_model, tmp_path / "make_sure_it_generates_the_directory") + # Update the auxiliary files if update_auxiliary_files is True + if update_auxiliary_files: + r.generate_latex_file(data_model, reference_directory_path) + + assert filecmp.cmp(output_file_path, reference_file_path) + + +@pytest.mark.parametrize( + "theme_name", + dm.available_themes, +) +@pytest.mark.parametrize( + "curriculum_vitae_data_model", + [ + "rendercv_empty_curriculum_vitae_data_model", + "rendercv_filled_curriculum_vitae_data_model", + ], +) +@time_machine.travel("2024-01-01") +def test_generate_markdown_file( + tmp_path, + auxiliary_files_directory_path, + request, + theme_name, + curriculum_vitae_data_model, +): + reference_directory_path = ( + auxiliary_files_directory_path + / "test_generate_markdown_file" + / f"{theme_name}_{folder_name_dictionary[curriculum_vitae_data_model]}" + ) + + cv_data_model = request.getfixturevalue(curriculum_vitae_data_model) + + file_name = f"{str(cv_data_model.name).replace(' ', '_')}_CV.md" + output_file_path = tmp_path / "make_sure_it_generates_the_directory" / file_name + reference_file_path = reference_directory_path / file_name + + data_model = dm.RenderCVDataModel( + cv=cv_data_model, + ) + r.generate_markdown_file( + data_model, tmp_path / "make_sure_it_generates_the_directory" + ) + # Update the auxiliary files if update_auxiliary_files is True + if update_auxiliary_files: + r.generate_markdown_file(data_model, reference_directory_path) + + assert filecmp.cmp(output_file_path, reference_file_path) + + +@pytest.mark.parametrize( + "theme_name", + dm.available_themes, +) +def test_copy_theme_files_to_output_directory( + tmp_path, auxiliary_files_directory_path, theme_name +): + reference_directory_path = ( + auxiliary_files_directory_path / "test_copy_theme_files_to_output_directory" + ) + + r.copy_theme_files_to_output_directory(theme_name, tmp_path) + # Update the auxiliary files if update_auxiliary_files is True + if update_auxiliary_files: + reference_directory_path.mkdir(parents=True, exist_ok=True) + r.copy_theme_files_to_output_directory(theme_name, reference_directory_path) + + assert filecmp.dircmp(tmp_path, reference_directory_path).diff_files == [] + + +def test_copy_theme_files_to_output_directory_custom_theme( + tmp_path, auxiliary_files_directory_path +): + theme_name = "dummytheme" + + test_auxiliary_files_directory_path = ( + auxiliary_files_directory_path + / "test_copy_theme_files_to_output_directory_custom_theme" + ) + custom_theme_directory_path = test_auxiliary_files_directory_path / "dummytheme" + reference_directory_path = ( + test_auxiliary_files_directory_path / "theme_auxiliary_files" + ) + + # Update the auxiliary files if update_auxiliary_files is True + if update_auxiliary_files: + # create dummytheme: + if not custom_theme_directory_path.exists(): + custom_theme_directory_path.mkdir(parents=True, exist_ok=True) + + # create a txt file called test.txt in the custom theme directory: + pathlib.Path(custom_theme_directory_path / "EducationEntry.j2.tex").touch() + pathlib.Path(custom_theme_directory_path / "ExperienceEntry.j2.tex").touch() + pathlib.Path(custom_theme_directory_path / "Header.j2.tex").touch() + pathlib.Path(custom_theme_directory_path / "NormalEntry.j2.tex").touch() + pathlib.Path(custom_theme_directory_path / "OneLineEntry.j2.tex").touch() + pathlib.Path(custom_theme_directory_path / "Preamble.j2.tex").touch() + pathlib.Path(custom_theme_directory_path / "PublicationEntry.j2.tex").touch() + pathlib.Path(custom_theme_directory_path / "SectionBeginning.j2.tex").touch() + pathlib.Path(custom_theme_directory_path / "SectionEnding.j2.tex").touch() + pathlib.Path(custom_theme_directory_path / "TextEntry.j2.tex").touch() + pathlib.Path(custom_theme_directory_path / "theme_auxiliary_file.cls").touch() + pathlib.Path(custom_theme_directory_path / "theme_auxiliary_dir").mkdir( + exist_ok=True + ) + init_file = pathlib.Path(custom_theme_directory_path / "__init__.py") + + init_file.touch() + init_file.write_text( + "from typing import Literal\n\nimport pydantic\n\n\nclass" + " DummythemeThemeOptions(pydantic.BaseModel):\n theme:" + " Literal['dummytheme']\n" + ) + + # create reference_directory_path: + os.chdir(test_auxiliary_files_directory_path) + r.copy_theme_files_to_output_directory(theme_name, reference_directory_path) + + # change current working directory to the test_auxiliary_files_directory_path + os.chdir(test_auxiliary_files_directory_path) + + # copy the auxiliary theme files to tmp_path: + r.copy_theme_files_to_output_directory(theme_name, tmp_path) + + assert filecmp.dircmp(tmp_path, reference_directory_path).left_only == [] + assert filecmp.dircmp(tmp_path, reference_directory_path).right_only == [] + + +@pytest.mark.parametrize( + "theme_name", + dm.available_themes, +) +@pytest.mark.parametrize( + "curriculum_vitae_data_model", + [ + "rendercv_empty_curriculum_vitae_data_model", + "rendercv_filled_curriculum_vitae_data_model", + ], +) +@time_machine.travel("2024-01-01") +def test_generate_latex_file_and_copy_theme_files( + tmp_path, + auxiliary_files_directory_path, + request, + theme_name, + curriculum_vitae_data_model, +): + reference_directory_path = ( + auxiliary_files_directory_path + / "test_generate_latex_file_and_copy_theme_files" + / f"{theme_name}_{folder_name_dictionary[curriculum_vitae_data_model]}" + ) + + data_model = dm.RenderCVDataModel( + cv=request.getfixturevalue(curriculum_vitae_data_model), + design={"theme": theme_name}, + ) + r.generate_latex_file_and_copy_theme_files(data_model, tmp_path) + # Update the auxiliary files if update_auxiliary_files is True + if update_auxiliary_files: + r.generate_latex_file_and_copy_theme_files(data_model, reference_directory_path) + + assert filecmp.dircmp(tmp_path, reference_directory_path).left_only == [] + assert filecmp.dircmp(tmp_path, reference_directory_path).right_only == [] + + +@pytest.mark.parametrize( + "theme_name", + dm.available_themes, +) +@pytest.mark.parametrize( + "curriculum_vitae_data_model", + [ + "rendercv_empty_curriculum_vitae_data_model", + "rendercv_filled_curriculum_vitae_data_model", + ], +) +@time_machine.travel("2024-01-01") +def test_latex_to_pdf( + tmp_path, + request, + auxiliary_files_directory_path, + theme_name, + curriculum_vitae_data_model, +): + latex_sources_path = ( + auxiliary_files_directory_path + / "test_generate_latex_file_and_copy_theme_files" + / f"{theme_name}_{folder_name_dictionary[curriculum_vitae_data_model]}" + ) + reference_directory_path = ( + auxiliary_files_directory_path + / "test_latex_to_pdf" + / f"{theme_name}_{folder_name_dictionary[curriculum_vitae_data_model]}" + ) + + cv_data_model = request.getfixturevalue(curriculum_vitae_data_model) + file_name_stem = f"{str(cv_data_model.name).replace(' ', '_')}_CV" + + # Update the auxiliary files if update_auxiliary_files is True + if update_auxiliary_files: + # copy the latex sources to the reference_directory_path + shutil.copytree( + latex_sources_path, reference_directory_path, dirs_exist_ok=True + ) + + # convert the latex code to a pdf + reference_pdf_file_path = r.latex_to_pdf( + reference_directory_path / f"{file_name_stem}.tex" + ) + + # remove the latex sources from the reference_directory_path, but keep the pdf + for file in reference_directory_path.iterdir(): + if file.is_file() and file.suffix != ".pdf": + file.unlink() + + # copy the latex sources to the tmp_path + shutil.copytree(latex_sources_path, tmp_path, dirs_exist_ok=True) + + # convert the latex code to a pdf + reference_pdf_file_path = reference_directory_path / f"{file_name_stem}.pdf" + output_file_path = r.latex_to_pdf(tmp_path / f"{file_name_stem}.tex") + + text1 = pypdf.PdfReader(output_file_path).pages[0].extract_text() + text2 = pypdf.PdfReader(reference_pdf_file_path).pages[0].extract_text() + assert text1 == text2 + + +def test_latex_to_pdf_invalid_latex_file(): + with pytest.raises(FileNotFoundError): + file_path = pathlib.Path("file_doesnt_exist.tex") + r.latex_to_pdf(file_path) + + +@pytest.mark.parametrize( + "theme_name", + dm.available_themes, +) +@pytest.mark.parametrize( + "curriculum_vitae_data_model", + [ + "rendercv_empty_curriculum_vitae_data_model", + "rendercv_filled_curriculum_vitae_data_model", + ], +) +@time_machine.travel("2024-01-01") +def test_markdown_to_html( + tmp_path, + request, + auxiliary_files_directory_path, + theme_name, + curriculum_vitae_data_model, +): + markdown_sources_path = ( + auxiliary_files_directory_path + / "test_generate_markdown_file" + / f"{theme_name}_{folder_name_dictionary[curriculum_vitae_data_model]}" + ) + reference_directory = ( + auxiliary_files_directory_path + / "test_markdown_to_html" + / f"{theme_name}_{folder_name_dictionary[curriculum_vitae_data_model]}" + ) + + cv_data_model = request.getfixturevalue(curriculum_vitae_data_model) + file_name_stem = f"{str(cv_data_model.name).replace(' ', '_')}_CV" + + # Update the auxiliary files if update_auxiliary_files is True + if update_auxiliary_files: + # copy the markdown sources to the reference_directory + shutil.copytree(markdown_sources_path, reference_directory, dirs_exist_ok=True) + + # convert markdown to html + r.markdown_to_html(reference_directory / f"{file_name_stem}.md") + + # remove the markdown sources from the reference_directory + for file in reference_directory.iterdir(): + if file.is_file() and file.suffix != ".html": + file.unlink() + + # copy the markdown sources to the tmp_path + shutil.copytree(markdown_sources_path, tmp_path, dirs_exist_ok=True) + + # convert markdown to html + output_file_path = r.markdown_to_html(tmp_path / f"{file_name_stem}.md") + reference_file_path = ( + reference_directory / f"{file_name_stem}_PASTETOGRAMMARLY.html" + ) + + assert filecmp.cmp(output_file_path, reference_file_path) + + +def test_markdown_to_html_invalid_markdown_file(): + with pytest.raises(FileNotFoundError): + file_path = pathlib.Path("file_doesnt_exist.md") + r.markdown_to_html(file_path) diff --git a/tests/test_rendering.py b/tests/test_rendering.py deleted file mode 100644 index 61fea74..0000000 --- a/tests/test_rendering.py +++ /dev/null @@ -1,303 +0,0 @@ -import unittest -import os -from datetime import date -import shutil - -from rendercv import rendering, data_model - - -class TestRendering(unittest.TestCase): - def test_markdown_to_latex(self): - input = "[link](www.example.com)" - expected = r"\href{www.example.com}{link}" - output = rendering.markdown_to_latex(input) - with self.subTest(msg="only one link"): - self.assertEqual(output, expected) - - input = "[link](www.example.com) and [link2](www.example2.com)" - expected = ( - r"\href{www.example.com}{link} and" r" \href{www.example2.com}{link2}" - ) - output = rendering.markdown_to_latex(input) - with self.subTest(msg="two links"): - self.assertEqual(output, expected) - - input = "[**link**](www.example.com)" - expected = r"\href{www.example.com}{\textbf{link}}" - output = rendering.markdown_to_latex(input) - with self.subTest(msg="bold link"): - self.assertEqual(output, expected) - - input = "[*link*](www.example.com)" - expected = r"\href{www.example.com}{\textit{link}}" - output = rendering.markdown_to_latex(input) - with self.subTest(msg="italic link"): - self.assertEqual(output, expected) - - input = "[*link*](www.example.com) and [**link2**](www.example2.com)" - expected = ( - r"\href{www.example.com}{\textit{link}} and" - r" \href{www.example2.com}{\textbf{link2}}" - ) - output = rendering.markdown_to_latex(input) - with self.subTest(msg="italic and bold links"): - self.assertEqual(output, expected) - - input = "**bold**, *italic*, and [link](www.example.com)" - expected = ( - r"\textbf{bold}, \textit{italic}, and" r" \href{www.example.com}{link}" - ) - output = rendering.markdown_to_latex(input) - with self.subTest(msg="bold, italic, and link"): - self.assertEqual(output, expected) - - # invalid input: - input = 20 - with self.subTest(msg="float input"): - with self.assertRaises(ValueError): - rendering.markdown_to_latex(input) # type: ignore - - def test_markdown_link_to_url(self): - input = "[link](www.example.com)" - expected = "www.example.com" - output = rendering.markdown_link_to_url(input) - with self.subTest(msg="only one link"): - self.assertEqual(output, expected) - - input = "[**link**](www.example.com)" - expected = "www.example.com" - output = rendering.markdown_link_to_url(input) - with self.subTest(msg="bold link"): - self.assertEqual(output, expected) - - input = "[*link*](www.example.com)" - expected = "www.example.com" - output = rendering.markdown_link_to_url(input) - with self.subTest(msg="italic link"): - self.assertEqual(output, expected) - - # invalid input: - input = 20 - with self.subTest(msg="float input"): - with self.assertRaises(ValueError): - rendering.markdown_link_to_url(input) # type: ignore - - input = "not a markdown link" - with self.subTest(msg="invalid input"): - with self.assertRaises(ValueError): - rendering.markdown_link_to_url(input) - - input = "[]()" - with self.subTest(msg="empty link"): - with self.assertRaises(ValueError): - rendering.markdown_link_to_url(input) - - def test_make_it_something(self): - # invalid input: - input = "test" - something = "haha" - result = rendering.make_it_something(input, something) - with self.subTest(msg="match_str is none"): - self.assertEqual(result, "\\haha{test}") - - result = rendering.make_it_something(input, something, match_str="te") - with self.subTest(msg="match_str is not none"): - self.assertEqual(result, "\\haha{te}st") - - def test_make_it_bold(self): - input = "some text" - expected = r"\textbf{some text}" - output = rendering.make_it_bold(input) - with self.subTest(msg="without match_str input"): - self.assertEqual(output, expected) - - match_str = "text" - expected = r"some \textbf{text}" - output = rendering.make_it_bold(input, match_str) - with self.subTest(msg="with match_str input"): - self.assertEqual(output, expected) - - match_str = 2423 - with self.subTest(msg="invalid match_str input"): - with self.assertRaises(ValueError): - rendering.make_it_bold(input, match_str) # type: ignore - - input = 20 - with self.subTest(msg="float input"): - with self.assertRaises(ValueError): - rendering.make_it_bold(input) # type: ignore - - def test_make_it_underlined(self): - input = "some text" - expected = r"\underline{some text}" - output = rendering.make_it_underlined(input) - with self.subTest(msg="without match_str input"): - self.assertEqual(output, expected) - - input = "some text" - match_str = "text" - expected = r"some \underline{text}" - output = rendering.make_it_underlined(input, match_str) - with self.subTest(msg="with match_str input"): - self.assertEqual(output, expected) - - input = 20 - with self.subTest(msg="float input"): - with self.assertRaises(ValueError): - rendering.make_it_underlined(input) # type: ignore - - def test_make_it_italic(self): - input = "some text" - expected = r"\textit{some text}" - output = rendering.make_it_italic(input) - with self.subTest(msg="without match_str input"): - self.assertEqual(output, expected) - - input = "some text" - match_str = "text" - expected = r"some \textit{text}" - output = rendering.make_it_italic(input, match_str) - with self.subTest(msg="with match_str input"): - self.assertEqual(output, expected) - - input = 20 - with self.subTest(msg="float input"): - with self.assertRaises(ValueError): - rendering.make_it_italic(input) # type: ignore - - def test_divide_length_by(self): - lengths = [ - "10cm", - "10.24in", - "10 pt", - "10.24 mm", - "10.24 em", - "1024 ex", - ] - divider = 10 - expected = [ - "1.0 cm", - "1.024 in", - "1.0 pt", - "1.024 mm", - "1.024 em", - "102.4 ex", - ] - for length, exp in zip(lengths, expected): - with self.subTest(length=length, msg="valid input"): - self.assertEqual(rendering.divide_length_by(length, divider), exp) - - def test_get_today(self): - expected = date.today().strftime("%B %Y") - result = rendering.get_today() - self.assertEqual(expected, result, msg="Today's date is not correct.") - - def test_get_path_to_font_directory(self): - font_name = "test" - expected = os.path.join( - os.path.dirname(os.path.dirname(__file__)), - "rendercv", - "templates", - "fonts", - font_name, - ) - result = rendering.get_path_to_font_directory(font_name) - self.assertEqual(expected, result, msg="Font directory path is not correct.") - - def test_render_template(self): - # Read the reference YAML file: - input_file_path = os.path.join( - os.path.dirname(__file__), - "reference_files", - "John_Doe_CV_yaml_reference.yaml", - ) - data = data_model.read_input_file(input_file_path) - output_file_path = rendering.render_template( - data=data, output_path=os.path.dirname(__file__) - ) - - # Check if the output file exists: - self.assertTrue( - os.path.exists(output_file_path), msg="LaTeX file couldn't be generated." - ) - - # Compare the output file with the reference file: - reference_file_path = os.path.join( - os.path.dirname(__file__), - "reference_files", - "John_Doe_CV_tex_reference.tex", - ) - with open(output_file_path, "r") as file: - output = file.read() - with open(reference_file_path, "r") as file: - reference = file.read() - reference = reference.replace("REPLACETHISWITHTODAY", rendering.get_today()) - - self.assertEqual( - output, reference, msg="LaTeX file didn't match the reference." - ) - - # Check if the font directory exists: - output_folder_path = os.path.dirname(output_file_path) - font_directory_path = os.path.join(output_folder_path, "fonts") - self.assertTrue( - os.path.exists(font_directory_path), msg="Font directory doesn't exist." - ) - - required_files = [ - f"{data.design.font}-Italic.ttf", - f"{data.design.font}-Regular.ttf", - f"{data.design.font}-Bold.ttf", - f"{data.design.font}-BoldItalic.ttf", - ] - font_files = os.listdir(font_directory_path) - for required_file in required_files: - with self.subTest(required_file=required_file): - self.assertIn( - required_file, - font_files, - msg=f"Font file ({required_file}) is missing.", - ) - - # Remove the output directory: - shutil.rmtree(output_folder_path) - - def test_run_latex(self): - latex_file_path = os.path.join( - os.path.dirname(__file__), - "reference_files", - "John_Doe_CV_tex_reference.tex", - ) - - with self.subTest(msg="Existent file name"): - pdf_file = rendering.run_latex(latex_file_path) - - # Check if the output file exists: - self.assertTrue( - os.path.exists(pdf_file), msg="PDF file couldn't be generated." - ) - - # Compare the pdf file with the reference pdf file: - reference_pdf_file = pdf_file.replace( - "_tex_reference.pdf", "_pdf_reference.pdf" - ) - reference_pdf_file_size = os.path.getsize(reference_pdf_file) - pdf_file_size = os.path.getsize(pdf_file) - - # Remove the output file: - os.remove(pdf_file) - - ratio = min(reference_pdf_file_size, pdf_file_size) / max( - reference_pdf_file_size, pdf_file_size - ) - self.assertTrue(ratio > 0.98, msg="PDF file didn't match the reference.") - - nonexistent_latex_file_path = os.path.join( - os.path.dirname(__file__), "reference_files", "nonexistent.tex" - ) - - with self.subTest(msg="Nonexistent file name"): - with self.assertRaises( - FileNotFoundError, msg="File not found error didn't raise." - ): - rendering.run_latex(nonexistent_latex_file_path)