Module

cli.templates.registry

Template registry and discovery.

This module discovers built‑in templates (and optionally custom ones on PYTHONPATH) by importingbengal.cli.templates.<name>.templateand looking for a module‑levelTEMPLATEvariable. The registry provides a small API to list, retrieve, and register templates programmatically.

Classes

TemplateRegistry
Registry for discovering and managing site templates. The registry scans the sibling directories o…
7

Registry for discovering and managing site templates.

The registry scans the sibling directories of this file for template packages that expose aTEMPLATEvariable.

Methods 3

get
Get a template by its identifier.
1 SiteTemplate | None
def get(self, template_id: str) -> SiteTemplate | None

Get a template by its identifier.

Parameters 1
template_id str

The template ID (e.g."blog").

Returns

SiteTemplate | None

The matching :class:SiteTemplateorNoneif not found.

list
List all templates as ``(id, description)`` tuples.
0 list[tuple[str, str]]
def list(self) -> list[tuple[str, str]]

List all templates as(id, description)tuples.

Returns

list[tuple[str, str]]

exists
Return True if a template with ``template_id`` exists.
1 bool
def exists(self, template_id: str) -> bool

Return True if a template withtemplate_idexists.

Parameters 1
template_id str
Returns

bool

Internal Methods 4
__init__
0 None
def __init__(self) -> None
_discover_templates
Discover all available templates in the built‑in package tree. Prefers skeleto…
0 None
def _discover_templates(self) -> None

Discover all available templates in the built‑in package tree.

Prefers skeleton.yaml manifests when available, falls back to Python templates.

_load_skeleton_template
Load a template from a skeleton manifest.
2 SiteTemplate | None
def _load_skeleton_template(self, skeleton_path: Path, template_id: str) -> SiteTemplate | None

Load a template from a skeleton manifest.

Parameters 2
skeleton_path Path

Path to skeleton.yaml file

template_id str

Template identifier (directory name)

Returns

SiteTemplate | None

SiteTemplate instance or None if loading fails

_skeleton_to_site_template
Convert a Skeleton manifest to a SiteTemplate.
2 SiteTemplate
def _skeleton_to_site_template(self, skeleton: Skeleton, template_id: str) -> SiteTemplate

Convert a Skeleton manifest to a SiteTemplate.

Parameters 2
skeleton Skeleton

Skeleton instance from manifest

template_id str

Template identifier

Returns

SiteTemplate

SiteTemplate instance

Functions

_get_registry
Get or create the global registry instance (singleton).
0 TemplateRegistry
def _get_registry() -> TemplateRegistry

Get or create the global registry instance (singleton).

Returns

TemplateRegistry

get_template
Convenience wrapper to get a template by ID from the global registry.
1 SiteTemplate | None
def get_template(template_id: str) -> SiteTemplate | None

Convenience wrapper to get a template by ID from the global registry.

Parameters 1

Name Type Default Description
template_id str

Returns

SiteTemplate | None

list_templates
Convenience wrapper to list all available templates.
0 list[tuple[str, str]]
def list_templates() -> list[tuple[str, str]]

Convenience wrapper to list all available templates.

Returns

list[tuple[str, str]]

register_template
Register a custom template with the global registry. This allows applications and plugins to add t…
1 None
def register_template(template: SiteTemplate) -> None

Register a custom template with the global registry.

This allows applications and plugins to add templates at runtime.

Parameters 1

Name Type Default Description
template SiteTemplate