Skip to content

Commit

Permalink
Merge pull request #434 from render-engine:fix-plugin-settings
Browse files Browse the repository at this point in the history
Fix plugin settings
  • Loading branch information
kjaymiller committed Dec 4, 2023
2 parents 69e277e + 2b485c7 commit 8b68e9e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/render_engine/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(
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,
Expand All @@ -46,3 +47,4 @@ def __init__(
self.routes = routes
self.template = template
self.title = title
self.template_vars = template_vars
2 changes: 2 additions & 0 deletions src/render_engine/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class BasicCollection(Collection):
routes: list[str] = ["./"]
sort_by: str = "title"
sort_reverse: bool = False
template_vars: dict[str, any]
template: str | None
plugins: list[typing.Callable] | None
plugin_manager: PluginManager | None
Expand Down Expand Up @@ -162,6 +163,7 @@ def archives(self) -> typing.Generator[Archive, None, None]:
yield Archive(
pages=pages,
template=getattr(self, "archive_template", None),
template_vars=getattr(self, "template_vars", {}),
title=self._title,
routes=self.routes,
archive_index=index,
Expand Down
14 changes: 6 additions & 8 deletions src/render_engine/extras/site_map.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import pathlib
import typing

from render_engine.engine import engine
from render_engine.hookspecs import hook_impl
Expand All @@ -19,7 +18,6 @@ class SiteMap:
@hook_impl
def post_build_site(
site: Site,
settings: dict[str, typing.Any],
):
"""Generate a sitemap.xml file.
Expand All @@ -31,13 +29,13 @@ def post_build_site(
map_item_pattern: The pattern to use to find the files to include in the sitemap.xml file
"""
logging.info(
f"""Generating sitemap - {settings['SiteMap']['output_path']}
from files matching - {settings['SiteMap']['map_item_pattern']}
using template - {settings['SiteMap']['template']}"""
f"""Generating sitemap - {site.plugin_settings["SiteMap"]['output_path']}
from files matching - {site.plugin_settings["SiteMap"]['map_item_pattern']}
using template - {site.plugin_settings["SiteMap"]['template']}"""
)
template = engine.get_template(settings["SiteMap"]["template"])
site_map_items = pathlib.Path(site.output_path).rglob(settings["SiteMap"]["map_item_pattern"])
sitemap_path = pathlib.Path(site.output_path).joinpath(settings["SiteMap"]["output_path"])
template = engine.get_template(site.plugin_settings["SiteMap"]["template"])
site_map_items = pathlib.Path(site.output_path).rglob(site.plugin_settings["SiteMap"]["map_item_pattern"])
sitemap_path = pathlib.Path(site.output_path).joinpath(site.plugin_settings["SiteMap"]["output_path"])
sitemap_path.write_text(
template.render(
items=[item.relative_to(site.output_path) for item in site_map_items],
Expand Down
1 change: 0 additions & 1 deletion src/render_engine/hookspecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def pre_build_site(
def post_build_site(
self,
site: "Site",
settings: dict[str, typing.Any],
) -> None:
"""Build After Building the site"""

Expand Down
8 changes: 4 additions & 4 deletions src/render_engine/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ def update_site_vars(self, **kwargs) -> None:
def register_plugins(self, *plugins):
for plugin in plugins:
self.plugin_manager.register_plugin(plugin)
if plugin_settings := self.plugin_settings.get("plugins"):
plugin.default_settings = plugin_settings
self.plugin_settings[plugin.__name__] = {
**getattr(plugin, "default_settings", {}),
**self.plugin_settings.get(plugin.__name__, {}),
}

def register_theme(self, theme: Theme):
"""Overrides the ThemeManager register_theme method to add plugins to the site"""
Expand Down Expand Up @@ -243,7 +245,6 @@ def render(self) -> None:

with Progress() as progress:
pre_build_task = progress.add_task("Loading Pre-Build Plugins", total=1)
print(self.plugin_manager._pm.hook)
self.plugin_manager._pm.hook.pre_build_site(site=self, settings=self.site_settings.get("plugins", {})) # type: ignore

self.theme_manager.engine.loader.loaders.insert(-2, PrefixLoader(self.theme_manager.prefix))
Expand Down Expand Up @@ -277,6 +278,5 @@ def render(self) -> None:
progress.add_task("Loading Post-Build Plugins", total=1)
self.plugin_manager._pm.hook.post_build_site(
site=self,
settings=self.site_settings.get("plugins", {}),
)
progress.update(pre_build_task, advance=1)
1 change: 1 addition & 0 deletions tests/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def test_archive_slug_name_with_pages():
routes=["./"],
archive_index=1,
num_archive_pages=2,
template_vars={}
)

assert archive.slug == "archive1"
2 changes: 0 additions & 2 deletions tests/test_templates/test_base_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class bodyClassTheme(Theme):
theme_site.register_themes(bodyClassTheme)
theme_site._render_output("./", theme_site.route_list["testpage"])

print(theme_site.theme_manager.engine.globals.keys())

assert '<body class="my-class">' in (theme_site.output_path / "testpage.html").read_text()


Expand Down

0 comments on commit 8b68e9e

Please sign in to comment.