]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
add a template_loader application setting for using custom template loaders. a slight...
authorDolapo Falola <dolapo@xenopus.local>
Thu, 18 Mar 2010 01:44:16 +0000 (18:44 -0700)
committerBen Darnell <bdarnell@beaker.local>
Thu, 18 Mar 2010 02:22:33 +0000 (19:22 -0700)
tornado/template.py
tornado/web.py

index b5e94bda702cf09c109a9f63790671f54dce04c4..b62735ee99de480708c84c66c7f44e981589a07a 100644 (file)
@@ -169,7 +169,10 @@ class Loader(object):
         self.root = os.path.abspath(root_directory)
         self.templates = {}
 
-    def load(self, name, parent_path=None):
+    def reset(self):
+      self.templates = {}
+
+    def resolve_path(self, name, parent_path=None):
         if parent_path and not parent_path.startswith("<") and \
            not parent_path.startswith("/") and \
            not name.startswith("/"):
@@ -178,6 +181,10 @@ class Loader(object):
             relative_path = os.path.abspath(os.path.join(file_dir, name))
             if relative_path.startswith(self.root):
                 name = relative_path[len(self.root) + 1:]
+        return name
+
+    def load(self, name, parent_path=None):
+        name = self.resolve_path(name, parent_path=parent_path)
         if name not in self.templates:
             path = os.path.join(self.root, name)
             f = open(path, "r")
index d901c4f6746718abff33a76f83f0f40eb4665677..766a441ffe90b9584a3044c543ba0f43a8e4b89d 100644 (file)
@@ -417,8 +417,9 @@ class RequestHandler(object):
         if not getattr(RequestHandler, "_templates", None):
             RequestHandler._templates = {}
         if template_path not in RequestHandler._templates:
-            RequestHandler._templates[template_path] = template.Loader(
-                template_path)
+            loader = self.application.settings.get("template_loader") or\
+              template.Loader(template_path)
+            RequestHandler._templates[template_path] = loader
         t = RequestHandler._templates[template_path].load(template_name)
         args = dict(
             handler=self,
@@ -1020,7 +1021,9 @@ class Application(object):
         # In debug mode, re-compile templates and reload static files on every
         # request so you don't need to restart to see changes
         if self.settings.get("debug"):
-            RequestHandler._templates = None
+            if getattr(RequestHandler, "_templates", None):
+              map(lambda loader: loader.reset(),
+                  RequestHandler._templates.values())
             RequestHandler._static_hashes = {}
 
         handler._execute(transforms, *args, **kwargs)