diff --git a/jweb/content.py b/jweb/content.py index 77aebf0..af57995 100644 --- a/jweb/content.py +++ b/jweb/content.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing import Any, Generic, Iterator, TypeVar +from typing import Generic, TypeVar TData = TypeVar("TData") @@ -26,24 +26,3 @@ class Content(Generic[TData]): if isinstance(self.__data, bytes): return self.__data.decode("utf-8") return str(self.__data) - - -class ContentField: - def __init__(self, owner_content_path: Path, value: Any) -> None: - self.__owner_content_path = owner_content_path - self.__value = value - - def __getitem__(self, key: Any) -> Any: - return ContentField(self.__owner_content_path, self.__value.get(key)) - - def __iter__(self) -> Iterator[Any]: - for it in self.__value: - yield ContentField(self.__owner_content_path, it) - - def __str__(self) -> str: - return str(self.__value) - - def as_path(self) -> Path: - if not isinstance(self.__value, (str, Path)): - raise ValueError("You can't use a field of type %s as a path", type(self.__value)) - return self.__owner_content_path.parent / str(self) diff --git a/jweb/context.py b/jweb/context.py index 9bf329d..a98c36e 100644 --- a/jweb/context.py +++ b/jweb/context.py @@ -10,7 +10,7 @@ from jinja2.environment import Environment from jinja2.loaders import FileSystemLoader from jinja2.runtime import Context as JinjaContext -from jweb.content import Content, ContentField +from jweb.content import Content _DEFAULT_LANGUAGE = "en" @@ -70,10 +70,7 @@ class Context: self.__render(source, self.__output_directory / output, **context) @pass_context - def __load(self, context: JinjaContext, path: str | Path | ContentField) -> Content[bytes]: - if isinstance(path, ContentField): - path = path.as_path() - + def __load(self, context: JinjaContext, path: str | Path) -> Content[bytes]: current_language = self.current_language if current_language: localized_path = self.__content_directory / current_language / path diff --git a/jweb/extensions/markdown.py b/jweb/extensions/markdown.py index 8b6ac86..0e64c1f 100644 --- a/jweb/extensions/markdown.py +++ b/jweb/extensions/markdown.py @@ -2,7 +2,7 @@ from typing import Any from markdown import Markdown -from jweb.content import Content, ContentField +from jweb.content import Content from jweb.context import Context @@ -27,4 +27,4 @@ class _MarkdownDocument(Content[str]): @property def meta(self) -> Any: - return ContentField(self.__content.path, self.__markdown.Meta) # type: ignore + return self.__markdown.Meta # type: ignore diff --git a/jweb/extensions/yaml.py b/jweb/extensions/yaml.py index f649c48..0a2e50a 100644 --- a/jweb/extensions/yaml.py +++ b/jweb/extensions/yaml.py @@ -2,7 +2,7 @@ from typing import Any from yaml import Loader, load -from jweb.content import Content, ContentField +from jweb.content import Content from jweb.context import Context @@ -10,7 +10,7 @@ def load_extension(context: Context) -> None: context.add_filters(yaml=_load_yaml) -def _load_yaml(content: Any) -> ContentField: +def _load_yaml(content: Any) -> Any: if not isinstance(content, Content) or not isinstance(content.data, (str, bytes)): raise ValueError("yaml filter can only accept byte or string content") @@ -20,4 +20,4 @@ def _load_yaml(content: Any) -> ContentField: assert isinstance(data, str) - return ContentField(content.path, load(data, Loader)) + return load(data, Loader) diff --git a/tests/test_context.py b/tests/test_context.py index 80964c7..917feb9 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -1,8 +1,7 @@ from pathlib import Path -from pytest import mark, raises +from pytest import mark -from jweb.content import ContentField from jweb.context import Context @@ -34,19 +33,6 @@ def test_load(datadir: Path, path: str | Path) -> None: assert ouput_file.read() == "Otters\n" -def test_load_content_field(datadir: Path) -> None: - context = Context(datadir) - context.render( - "test-load.html", "output.html", path=ContentField(Path("subdir/dummy.yml"), "content.txt") - ) - - with open(datadir / "build" / "output.html", encoding="utf-8") as ouput_file: - assert ouput_file.read() == "Weasel\n" - - with raises(ValueError): - context.render("test-load.html", "output.html", path=ContentField(Path("subdir"), 42)) - - def test_load_localized(datadir: Path) -> None: context = Context(datadir) context.load_translations("tests", datadir / "locale", "fr")