Index: cms/converters.py |
=================================================================== |
--- a/cms/converters.py |
+++ b/cms/converters.py |
@@ -263,31 +263,32 @@ class TemplateConverter(Converter): |
"linkify": self.linkify, |
"toclist": self.toclist, |
} |
globals = { |
"get_string": self.get_string, |
} |
- for filename in self._params["source"].list_files("filters"): |
- root, ext = os.path.splitext(filename) |
- if ext.lower() != ".py": |
- continue |
+ for dirname, dictionary in [("filters", filters), ("functions", globals)]: |
Sebastian Noack
2015/03/20 09:49:43
How about calling it "globals" as well to match th
Wladimir Palant
2015/03/20 16:02:24
Strictly speaking - yes, these don't need to be fu
Sebastian Noack
2015/03/20 16:10:54
Instances (with methods) would come to my mind.
|
+ for filename in self._params["source"].list_files(dirname): |
+ root, ext = os.path.splitext(filename) |
+ if ext.lower() != ".py": |
+ continue |
- path = "%s/%s" % ("filters", filename) |
- code = self._params["source"].read_file(path) |
- module = imp.new_module(root.replace("/", ".")) |
- exec code in module.__dict__ |
+ path = "%s/%s" % (dirname, filename) |
+ code = self._params["source"].read_file(path) |
+ module = imp.new_module(root.replace("/", ".")) |
+ exec code in module.__dict__ |
- func = os.path.basename(root) |
- if not hasattr(module, func): |
- raise Exception("Expected function %s not found in filter file %s" % (func, filename)) |
- filters[func] = getattr(module, func) |
- filters[func].module_ref = module # Prevent garbage collection |
+ func = os.path.basename(root) |
+ if not hasattr(module, func): |
+ raise Exception("Expected function %s not found in %s file %s" % (func, dirname, filename)) |
+ dictionary[func] = getattr(module, func) |
+ dictionary[func].module_ref = module # Prevent garbage collection |
self._env = jinja2.Environment( |
loader=self._SourceLoader(self._params["source"]), |
extensions=["jinja2.ext.do",], |
autoescape=True |
) |
self._env.filters.update(filters) |
self._env.globals.update(globals) |