Mercurial > piecrust2
comparison piecrust/templating/jinja/loader.py @ 851:2c7e57d80bba
optimize: Don't load Jinja unless we need to.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 29 Apr 2017 21:42:22 -0700 |
parents | |
children | 1bb704434ee2 |
comparison
equal
deleted
inserted
replaced
850:370e74941d32 | 851:2c7e57d80bba |
---|---|
1 import os.path | |
2 from jinja2 import FileSystemLoader | |
3 | |
4 | |
5 class PieCrustLoader(FileSystemLoader): | |
6 def __init__(self, searchpath, encoding='utf-8'): | |
7 super(PieCrustLoader, self).__init__(searchpath, encoding) | |
8 self.segment_parts_cache = {} | |
9 | |
10 def get_source(self, environment, template): | |
11 if template.startswith('$part='): | |
12 filename, seg_part = self.segment_parts_cache[template] | |
13 | |
14 mtime = os.path.getmtime(filename) | |
15 | |
16 def uptodate(): | |
17 try: | |
18 return os.path.getmtime(filename) == mtime | |
19 except OSError: | |
20 return False | |
21 | |
22 return seg_part, filename, uptodate | |
23 | |
24 return super(PieCrustLoader, self).get_source(environment, template) |