diff 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
line wrap: on
line diff
--- a/piecrust/rendering.py	Thu Jun 15 07:33:40 2017 -0700
+++ b/piecrust/rendering.py	Thu Jun 15 22:16:23 2017 -0700
@@ -6,6 +6,7 @@
     DataBuildingContext, build_page_data, add_layout_data)
 from piecrust.fastpickle import _pickle_object, _unpickle_object
 from piecrust.templating.base import TemplateNotFoundError, TemplatingError
+from piecrust.sources.base import AbortedSourceUseError
 
 
 logger = logging.getLogger(__name__)
@@ -127,6 +128,10 @@
         self._ctx_stack = []
 
     @property
+    def is_empty(self):
+        return len(self._ctx_stack) == 0
+
+    @property
     def current_ctx(self):
         if len(self._ctx_stack) == 0:
             return None
@@ -217,6 +222,8 @@
                 layout_result['pass_info'])
         return rp
 
+    except AbortedSourceUseError:
+        raise
     except Exception as ex:
         if ctx.app.debug:
             raise
@@ -234,6 +241,14 @@
     stats = env.stats
 
     stack = env.render_ctx_stack
+
+    if env.abort_source_use and not stack.is_empty:
+        cur_spec = ctx.page.content_spec
+        from_spec = stack.current_ctx.page.content_spec
+        logger.debug("Aborting rendering of '%s' from: %s." %
+                     (cur_spec, from_spec))
+        raise AbortedSourceUseError()
+
     stack.pushCtx(ctx)
 
     page = ctx.page