Compare commits
No commits in common. "562ecf366c5b19512cffe9ef8979dcf43bf225ac" and "1a32cb2b42213411afa785e45249be3aa37ad3b9" have entirely different histories.
562ecf366c
...
1a32cb2b42
|
|
@ -45,18 +45,6 @@ class ContentDirectory(Content):
|
|||
raise NotImplementedError()
|
||||
|
||||
|
||||
class DataField:
|
||||
def __init__(self, file: "DataFile", value: Any) -> None:
|
||||
self.__file = file
|
||||
self.__value = value
|
||||
|
||||
def as_path(self) -> Path:
|
||||
return self.__file.path.parent / str(self.__value)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return str(self.__value)
|
||||
|
||||
|
||||
class DataFile(Content):
|
||||
def __init__(self, path: Path) -> None:
|
||||
super().__init__(path)
|
||||
|
|
@ -64,11 +52,10 @@ class DataFile(Content):
|
|||
self.__data = load(data_file, Loader)
|
||||
|
||||
def __getitem__(self, key: Any) -> Any:
|
||||
return DataField(self, self.__data.get(key))
|
||||
return self.__data.get(key)
|
||||
|
||||
def __iter__(self) -> Iterator[Any]:
|
||||
for it in self.__data:
|
||||
yield DataField(self, it)
|
||||
yield from self.__data
|
||||
|
||||
|
||||
class MarkdownFile(Content):
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
from pathlib import Path
|
||||
from shutil import copy
|
||||
from typing import Any
|
||||
|
||||
from jinja2.environment import Environment
|
||||
|
|
@ -13,7 +12,6 @@ class Site:
|
|||
self.__root_directory = root_directory
|
||||
self.__output_directory = root_directory / "build"
|
||||
self.__environment = Environment(loader=FileSystemLoader(searchpath=root_directory / "src"))
|
||||
self.__environment.filters.update({"output": self.__output})
|
||||
self.__content = ContentDirectory(root_directory / "content")
|
||||
|
||||
@property
|
||||
|
|
@ -28,16 +26,3 @@ class Site:
|
|||
|
||||
with open(output_path, "w") as output_file:
|
||||
output_file.write(content)
|
||||
|
||||
def __output(self, path: str | Path) -> str:
|
||||
path = Path(path)
|
||||
if path.is_absolute():
|
||||
src_path = path
|
||||
relative_src_path = src_path.relative_to(self.__content.path)
|
||||
else:
|
||||
src_path = self.__content.path / path
|
||||
relative_src_path = path
|
||||
dst_path = self.__output_directory / relative_src_path
|
||||
dst_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
copy(src_path, dst_path, follow_symlinks=True)
|
||||
return f"/{relative_src_path}"
|
||||
|
|
|
|||
|
|
@ -25,18 +25,11 @@ def test_load_data(datadir: Path) -> None:
|
|||
content = ContentDirectory(datadir)
|
||||
steven = content.load(Path("otters/steven.yml"))
|
||||
|
||||
assert str(steven["name"]) == "Steven"
|
||||
assert str(steven["mood"]) == "Angry"
|
||||
assert steven["name"] == "Steven"
|
||||
assert steven["mood"] == "Angry"
|
||||
|
||||
otter_list = content.load(Path("otters/otter_list.json"))
|
||||
assert [str(it) for it in otter_list] == ["steven", "peter"]
|
||||
|
||||
|
||||
def test_data_as_path(datadir: Path) -> None:
|
||||
content = ContentDirectory(datadir)
|
||||
paths = content.load(Path("otters/paths.yml"))
|
||||
|
||||
assert paths["steven"].as_path() == datadir / "otters" / "relative-steven"
|
||||
assert list(otter_list) == ["steven", "peter"]
|
||||
|
||||
|
||||
def test_load_markdown(datadir: Path) -> None:
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
steven: ./relative-steven
|
||||
|
||||
|
|
@ -17,16 +17,3 @@ def test_render_page(datadir: Path, site_dir: FakeFilesystem):
|
|||
site.render("index.j2", "index.html")
|
||||
with open(datadir / "build" / "index.html", encoding="utf-8") as ouput_file:
|
||||
assert ouput_file.read() == "<p>Peter</p><p>Steven</p>"
|
||||
|
||||
|
||||
def test_output_file(datadir: Path, site_dir: FakeFilesystem):
|
||||
site = Site(datadir)
|
||||
build_dir = datadir / "build"
|
||||
|
||||
site.render("output-file.j2", "output-file.html")
|
||||
|
||||
with open(build_dir / "assets/steven-avatar", encoding="utf-8") as ouput_file:
|
||||
assert ouput_file.read() == "Yipee\n"
|
||||
|
||||
with open(build_dir / "output-file.html", encoding="utf-8") as ouput_file:
|
||||
assert ouput_file.read() == "/assets/steven-avatar\n"
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
Yipee
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
{{ "assets/steven-avatar" | output }}
|
||||
|
||||
Loading…
Reference in New Issue