Added documentation for custom templates and improved code readability

This commit is contained in:
Alexandre Chataignon
2017-03-12 00:34:13 +01:00
parent 34bb3899c1
commit 17c7a567e4
2 changed files with 12 additions and 2 deletions

View File

@@ -59,6 +59,15 @@ You can use the following variables in your template:
``theme.name``, ``theme.url``
Name and url of the currently used theme.
Filters
~~~~~~~
You can define custom jinja filters for your template by creating a ``filters.py`` script
at the root of your template directory.
This script will then be imported and all defined functions will be available as jinja filters
with the same names in your templates.
Documentation of sigal's main classes
-------------------------------------

View File

@@ -87,8 +87,9 @@ class Writer(object):
filters_py = os.path.join(self.theme, 'filters.py')
if os.path.exists(filters_py):
mod = imp.load_source('filters', filters_py)
for name in [name for name in dir(mod) if isinstance(getattr(mod, name), types.FunctionType)]:
env.filters[name] = getattr(mod, name)
for name in dir(mod):
if isinstance(getattr(mod, name), types.FunctionType):
env.filters[name] = getattr(mod, name)
try:
self.template = env.get_template(self.template_file)