refactor: do not make ContentField inherit from Content

This commit is contained in:
Corentin 2024-05-21 23:52:51 +02:00
parent 35454bfc0f
commit 77c30117ed
4 changed files with 12 additions and 8 deletions

View File

@ -26,13 +26,17 @@ class Content(Generic[TData]):
return str(self.__data) return str(self.__data)
class ContentField(Content[Any]): class ContentField:
def __init__(self, content_path: Path, value: Any) -> None:
self.__content_path = content_path
self.__value = value
def __getitem__(self, key: Any) -> Any: def __getitem__(self, key: Any) -> Any:
return ContentField(self.path, self.data.get(key), self.language) return ContentField(self.__content_path, self.__value.get(key))
def __iter__(self) -> Iterator[Any]: def __iter__(self) -> Iterator[Any]:
for it in self.data: for it in self.__value:
yield ContentField(self.path, it, self.language) yield ContentField(self.__content_path, it)
def __str__(self) -> str: def __str__(self) -> str:
return str(self.data) return str(self.__value)

View File

@ -27,4 +27,4 @@ class _MarkdownDocument(Content[str]):
@property @property
def meta(self) -> Any: def meta(self) -> Any:
return ContentField(self.__content.path, self.__markdown.Meta, self.__content.language) # type: ignore return ContentField(self.__content.path, self.__markdown.Meta) # type: ignore

View File

@ -20,4 +20,4 @@ def _load_yaml(content: Any) -> ContentField:
assert isinstance(data, str) assert isinstance(data, str)
return ContentField(content.path, load(data, Loader), content.language) return ContentField(content.path, load(data, Loader))

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PROJECT VERSION\n" "Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-05-21 23:42+0200\n" "POT-Creation-Date: 2024-05-21 23:52+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: fr\n" "Language: fr\n"