From 77c30117ed9e69fe40904879503e1cf64a1797a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20S=C3=A9chet?= Date: Tue, 21 May 2024 23:52:51 +0200 Subject: [PATCH] refactor: do not make ContentField inherit from Content --- jweb/content.py | 14 +++++++++----- jweb/extensions/markdown.py | 2 +- jweb/extensions/yaml.py | 2 +- tests/test_context/locale/fr/LC_MESSAGES/tests.po | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/jweb/content.py b/jweb/content.py index 8b3b71e..5b3a18d 100644 --- a/jweb/content.py +++ b/jweb/content.py @@ -26,13 +26,17 @@ class Content(Generic[TData]): 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: - return ContentField(self.path, self.data.get(key), self.language) + return ContentField(self.__content_path, self.__value.get(key)) def __iter__(self) -> Iterator[Any]: - for it in self.data: - yield ContentField(self.path, it, self.language) + for it in self.__value: + yield ContentField(self.__content_path, it) def __str__(self) -> str: - return str(self.data) + return str(self.__value) diff --git a/jweb/extensions/markdown.py b/jweb/extensions/markdown.py index 76d9cf1..8b6ac86 100644 --- a/jweb/extensions/markdown.py +++ b/jweb/extensions/markdown.py @@ -27,4 +27,4 @@ class _MarkdownDocument(Content[str]): @property 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 diff --git a/jweb/extensions/yaml.py b/jweb/extensions/yaml.py index c9bd46f..f649c48 100644 --- a/jweb/extensions/yaml.py +++ b/jweb/extensions/yaml.py @@ -20,4 +20,4 @@ def _load_yaml(content: Any) -> ContentField: assert isinstance(data, str) - return ContentField(content.path, load(data, Loader), content.language) + return ContentField(content.path, load(data, Loader)) diff --git a/tests/test_context/locale/fr/LC_MESSAGES/tests.po b/tests/test_context/locale/fr/LC_MESSAGES/tests.po index 1069f84..bbb7231 100644 --- a/tests/test_context/locale/fr/LC_MESSAGES/tests.po +++ b/tests/test_context/locale/fr/LC_MESSAGES/tests.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\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" "Last-Translator: FULL NAME \n" "Language: fr\n"