Mercurial > piecrust2
comparison piecrust/templating/jinjaengine.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 | 3e69f18912f5 |
children | 8adc27285d93 |
comparison
equal
deleted
inserted
replaced
923:5713b6a2850d | 924:1bb704434ee2 |
---|---|
15 def __init__(self): | 15 def __init__(self): |
16 self.env = None | 16 self.env = None |
17 self._jinja_syntax_error = None | 17 self._jinja_syntax_error = None |
18 self._jinja_not_found = None | 18 self._jinja_not_found = None |
19 | 19 |
20 def renderSegmentPart(self, path, seg_part, data): | 20 def renderSegment(self, path, segment, data): |
21 if not _string_needs_render(seg_part.content): | 21 if not _string_needs_render(segment.content): |
22 return seg_part.content | 22 return segment.content |
23 | 23 |
24 self._ensureLoaded() | 24 self._ensureLoaded() |
25 | 25 |
26 part_path = _make_segment_part_path(path, seg_part.offset) | 26 seg_path = _make_segment_path(path, segment.offset) |
27 self.env.loader.segment_parts_cache[part_path] = ( | 27 self.env.loader.segments_cache[seg_path] = ( |
28 path, seg_part.content) | 28 path, segment.content) |
29 try: | 29 try: |
30 tpl = self.env.get_template(part_path) | 30 tpl = self.env.get_template(seg_path) |
31 except self._jinja_syntax_error as tse: | 31 except self._jinja_syntax_error as tse: |
32 raise self._getTemplatingError(tse, filename=path) | 32 raise self._getTemplatingError(tse, filename=path) |
33 except self._jinja_not_found: | 33 except self._jinja_not_found: |
34 raise TemplateNotFoundError() | 34 raise TemplateNotFoundError() |
35 | 35 |
143 return True | 143 return True |
144 index = txt.find('{', index + 1) | 144 index = txt.find('{', index + 1) |
145 return False | 145 return False |
146 | 146 |
147 | 147 |
148 def _make_segment_part_path(path, start): | 148 def _make_segment_path(path, start): |
149 return '$part=%s:%d' % (path, start) | 149 return '$seg=%s:%d' % (path, start) |
150 | 150 |