Mercurial > piecrust2
comparison piecrust/templating/jinja/loader.py @ 924:1bb704434ee2
formatting: Remove segment parts, you can use template tags instead.
Segment parts were used to switch formatters insides a given content segment,
but that's also achievable with template tags like `pcformat` in Jinja to
some degree. It's not totally the same but removing it simplifies the code
and improves performance.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 01 Oct 2017 20:36:04 -0700 |
parents | 2c7e57d80bba |
children |
comparison
equal
deleted
inserted
replaced
923:5713b6a2850d | 924:1bb704434ee2 |
---|---|
3 | 3 |
4 | 4 |
5 class PieCrustLoader(FileSystemLoader): | 5 class PieCrustLoader(FileSystemLoader): |
6 def __init__(self, searchpath, encoding='utf-8'): | 6 def __init__(self, searchpath, encoding='utf-8'): |
7 super(PieCrustLoader, self).__init__(searchpath, encoding) | 7 super(PieCrustLoader, self).__init__(searchpath, encoding) |
8 self.segment_parts_cache = {} | 8 self.segments_cache = {} |
9 | 9 |
10 def get_source(self, environment, template): | 10 def get_source(self, environment, template): |
11 if template.startswith('$part='): | 11 if template.startswith('$seg='): |
12 filename, seg_part = self.segment_parts_cache[template] | 12 filename, seg_content = self.segments_cache[template] |
13 | 13 |
14 mtime = os.path.getmtime(filename) | 14 mtime = os.path.getmtime(filename) |
15 | 15 |
16 def uptodate(): | 16 def uptodate(): |
17 try: | 17 try: |
18 return os.path.getmtime(filename) == mtime | 18 return os.path.getmtime(filename) == mtime |
19 except OSError: | 19 except OSError: |
20 return False | 20 return False |
21 | 21 |
22 return seg_part, filename, uptodate | 22 return seg_content, filename, uptodate |
23 | 23 |
24 return super(PieCrustLoader, self).get_source(environment, template) | 24 return super(PieCrustLoader, self).get_source(environment, template) |