Coverage for rendercv/api/functions.py: 78%
9 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-26 00:25 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-26 00:25 +0000
1"""
2The `rendercv.api.functions` package contains the basic functions that are used to
3interact with the RenderCV.
4"""
6import pydantic
8from .. import data, renderer
11def create_contents_of_a_typst_file(
12 yaml_file_as_string: str,
13) -> str | list[dict]:
14 """
15 Validate the input file given as a string, generate a Typst file and return it as a
16 string. If there are any validation errors, return them as a list of dictionaries.
18 Args:
19 yaml_file_as_string: The input file as a string.
21 Returns:
22 The Typst file as a string or a list of dictionaries that contain the error
23 messages, locations, and the input values.
24 """
26 try:
27 input_file_as_a_dict = data.read_a_yaml_file(yaml_file_as_string)
28 data_model = data.validate_input_dictionary_and_return_the_data_model(
29 input_file_as_a_dict,
30 )
31 except pydantic.ValidationError as e:
32 return data.parse_validation_errors(e)
34 return renderer.create_contents_of_a_typst_file(data_model)