Skip to content

Commit

Permalink
lean add_module
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsca committed Jun 1, 2024
1 parent a14dfb3 commit 5ca65f9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 38 deletions.
11 changes: 3 additions & 8 deletions src/jinjax/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,9 @@ def add_folder(
logger.debug(f"Adding folder `{root_path}` with the prefix `{prefix}`")
self.prefixes[prefix] = jinja2.FileSystemLoader(root_path)

def add_module(self, module: t.Any, *, prefix: str = "") -> None:
if hasattr(module, "components_path"):
prefix = prefix or getattr(module, "prefix", DEFAULT_PREFIX)
self.add_folder(module.components_path, prefix=prefix)
return

for mprefix, path in module.components.items():
self.add_folder(path, prefix=prefix or mprefix)
def add_module(self, module: t.Any, *, prefix: str | None = None) -> None:
mprefix = prefix if prefix is not None else getattr(module, "prefix", DEFAULT_PREFIX)
self.add_folder(module.components_path, prefix=mprefix)

def render(
self,
Expand Down
30 changes: 0 additions & 30 deletions tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,36 +78,6 @@ class Module:
assert "legacy_path" in catalog.prefixes["custom"].searchpath


def test_add_module():
class Module:
components = {
"theme": "theme_path",
"": "extra_path",
}

catalog = jinjax.Catalog()
module = Module()
catalog.add_module(module)

assert "theme_path" in catalog.prefixes["theme"].searchpath
assert "extra_path" in catalog.prefixes[""].searchpath


def test_add_module_with_custom_prefix():
class Module:
components = {
"theme": "theme_path",
"": "extra_path",
}

catalog = jinjax.Catalog()
module = Module()
catalog.add_module(module, prefix="custom")

assert "theme_path" in catalog.prefixes["custom"].searchpath
assert "extra_path" in catalog.prefixes["custom"].searchpath


def test_add_module_fails_with_other_modules():
class Module:
pass
Expand Down

0 comments on commit 5ca65f9

Please sign in to comment.