diff piecrust/serving.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 741e97e63048
children 4b1019bb2533
line wrap: on
line diff
--- a/piecrust/serving.py	Sun Apr 26 08:34:27 2015 -0700
+++ b/piecrust/serving.py	Sun Apr 26 15:07:40 2015 -0700
@@ -231,19 +231,17 @@
         for route, route_metadata in routes:
             source = app.getSource(route.source_name)
             if route.taxonomy_name is None:
-                rel_path, fac_metadata = source.findPagePath(
-                        route_metadata, MODE_PARSING)
-                if rel_path is not None:
+                factory = source.findPageFactory(route_metadata, MODE_PARSING)
+                if factory is not None:
                     break
             else:
                 taxonomy = app.getTaxonomy(route.taxonomy_name)
                 route_terms = route_metadata.get(taxonomy.term_name)
                 if route_terms is not None:
                     tax_page_ref = taxonomy.getPageRef(source.name)
-                    rel_path = tax_page_ref.rel_path
-                    source = tax_page_ref.source
+                    factory = tax_page_ref.getFactory()
                     tax_terms = route.unslugifyTaxonomyTerm(route_terms)
-                    fac_metadata = {taxonomy.term_name: tax_terms}
+                    factory.metadata[taxonomy.term_name] = tax_terms
                     break
         else:
             raise SourceNotFoundError(
@@ -251,8 +249,7 @@
                     (req_path, [r.source_name for r, _ in routes]))
 
         # Build the page.
-        fac = PageFactory(source, rel_path, fac_metadata)
-        page = fac.buildPage()
+        page = factory.buildPage()
         # We force the rendering of the page because it could not have
         # changed, but include pages that did change.
         render_ctx = PageRenderingContext(page, req_path, page_num,