comparison piecrust/rendering.py @ 877:d6d35b2efd04

bake: Rename "pass" to "step" and make the page pipeline use different steps. That pipeline is now first loading all pages, and then rendering full pages unless they trigger a sub-render.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 15 Jun 2017 22:16:23 -0700
parents d1095774bfcf
children cc2647360036
comparison
equal deleted inserted replaced
876:d1095774bfcf 877:d6d35b2efd04
4 import logging 4 import logging
5 from piecrust.data.builder import ( 5 from piecrust.data.builder import (
6 DataBuildingContext, build_page_data, add_layout_data) 6 DataBuildingContext, build_page_data, add_layout_data)
7 from piecrust.fastpickle import _pickle_object, _unpickle_object 7 from piecrust.fastpickle import _pickle_object, _unpickle_object
8 from piecrust.templating.base import TemplateNotFoundError, TemplatingError 8 from piecrust.templating.base import TemplateNotFoundError, TemplatingError
9 from piecrust.sources.base import AbortedSourceUseError
9 10
10 11
11 logger = logging.getLogger(__name__) 12 logger = logging.getLogger(__name__)
12 13
13 14
123 124
124 125
125 class RenderingContextStack(object): 126 class RenderingContextStack(object):
126 def __init__(self): 127 def __init__(self):
127 self._ctx_stack = [] 128 self._ctx_stack = []
129
130 @property
131 def is_empty(self):
132 return len(self._ctx_stack) == 0
128 133
129 @property 134 @property
130 def current_ctx(self): 135 def current_ctx(self):
131 if len(self._ctx_stack) == 0: 136 if len(self._ctx_stack) == 0:
132 return None 137 return None
215 if layout_result['pass_info'] is not None: 220 if layout_result['pass_info'] is not None:
216 rp.render_info[PASS_RENDERING] = _unpickle_object( 221 rp.render_info[PASS_RENDERING] = _unpickle_object(
217 layout_result['pass_info']) 222 layout_result['pass_info'])
218 return rp 223 return rp
219 224
225 except AbortedSourceUseError:
226 raise
220 except Exception as ex: 227 except Exception as ex:
221 if ctx.app.debug: 228 if ctx.app.debug:
222 raise 229 raise
223 logger.exception(ex) 230 logger.exception(ex)
224 raise Exception("Error rendering page: %s" % 231 raise Exception("Error rendering page: %s" %
232 def render_page_segments(ctx): 239 def render_page_segments(ctx):
233 env = ctx.app.env 240 env = ctx.app.env
234 stats = env.stats 241 stats = env.stats
235 242
236 stack = env.render_ctx_stack 243 stack = env.render_ctx_stack
244
245 if env.abort_source_use and not stack.is_empty:
246 cur_spec = ctx.page.content_spec
247 from_spec = stack.current_ctx.page.content_spec
248 logger.debug("Aborting rendering of '%s' from: %s." %
249 (cur_spec, from_spec))
250 raise AbortedSourceUseError()
251
237 stack.pushCtx(ctx) 252 stack.pushCtx(ctx)
238 253
239 page = ctx.page 254 page = ctx.page
240 page_uri = page.getUri(ctx.sub_num) 255 page_uri = page.getUri(ctx.sub_num)
241 256