diff piecrust/data/builder.py @ 802:0da1207472d3

templating: Put the routing functions in the data, not the template engine.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 29 Sep 2016 21:52:18 -0700
parents 606f6d57b5df
children 7f235e65ef5d
line wrap: on
line diff
--- a/piecrust/data/builder.py	Thu Sep 29 21:28:20 2016 -0700
+++ b/piecrust/data/builder.py	Thu Sep 29 21:52:18 2016 -0700
@@ -7,6 +7,7 @@
 from piecrust.data.paginator import Paginator
 from piecrust.data.piecrustdata import PieCrustData
 from piecrust.data.providersdata import DataProvidersData
+from piecrust.routing import CompositeRouteFunction
 
 
 logger = logging.getLogger(__name__)
@@ -49,6 +50,20 @@
             'family': linker
             }
 
+    for route in app.routes:
+        name = route.func_name
+        func = data.get(name)
+        if func is None:
+            func = CompositeRouteFunction()
+            func.addFunc(route)
+            data[name] = func
+        elif isinstance(func, CompositeRouteFunction):
+            func.addFunc(route)
+        else:
+            raise Exception("Route function '%s' collides with an "
+                            "existing function or template data." %
+                            name)
+
     #TODO: handle slugified taxonomy terms.
 
     site_data = app.config.getAll()