Mercurial > piecrust2
diff piecrust/routing.py @ 147:ab6e7e0e9d44
Pass date information to routing when building URLs.
This is so that URLs with dates in them can be built even when the date
information is not coming from the source metadata, but from the page's
config.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 29 Nov 2014 21:00:44 -0800 |
parents | f485ba500df3 |
children | a42469dbdc47 |
line wrap: on
line diff
--- a/piecrust/routing.py Sat Nov 29 20:58:28 2014 -0800 +++ b/piecrust/routing.py Sat Nov 29 21:00:44 2014 -0800 @@ -10,6 +10,11 @@ template_func_arg_re = re.compile(r',\s*(?P<arg>\w+)') +class IRouteMetadataProvider(object): + def getRouteMetadata(self): + raise NotImplementedError() + + class Route(object): """ Information about a route for a PieCrust application. Each route defines the "shape" of an URL and how it maps to @@ -48,7 +53,10 @@ def isMatch(self, source_metadata): return True - def getUri(self, source_metadata): + def getUri(self, source_metadata, provider=None): + if provider: + source_metadata = dict(source_metadata) + source_metadata.update(provider.getRouteMetadata()) #TODO: fix this hard-coded shit for key in ['year', 'month', 'day']: if key in source_metadata and isinstance(source_metadata[key], str):