comparison piecrust/page.py @ 792:58ebf50235a5

routing: Simplify how routes are defined. * No more declaring the type of route parameters -- the sources and generators already know what type each parameter is supposed to be. * Same for variadic parameters -- we know already. * Update cache version to force a clear reload of the config. * Update tests. TODO: simplify code in the `Route` class to use source or generator transparently.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 07 Sep 2016 08:58:41 -0700
parents e7481bbbb29f
children e01473c3ea7e
comparison
equal deleted inserted replaced
791:504d6817352d 792:58ebf50235a5
9 import collections 9 import collections
10 from werkzeug.utils import cached_property 10 from werkzeug.utils import cached_property
11 from piecrust.configuration import ( 11 from piecrust.configuration import (
12 Configuration, ConfigurationError, 12 Configuration, ConfigurationError,
13 parse_config_header) 13 parse_config_header)
14 from piecrust.routing import IRouteMetadataProvider
15 14
16 15
17 logger = logging.getLogger(__name__) 16 logger = logging.getLogger(__name__)
18 17
19 18
35 34
36 FLAG_NONE = 0 35 FLAG_NONE = 0
37 FLAG_RAW_CACHE_VALID = 2**0 36 FLAG_RAW_CACHE_VALID = 2**0
38 37
39 38
40 class Page(IRouteMetadataProvider): 39 class Page(object):
41 def __init__(self, source, source_metadata, rel_path): 40 def __init__(self, source, source_metadata, rel_path):
42 self.source = source 41 self.source = source
43 self.source_metadata = source_metadata 42 self.source_metadata = source_metadata
44 self.rel_path = rel_path 43 self.rel_path = rel_path
45 self._config = None 44 self._config = None
138 self._config = config 137 self._config = config
139 self._segments = content 138 self._segments = content
140 if was_cache_valid: 139 if was_cache_valid:
141 self._flags |= FLAG_RAW_CACHE_VALID 140 self._flags |= FLAG_RAW_CACHE_VALID
142 141
143 def getRouteMetadata(self):
144 page_dt = self.datetime
145 return {
146 'year': page_dt.year,
147 'month': page_dt.month,
148 'day': page_dt.day}
149
150 142
151 def _parse_config_date(page_date): 143 def _parse_config_date(page_date):
152 if page_date is None: 144 if page_date is None:
153 return None 145 return None
154 146