summaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-11-11 09:28:40 -0500
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-11-11 09:29:26 -0500
commit7aa15c4c5507e311ff66264bc31e6758a80eb337 (patch)
treebc7778bc2cab315d5a8c9a23e3e5d39a7e010e44 /doc
parentc2ab446b6b33cb24f3916bb9d46e0554d3561376 (diff)
downloadbcfg2-7aa15c4c5507e311ff66264bc31e6758a80eb337.tar.gz
bcfg2-7aa15c4c5507e311ff66264bc31e6758a80eb337.tar.bz2
bcfg2-7aa15c4c5507e311ff66264bc31e6758a80eb337.zip
doc: Added docs for TemplateHelper __default__ feature
Diffstat (limited to 'doc')
-rw-r--r--doc/server/plugins/connectors/templatehelper.txt16
1 files changed, 14 insertions, 2 deletions
diff --git a/doc/server/plugins/connectors/templatehelper.txt b/doc/server/plugins/connectors/templatehelper.txt
index 374aeb171..c719f93cb 100644
--- a/doc/server/plugins/connectors/templatehelper.txt
+++ b/doc/server/plugins/connectors/templatehelper.txt
@@ -31,7 +31,7 @@ helpers will be available to all clients.
Writing Helpers
===============
-A helper module is just a Python module with three special conditions:
+A helper module is just a Python module with several special conditions:
* The filename must end with ``.py``
* The module must have an attribute, ``__export__``, that lists all of
@@ -43,6 +43,12 @@ A helper module is just a Python module with three special conditions:
an underscore or double underscore is bad form, and may also produce
errors.
+Additionally, the module *may* have an attribute, ``__default__``,
+that lists all of the symbols that you wish to include by default in
+the template namespace. ``name``, ``metadata``, ``source_path``,
+``repo``, and ``path`` are reserved names, and should not be included
+in ``__default__``.
+
See ``examples/TemplateHelper`` for examples of helper modules.
Usage
@@ -54,17 +60,23 @@ a HelperModule object will has, as attributes, all symbols listed in
``__export__``. For example, consider this helper module::
__export__ = ["hello"]
-
+ __default__ = ["pining"]
+
def hello(metadata):
return "Hello, %s!" % metadata.hostname
+ def pining(text):
+ return "It's pinin' for the %s!" % text
+
To use this in a Genshi template, we could do::
${metadata.TemplateHelper['hello'].hello(metadata)}
+ ${pining("fjords")}
The template would produce::
Hello, foo.example.com!
+ It's pinin' for the fjords!
Note that the client metadata object is not passed to a helper module
in any magical way; if you want to access the client metadata object