Move last_updated_date_style and page_numbering_style fields to locale_catalog field (#270)

* Move last_updated_date_style and page_numbering_style fields to locale_catalog field (#148)

* update testdata

* fix an example

* update locale catalog validator

* set update_testdata to False

* update
This commit is contained in:
Sina Atalay
2024-12-25 17:25:20 -05:00
committed by GitHub
parent 1186d4ca41
commit 16dc64ff68
36 changed files with 81 additions and 90 deletions

View File

@@ -281,9 +281,7 @@ design:
color: blue
disable_external_link_icons: false
disable_last_updated_date: false
last_updated_date_style: Last updated in TODAY
disable_page_numbering: false
page_numbering_style: NAME - Page PAGE_NUMBER of TOTAL_PAGES
font: Source Sans 3
font_size: 10pt
header_font_size: "30 pt"
@@ -325,7 +323,9 @@ Here is an example:
locale_catalog:
phone_number_format: national # (1)!
date_style: "MONTH_ABBREVIATION YEAR" # (2)!
abbreviations_for_months: # (3)!
last_updated_date_style: Last updated in TODAY # (3)!
page_numbering_style: NAME - Page PAGE_NUMBER of TOTAL_PAGES # (4)!
abbreviations_for_months:
- Jan
- Feb
- Mar
@@ -338,7 +338,7 @@ locale_catalog:
- Oct
- Nov
- Dec
full_names_of_months: # (4)!
full_names_of_months:
- January
- February
- March
@@ -351,24 +351,18 @@ locale_catalog:
- October
- November
- December
month: month # (5)!
months: months # (6)!
year: year # (7)!
years: years # (8)!
present: present # (9)!
to: to # (10)!
month: month
months: months
year: year
years: years
present: present
to: to
```
1. The available phone number formats are: `national`, `international`, and `E164`.
2. The `MONTH_ABBREVIATION` and `YEAR` are placeholders. The available placeholders are: `FULL_MONTH_NAME`, `MONTH_ABBREVIATION`, `MONTH`, `MONTH_IN_TWO_DIGITS`, `YEAR`, and `YEAR_IN_TWO_DIGITS`.
3. The translation of the month abbreviations.
4. The translation of the full month names.
5. The translation of the word "month".
6. The translation of the word "months".
7. The translation of the word "year".
8. The translation of the word "years".
9. The translation of the word "present".
10. The translation of the word "to".
3. The available placeholders are: `TODAY`, which prints the today's date with `locale_catalog.date_style`.
4. The available placeholders are: `NAME`, `PAGE_NUMBER`, `TOTAL_PAGES`, and `TODAY`.
## "`rendercv_settings`" field

View File

@@ -111,9 +111,7 @@ design:
color: '#004f90'
disable_external_link_icons: false
disable_page_numbering: false
page_numbering_style: NAME - Page PAGE_NUMBER of TOTAL_PAGES
disable_last_updated_date: false
last_updated_date_style: Last updated in TODAY
header_font_size: 30 pt
text_alignment: justified
seperator_between_connections: ''

View File

@@ -111,9 +111,7 @@ design:
color: black
disable_external_link_icons: true
disable_page_numbering: true
page_numbering_style: NAME - Page PAGE_NUMBER of TOTAL_PAGES
disable_last_updated_date: true
last_updated_date_style: Last updated in TODAY
header_font_size: 25 pt
text_alignment: left-aligned
seperator_between_connections: $|$

View File

@@ -111,9 +111,7 @@ design:
color: '#004f90'
disable_external_link_icons: false
disable_page_numbering: false
page_numbering_style: NAME - Page PAGE_NUMBER of TOTAL_PAGES
disable_last_updated_date: false
last_updated_date_style: Last updated in TODAY
header_font_size: 24 pt
text_alignment: justified
seperator_between_connections: ''

View File

@@ -16,6 +16,8 @@ class LocaleCatalog(RenderCVBaseModelWithoutExtraKeys):
updates the `locale_catalog` dictionary.
"""
model_config = pydantic.ConfigDict(validate_default=True)
phone_number_format: Optional[Literal["national", "international", "E164"]] = (
pydantic.Field(
default="national",
@@ -27,16 +29,36 @@ class LocaleCatalog(RenderCVBaseModelWithoutExtraKeys):
),
)
)
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\n- TODAY: Today's date"
' with `locale_catalog.date_style`\nThe default value is "NAME -'
' Page PAGE_NUMBER of TOTAL_PAGES".'
),
)
last_updated_date_style: str = pydantic.Field(
default="Last updated in TODAY",
title="Last Updated Date Style",
description=(
"The style of the last updated date. The following placeholders can be"
" used:\n- TODAY: Today's date with `locale_catalog.date_style`\nThe"
' default value is "Last updated in TODAY".'
),
)
date_style: Optional[str] = pydantic.Field(
default="MONTH_ABBREVIATION YEAR",
title="Date Style",
description=(
"The style of the date. The following placeholders can be used:\n-"
" FULL_MONTH_NAME: Full name of the month\n- MONTH_ABBREVIATION:"
"The style of the date. The following placeholders can be"
" used:\n-FULL_MONTH_NAME: Full name of the month\n- MONTH_ABBREVIATION:"
" Abbreviation of the month\n- MONTH: Month as a number\n-"
" MONTH_IN_TWO_DIGITS: Month as a number in two digits\n- YEAR: Year as a"
" number\n- YEAR_IN_TWO_DIGITS: Year as a number in two digits\nThe default"
' value is "MONTH_ABBREVIATION YEAR".'
" number\n- YEAR_IN_TWO_DIGITS: Year as a number in two digits\nThe"
' default value is "MONTH_ABBREVIATION YEAR".'
),
)
month: Optional[str] = pydantic.Field(

View File

@@ -35,15 +35,15 @@ class RenderCVDataModel(RenderCVBaseModelWithoutExtraKeys):
"The design information of the CV. The default is the classic theme."
),
)
locale_catalog: Optional[LocaleCatalog] = pydantic.Field(
default=None,
locale_catalog: LocaleCatalog = pydantic.Field(
default=LocaleCatalog(),
title="Locale Catalog",
description=(
"The locale catalog of the CV to allow the support of multiple languages."
),
)
rendercv_settings: Optional[RenderCVSettings] = pydantic.Field(
default=None,
rendercv_settings: RenderCVSettings = pydantic.Field(
default=RenderCVSettings(),
title="RenderCV Settings",
description="The settings of the RenderCV.",
)
@@ -67,15 +67,10 @@ class RenderCVDataModel(RenderCVBaseModelWithoutExtraKeys):
@pydantic.field_validator("locale_catalog")
@classmethod
def initialize_locale_catalog(
cls, locale_catalog: Optional[LocaleCatalog]
) -> Optional[LocaleCatalog]:
"""Even if the locale catalog is not provided, initialize it with the default
values."""
if locale_catalog is None:
LocaleCatalog()
return locale_catalog
def update_locale_catalog(cls, _) -> LocaleCatalog:
"""Update the output folder name in the RenderCV settings."""
# Somehow, we need this for `test_if_local_catalog_resets` to pass.
return LocaleCatalog()
rendercv_data_model_fields = tuple(RenderCVDataModel.model_fields.keys())

View File

@@ -21,12 +21,12 @@ file_path_placeholder_description = (
" NAME_IN_UPPER_SNAKE_CASE: The name of the CV owner in upper snake case\n-"
" NAME_IN_KEBAB_CASE: The name of the CV owner in kebab case\n-"
" NAME_IN_LOWER_KEBAB_CASE: The name of the CV owner in lower kebab case\n-"
" NAME_IN_UPPER_KEBAB_CASE: The name of the CV owner in upper kebab case\nThe"
" default value is an empty string.\n- FULL_MONTH_NAME: Full name of the month\n-"
" MONTH_ABBREVIATION: Abbreviation of the month\n- MONTH: Month as a number\n-"
" MONTH_IN_TWO_DIGITS: Month as a number in two digits\n- YEAR: Year as a number\n-"
" YEAR_IN_TWO_DIGITS: Year as a number in two digits\nThe default value is"
' "MONTH_ABBREVIATION YEAR".\nThe default value is null.'
" NAME_IN_UPPER_KEBAB_CASE: The name of the CV owner in upper kebab case\n-"
" FULL_MONTH_NAME: Full name of the month\n- MONTH_ABBREVIATION: Abbreviation of"
" the month\n- MONTH: Month as a number\n- MONTH_IN_TWO_DIGITS: Month as a number"
" in two digits\n- YEAR: Year as a number\n- YEAR_IN_TWO_DIGITS: Year as a number"
' in two digits\nThe default value is "MONTH_ABBREVIATION YEAR".\nThe default value'
" is null."
)
file_path_placeholder_description_without_default = (

View File

@@ -33,6 +33,7 @@ class TemplatedFile:
):
self.cv = data_model.cv
self.design = data_model.design
self.locale_catalog = data_model.locale_catalog
self.environment = environment
def template(
@@ -74,8 +75,9 @@ class TemplatedFile:
return template.render(
cv=self.cv,
design=self.design,
locale_catalog=self.locale_catalog,
entry=entry,
today=data.format_date(Date.today(), date_style="FULL_MONTH_NAME YEAR"),
today=data.format_date(Date.today()),
**kwargs,
)

View File

@@ -79,7 +79,7 @@
\makeatletter
\let\ps@customFooterStyle\ps@plain % Copy the plain style to customFooterStyle
\patchcmd{\ps@customFooterStyle}{\thepage}{
\color{gray}\textit{\small <<design.page_numbering_style|replace_placeholders_with_actual_values(page_numbering_style_placeholders)>>}
\color{gray}\textit{\small <<locale_catalog.page_numbering_style|replace_placeholders_with_actual_values(page_numbering_style_placeholders)>>}
}{}{} % replace number by desired string
\makeatother
\pagestyle{customFooterStyle}
@@ -183,7 +183,7 @@
\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{<<design.last_updated_date_style|replace_placeholders_with_actual_values(last_updated_date_style_placeholders)>>}\hspace{\widthof{<<design.last_updated_date_style|replace_placeholders_with_actual_values(last_updated_date_style_placeholders)>>}}
\small\color{gray}\textit{<<locale_catalog.last_updated_date_style|replace_placeholders_with_actual_values(last_updated_date_style_placeholders)>>}\hspace{\widthof{<<locale_catalog.last_updated_date_style|replace_placeholders_with_actual_values(last_updated_date_style_placeholders)>>}}
}}}%
}%
}%

View File

@@ -241,17 +241,6 @@ class ThemeOptions(RenderCVBaseModelWithoutExtraKeys):
" 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\n- TODAY: Today's month"
" and year (April 2024)\nThe default value is NAME - Page PAGE_NUMBER of"
" TOTAL_PAGES."
),
)
disable_last_updated_date: bool = pydantic.Field(
default=False,
title="Disable Last Updated Date",
@@ -260,15 +249,6 @@ class ThemeOptions(RenderCVBaseModelWithoutExtraKeys):
" shown in the header. The default value is false."
),
)
last_updated_date_style: str = pydantic.Field(
default="Last updated in TODAY",
title="Last Updated Date Style",
description=(
"The style of the last updated date. The following placeholders can be"
" used:\n- TODAY: Today's month and year (April 2024)\nThe default value is"
" Last updated in TODAY."
),
)
header_font_size: LaTeXDimension = pydantic.Field(
default="30 pt",
title="Header Font Size",

View File

@@ -79,7 +79,7 @@
\makeatletter
\let\ps@customFooterStyle\ps@plain % Copy the plain style to customFooterStyle
\patchcmd{\ps@customFooterStyle}{\thepage}{
\color{gray}\textit{\small <<design.page_numbering_style|replace_placeholders_with_actual_values(page_numbering_style_placeholders)>>}
\color{gray}\textit{\small <<locale_catalog.page_numbering_style|replace_placeholders_with_actual_values(page_numbering_style_placeholders)>>}
}{}{} % replace number by desired string
\makeatother
\pagestyle{customFooterStyle}
@@ -172,7 +172,7 @@
\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{<<design.last_updated_date_style|replace_placeholders_with_actual_values(last_updated_date_style_placeholders)>>}\hspace{\widthof{<<design.last_updated_date_style|replace_placeholders_with_actual_values(last_updated_date_style_placeholders)>>}}
\small\color{gray}\textit{<<locale_catalog.last_updated_date_style|replace_placeholders_with_actual_values(last_updated_date_style_placeholders)>>}\hspace{\widthof{<<locale_catalog.last_updated_date_style|replace_placeholders_with_actual_values(last_updated_date_style_placeholders)>>}}
}}}%
}%
}%

View File

@@ -79,7 +79,7 @@
\makeatletter
\let\ps@customFooterStyle\ps@plain % Copy the plain style to customFooterStyle
\patchcmd{\ps@customFooterStyle}{\thepage}{
\color{gray}\textit{\small <<design.page_numbering_style|replace_placeholders_with_actual_values(page_numbering_style_placeholders)>>}
\color{gray}\textit{\small <<locale_catalog.page_numbering_style|replace_placeholders_with_actual_values(page_numbering_style_placeholders)>>}
}{}{} % replace number by desired string
\makeatother
\pagestyle{customFooterStyle}
@@ -171,7 +171,7 @@
\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{<<design.last_updated_date_style|replace_placeholders_with_actual_values(last_updated_date_style_placeholders)>>}\hspace{\widthof{<<design.last_updated_date_style|replace_placeholders_with_actual_values(last_updated_date_style_placeholders)>>}}
\small\color{gray}\textit{<<locale_catalog.last_updated_date_style|replace_placeholders_with_actual_values(last_updated_date_style_placeholders)>>}\hspace{\widthof{<<locale_catalog.last_updated_date_style|replace_placeholders_with_actual_values(last_updated_date_style_placeholders)>>}}
}}}%
}%
}%

View File

@@ -741,7 +741,11 @@ def test_locale_catalog():
phone_number_format="international",
)
assert data_model.locale_catalog.model_dump() == locale_catalog.LOCALE_CATALOG
locale_catalog_as_dict = data_model.locale_catalog.model_dump()
del locale_catalog_as_dict["page_numbering_style"]
del locale_catalog_as_dict["last_updated_date_style"]
assert locale_catalog_as_dict == locale_catalog.LOCALE_CATALOG
def test_if_local_catalog_resets():
@@ -803,9 +807,10 @@ def test_create_a_sample_yaml_input_file(tmp_path):
assert yaml_contents == input_file_path.read_text(encoding="utf-8")
def test_default_input_file_doesnt_have_local_catalog():
@pytest.mark.skip("We want `rendercv_settings` to be in the input file for now.")
def test_default_input_file_doesnt_have_rendercv_settings():
yaml_contents = data.create_a_sample_yaml_input_file()
assert "locale_catalog" not in yaml_contents
assert "rendercv_settings" not in yaml_contents
@pytest.mark.parametrize(

View File

@@ -155,7 +155,7 @@
\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}}
\small\color{gray}\textit{Last updated in Jan 2024}\hspace{\widthof{Last updated in Jan 2024}}
}}}%
}%
}%

View File

@@ -155,7 +155,7 @@
\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}}
\small\color{gray}\textit{Last updated in Jan 2024}\hspace{\widthof{Last updated in Jan 2024}}
}}}%
}%
}%

View File

@@ -139,7 +139,7 @@
\LenToUnit{\paperwidth-2 cm-0 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}}
\small\color{gray}\textit{Last updated in Jan 2024}\hspace{\widthof{Last updated in Jan 2024}}
}}}%
}%
}%

View File

@@ -139,7 +139,7 @@
\LenToUnit{\paperwidth-2 cm-0 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}}
\small\color{gray}\textit{Last updated in Jan 2024}\hspace{\widthof{Last updated in Jan 2024}}
}}}%
}%
}%

View File

@@ -142,7 +142,7 @@
\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}}
\small\color{gray}\textit{Last updated in Jan 2024}\hspace{\widthof{Last updated in Jan 2024}}
}}}%
}%
}%

View File

@@ -142,7 +142,7 @@
\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}}
\small\color{gray}\textit{Last updated in Jan 2024}\hspace{\widthof{Last updated in Jan 2024}}
}}}%
}%
}%

View File

@@ -155,7 +155,7 @@
\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}}
\small\color{gray}\textit{Last updated in Jan 2024}\hspace{\widthof{Last updated in Jan 2024}}
}}}%
}%
}%

View File

@@ -155,7 +155,7 @@
\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}}
\small\color{gray}\textit{Last updated in Jan 2024}\hspace{\widthof{Last updated in Jan 2024}}
}}}%
}%
}%

View File

@@ -139,7 +139,7 @@
\LenToUnit{\paperwidth-2 cm-0 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}}
\small\color{gray}\textit{Last updated in Jan 2024}\hspace{\widthof{Last updated in Jan 2024}}
}}}%
}%
}%

View File

@@ -139,7 +139,7 @@
\LenToUnit{\paperwidth-2 cm-0 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}}
\small\color{gray}\textit{Last updated in Jan 2024}\hspace{\widthof{Last updated in Jan 2024}}
}}}%
}%
}%

View File

@@ -142,7 +142,7 @@
\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}}
\small\color{gray}\textit{Last updated in Jan 2024}\hspace{\widthof{Last updated in Jan 2024}}
}}}%
}%
}%

View File

@@ -142,7 +142,7 @@
\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}}
\small\color{gray}\textit{Last updated in Jan 2024}\hspace{\widthof{Last updated in Jan 2024}}
}}}%
}%
}%

View File

Binary file not shown.

View File

Binary file not shown.

View File

Binary file not shown.

View File

Binary file not shown.

View File

Binary file not shown.

View File

Binary file not shown.

View File

Binary file not shown.

Before

Width:  |  Height:  |  Size: 753 KiB

After

Width:  |  Height:  |  Size: 752 KiB

View File

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 45 KiB

View File

@@ -1,4 +1,3 @@
design:
theme: sb2nov
last_updated_date_style: theme - sb2nov