Mercurial > piecrust2
diff piecrust/routing.py @ 334:b034f6f15e22
bake: Several bug taxonomy-related fixes for incorrect incremental bakes.
* Improve how the baker processes taxonomy terms and figures out what needs
to be re-baked or not.
* Create bake entries for clean taxnomy terms so they're not deleted by an
incremental bake.
* Add more information to bake records.
* Slugify taxonomy terms is now done by the route in one place.
* Fix a bug where the cache key for invalidating rendered segments was not
computed the same way as when the caching was done.
* Fix how term combinations are passed around, rendered, printed, parsed, etc.
(TODO: more word needed in the routing functions)
* Expose to the template whether a taxonomy term is a combination or not.
* Display term combinations better in the built-in theme.
* Rename `route.taxonomy` to `route.taxonomy_name` to prevent confusion.
* Add options to show bake records for previous bakes.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 03 Apr 2015 10:59:50 -0700 |
parents | 422052d2e978 |
children | 49408002798e |
line wrap: on
line diff
--- a/piecrust/routing.py Fri Apr 03 08:44:21 2015 -0700 +++ b/piecrust/routing.py Fri Apr 03 10:59:50 2015 -0700 @@ -27,6 +27,9 @@ def __init__(self, app, cfg): self.app = app + self.source_name = cfg['source'] + self.taxonomy_name = cfg.get('taxonomy') + self.pretty_urls = app.config.get('site/pretty_urls') self.trailing_slash = app.config.get('site/trailing_slash') self.pagination_suffix_format = app.config.get( @@ -66,8 +69,6 @@ for m in route_re.finditer(self.uri_pattern): self.required_source_metadata.add(m.group('name')) - self.source_name = cfg['source'] - self.taxonomy = cfg.get('taxonomy') self.template_func = None self.template_func_name = None self.template_func_args = [] @@ -157,6 +158,19 @@ uri = self.uri_root + uri return uri + def slugifyTaxonomyTerm(self, term): + #TODO: add options for transliterating and combining terms. + if isinstance(term, tuple): + return '/'.join(term) + return term + + def unslugifyTaxonomyTerm(self, term): + #TODO: same as above. + split_terms = term.split('/') + if len(split_terms) == 1: + return term + return tuple(split_terms) + def _uriFormatRepl(self, m): name = m.group('name') #TODO: fix this hard-coded shit @@ -171,7 +185,7 @@ def _uriPatternRepl(self, m): name = m.group('name') qualifier = m.group('qual') - if qualifier == 'path': + if qualifier == 'path' or self.taxonomy_name: return r'(?P<%s>[^\?]*)' % name return r'(?P<%s>[^/\?]+)' % name @@ -198,7 +212,7 @@ if arg_list: self.template_func_args += template_func_arg_re.findall(arg_list) - if self.taxonomy: + if self.taxonomy_name: # This will be a taxonomy route function... this means we can # have a variable number of parameters, but only one parameter # definition, which is the value. @@ -226,12 +240,10 @@ registered_values = tuple(values) eis = self.app.env.exec_info_stack eis.current_page_info.render_ctx.used_taxonomy_terms.add( - (self.source_name, self.taxonomy, registered_values)) + (self.source_name, self.taxonomy_name, + registered_values)) - if len(values) == 1: - str_values = values[0] - else: - str_values = '/'.join(values) + str_values = self.slugifyTaxonomyTerm(registered_values) term_name = self.template_func_args[0] metadata = {term_name: str_values} @@ -270,7 +282,7 @@ self._funcs.append((route, route.template_func)) def __call__(self, *args, **kwargs): - if len(args) == len(self._arg_names): + if len(self._funcs) == 1 or len(args) == len(self._arg_names): f = self._funcs[0][1] return f(*args, **kwargs)