summaryrefslogtreecommitdiff
path: root/wikimini/templates
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2021-08-21 22:12:45 +0200
committerDaniel Schadt <kingdread@gmx.de>2021-08-21 22:12:45 +0200
commit662fcdc06012efacad53125ee4a449b632fad187 (patch)
tree2f0223e4d4cf1d22c4d397f069ab7a6a92249b89 /wikimini/templates
parent01f52aa2481c314511f43560757c5bd63ca05ac2 (diff)
downloadwikimini-662fcdc06012efacad53125ee4a449b632fad187.tar.gz
wikimini-662fcdc06012efacad53125ee4a449b632fad187.tar.bz2
wikimini-662fcdc06012efacad53125ee4a449b632fad187.zip
Allow passing a custom template registry
Diffstat (limited to 'wikimini/templates')
-rw-r--r--wikimini/templates/__init__.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/wikimini/templates/__init__.py b/wikimini/templates/__init__.py
index 360b3fa..ebe3bbc 100644
--- a/wikimini/templates/__init__.py
+++ b/wikimini/templates/__init__.py
@@ -6,6 +6,7 @@ A template is a function that takes the :class:`~wikimini.Wikimini` instance
and the :class:`~mwparserfromhell.nodes.template.Template` node to convert, and
returns a string with the template output (see :const:`Template`).
"""
+import copy
from typing import Callable, Optional
import mwparserfromhell as mwp
@@ -49,6 +50,19 @@ class Registry:
"""
self.templates[name] = template
+ def copy(self) -> "Registry":
+ """Returns a copy of the registry.
+
+ This is useful if you want to use the global registry as a starting
+ point to add your own templates, without modifying the global instance.
+
+ Returns:
+ A copy of the registry.
+ """
+ copied = Registry()
+ copied.templates = copy.copy(self.templates)
+ return copied
+
#: The global template registry.
registry = Registry()