diff piecrust/sources/base.py @ 363:dd25bd3ce1f9

serve: Refactoring and fixes to be able to serve taxonomy pages. * Page sources' `findPagePath` is renamed to `findPageFactory`, so that it also returns source metadata. * Page refs now store possible hits more properly, and use the previous point to also store metadata. As a result, they can also return a proper factory. * Implement `findPageFactory` correctly in all built-in sources. * When the Chef server matches a taxonomy page, get the source metadata from the page ref in order to make a more proper page. * Make the `getRoute(s)` functions explicitely say if they want taxonomy routes or not.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 26 Apr 2015 15:07:40 -0700
parents ac9b94c8fb37
children 4b1019bb2533
line wrap: on
line diff
--- a/piecrust/sources/base.py	Sun Apr 26 08:34:27 2015 -0700
+++ b/piecrust/sources/base.py	Sun Apr 26 15:07:40 2015 -0700
@@ -45,7 +45,8 @@
 
     @cached_property
     def path(self):
-        return self.source.resolveRef(self.rel_path)
+        path, _ = self.source.resolveRef(self.rel_path)
+        return path
 
     def buildPage(self):
         repo = self.source.app.env.page_repository
@@ -94,10 +95,10 @@
         return build_pages(self.app, self.getPageFactories())
 
     def getPage(self, metadata):
-        rel_path, metadata = self.findPagePath(metadata, MODE_PARSING)
-        if rel_path is None:
+        factory = self.findPageFactory(metadata, MODE_PARSING)
+        if factory is None:
             return None
-        return Page(self, metadata, rel_path)
+        return factory.buildPage()
 
     def getPageFactories(self):
         if self._factories is None:
@@ -108,9 +109,12 @@
         raise NotImplementedError()
 
     def resolveRef(self, ref_path):
+        """ Returns the full path and source metadata given a source
+            (relative) path, like a ref-spec.
+        """
         raise NotImplementedError()
 
-    def findPagePath(self, metadata, mode):
+    def findPageFactory(self, metadata, mode):
         raise NotImplementedError()
 
     def buildDataProvider(self, page, user_data):