worked out some bugs in extension loading
This commit is contained in:
parent
13bdcf7f58
commit
2b5f9e9b43
|
@ -65,8 +65,8 @@ sitetitle = ""
|
||||||
|
|
||||||
[extensions]
|
[extensions]
|
||||||
# Full classnames of the extensions to be loaded.
|
# Full classnames of the extensions to be loaded.
|
||||||
load = ["dragonglass.extensions.breadcrumbs.BreadcrumbExtension"]
|
load = ["dragonglass.extensions.breadcrumbs.Breadcrumbs"]
|
||||||
|
|
||||||
[extensions.BreadcrumbExtension]
|
[extensions.Breadcrumbs]
|
||||||
# Configuration data for BreadcrumbExtension.
|
# Configuration data for Breadcrumbs.
|
||||||
var = "value"
|
var = "value"
|
||||||
|
|
|
@ -49,8 +49,6 @@ CALLOUT_ICONS = {
|
||||||
'todo': 'circle-check',
|
'todo': 'circle-check',
|
||||||
'warning': 'triangle-alert'
|
'warning': 'triangle-alert'
|
||||||
}
|
}
|
||||||
"""Cache of extension module names."""
|
|
||||||
EXTENSION_PKGS = {}
|
|
||||||
|
|
||||||
|
|
||||||
def load_extension_class(name: str, sect: dict[str, Any]) -> Extension:
|
def load_extension_class(name: str, sect: dict[str, Any]) -> Extension:
|
||||||
|
@ -65,15 +63,14 @@ def load_extension_class(name: str, sect: dict[str, Any]) -> Extension:
|
||||||
Extension: Instance of the extension class.
|
Extension: Instance of the extension class.
|
||||||
"""
|
"""
|
||||||
components = name.split('.')
|
components = name.split('.')
|
||||||
classname = components.pop()
|
modname = ".".join(components[:-1])
|
||||||
modname = ".".join(components)
|
b = __import__(modname)
|
||||||
if modname not in EXTENSION_PKGS:
|
for c in components[1:]:
|
||||||
EXTENSION_PKGS[modname] = __import__(modname)
|
b = getattr(b, c)
|
||||||
extclass = getattr(EXTENSION_PKGS[modname], classname)
|
cfg_sect = sect.get(components[-1], {})
|
||||||
cfg_sect = sect.get(classname, {})
|
rc = b(cfg_sect)
|
||||||
rc = extclass(cfg_sect)
|
|
||||||
if not isinstance(rc, Extension):
|
if not isinstance(rc, Extension):
|
||||||
raise RuntimeError(f"class {name} is not a valid Dragonglass extension")
|
raise RuntimeError(f"class {name} is not a valid dragonglass extension")
|
||||||
return rc
|
return rc
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,11 +9,17 @@ from ..tree import SourceNode, SourceIndex
|
||||||
"""The extension for generating breadcrumb informatioon."""
|
"""The extension for generating breadcrumb informatioon."""
|
||||||
|
|
||||||
|
|
||||||
class BreadcrumbExtension(Extension):
|
class Breadcrumbs(Extension):
|
||||||
LINK = re.compile(r'^\[\[(.+)(?:\|.+)?\]\]')
|
LINK = re.compile(r'^\[\[(.+)(?:\|.+)?\]\]')
|
||||||
|
|
||||||
def __init__(self, config: dict[str, Any]):
|
def __init__(self, config: dict[str, Any]):
|
||||||
super(BreadcrumbExtension, self).__init__(config)
|
"""
|
||||||
|
Initialize the Breadcrumbs extension.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
config (dict[str, Any]): Configuration variables for this extension.
|
||||||
|
"""
|
||||||
|
super(Breadcrumbs, self).__init__(config)
|
||||||
self._root_nodes: list[SourceNode] = []
|
self._root_nodes: list[SourceNode] = []
|
||||||
self._raw_targets: list[tuple[SourceNode, str]] = []
|
self._raw_targets: list[tuple[SourceNode, str]] = []
|
||||||
self._parents: dict[SourceNode, SourceNode] = {}
|
self._parents: dict[SourceNode, SourceNode] = {}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user