Skip to content

Commit

Permalink
228 make archivehtml default template for archive objects (#611)
Browse files Browse the repository at this point in the history
* adds tests for archive and ruff format

* updates test for variable

* update docs
  • Loading branch information
kjaymiller committed Feb 24, 2024
1 parent e04b96c commit 984fdcf
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
20 changes: 12 additions & 8 deletions docs/docs/archive.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<!-- markdownlint-disable MD052 -->

# Archive

Archives are a [`BasePage`](../page?id=basepage) object used to display a list of [`Page`](../page?id=page) objects in a [`Collection`](../collection?id=collection).
Expand All @@ -12,16 +13,19 @@ that focuses on presenting the Collection's pages.

**Parameters:**

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `pages` | `list[`[`BasePage`](../page?id=basepage)`]` |The list of pages to include in the archive | _required_ |
| `title` | `str` |The title of the archive | _required_ |
| `template` | `str | Template` |The template to use for the archive | _required_ |
| `routes` | `list[str |Path]` |The routes for where the archive page should be generated | _required_ |
| `archive_index` | `int` |The index of the page in the series of archive pages | `0` |
| `num_of_pages` | |The total number of pages in the series of archive pages | _required_ |
<!-- markdownlint-disable -->

| Name | Type | Description | Default |
| --------------- | ------------------------------------------- | -------------------------------------------------------- | --------------------------------------------------------- | -------------- |
| `pages` | `list[`[`BasePage`](../page?id=basepage)`]` | The list of pages to include in the archive | _required_ |
| `title` | `str` | The title of the archive | _required_ |
| `template` | `str | Template` | The template to use for the archive | "archive.html" |
| `routes` | `list[str | Path]` | The routes for where the archive page should be generated | _required_ |
| `archive_index` | `int` | The index of the page in the series of archive pages | `0` |
| `num_of_pages` | | The total number of pages in the series of archive pages | _required_ |

> !!! Warning Not Directly Used
The Archive object is not meant to be used directly.
It is used by the [Collection](../collection?id=collection) object.
Attributes can be used to customize.
Expand Down
2 changes: 1 addition & 1 deletion src/render_engine/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ def __init__(
self,
title: str,
pages: list[BasePage],
template: str | jinja2.Template,
template_vars: dict[str, any],
routes: list[str | pathlib.Path],
archive_index: int = 0,
num_archive_pages: int = 1,
is_index: bool = False,
plugin_manager: PluginManager | None = None,
template: str | jinja2.Template = "archive.html",
) -> None:
super().__init__()
self.slug = title
Expand Down
33 changes: 30 additions & 3 deletions tests/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,47 @@
def test_archive_slug_named_after_title():
"""Archives usually get their name from their collection. This tests that the slug is named after the title"""

archive = Archive(title="test archive", pages=[Page()], template="", routes=["./"], template_vars={})
archive = Archive(
title="test archive",
pages=[Page()],
template="",
routes=["./"],
template_vars={},
)

assert archive._slug == "test-archive"


@pytest.mark.parametrize(
"title, expected_slug",
[("archive", "archive1"), ("collection", "collection1"), ("Test Collection", "test-collection1")],
[
("archive", "archive1"),
("collection", "collection1"),
("Test Collection", "test-collection1"),
],
)
def test_archive_slug_name_with_pages(title, expected_slug):
"""tests that if num_archive_pages is greater than 1, the slug is appended with the archive_index"""

archive = Archive(
title=title, pages=[Page()], template="", routes=["./"], archive_index=1, num_archive_pages=2, template_vars={}
title=title,
pages=[Page()],
template="",
routes=["./"],
archive_index=1,
num_archive_pages=2,
template_vars={},
)

assert archive._slug == expected_slug


def test_archive_template_is_archive_html():
"""Tests that the template is set to archive.html"""
archive = Archive(
title="test archive",
pages=[Page()],
routes=["./"],
template_vars={},
)
assert archive.template == "archive.html"

0 comments on commit 984fdcf

Please sign in to comment.