diff piecrust/app.py @ 853:f070a4fc033c

core: Continue PieCrust3 refactor, simplify pages. The asset pipeline is still the only function pipeline at this point. * No more `QualifiedPage`, and several other pieces of code deleted. * Data providers are simpler and more focused. For instance, the page iterator doesn't try to support other types of items. * Route parameters are proper known source metadata to remove the confusion between the two. * Make the baker and pipeline more correctly manage records and record histories. * Add support for record collapsing and deleting stale outputs in the asset pipeline.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 21 May 2017 00:06:59 -0700
parents 4850f8c21b6e
children 08e02c2a2a1a
line wrap: on
line diff
--- a/piecrust/app.py	Wed May 17 00:11:48 2017 -0700
+++ b/piecrust/app.py	Sun May 21 00:06:59 2017 -0700
@@ -34,18 +34,20 @@
         else:
             self.cache = NullExtensibleCache()
 
+        if env is None:
+            env = StandardEnvironment()
         self.env = env
-        if self.env is None:
-            self.env = StandardEnvironment()
-        self.env.initialize(self)
-        self.env.stats.registerTimer('SiteConfigLoad')
-        self.env.stats.registerTimer('PageLoad')
-        self.env.stats.registerTimer("PageDataBuild")
-        self.env.stats.registerTimer("BuildRenderData")
-        self.env.stats.registerTimer("PageRender")
-        self.env.stats.registerTimer("PageRenderSegments")
-        self.env.stats.registerTimer("PageRenderLayout")
-        self.env.stats.registerTimer("PageSerialize")
+        env.initialize(self)
+
+        stats = env.stats
+        stats.registerTimer('SiteConfigLoad')
+        stats.registerTimer('PageLoad')
+        stats.registerTimer("PageDataBuild")
+        stats.registerTimer("BuildRenderData")
+        stats.registerTimer("PageRender")
+        stats.registerTimer("PageRenderSegments")
+        stats.registerTimer("PageRenderLayout")
+        stats.registerTimer("PageSerialize")
 
     @cached_property
     def config(self):
@@ -193,19 +195,17 @@
         for source in self.sources:
             if source.name == source_name:
                 return source
-        return None
 
-    def getSourceRoutes(self, source_name):
+        from piecrust.sources.base import SourceNotFoundError
+        raise SourceNotFoundError(source_name)
+
+    def getSourceRoute(self, source_name):
         for route in self.routes:
             if route.source_name == source_name:
-                yield route
+                return route
 
-    def getSourceRoute(self, source_name, route_params):
-        for route in self.getSourceRoutes(source_name):
-            if (route_params is None or
-                    route.matchesParameters(route_params)):
-                return route
-        return None
+        from piecrust.routing import RouteNotFoundError
+        raise RouteNotFoundError(source_name)
 
     def getPublisher(self, target_name):
         for pub in self.publishers:
@@ -213,11 +213,11 @@
                 return pub
         return None
 
-    def getPage(self, content_item):
+    def getPage(self, source, content_item):
         cache_key = content_item.spec
         return self.env.page_repository.get(
             cache_key,
-            lambda: Page(content_item))
+            lambda: Page(source, content_item))
 
     def _get_dir(self, default_rel_dir):
         abs_dir = os.path.join(self.root_dir, default_rel_dir)