# HG changeset patch # User Ludovic Chabant # Date 1465010518 25200 # Node ID 7705b3d981cad70ac83eed5aaaee1ac77e90ad75 # Parent 9231172e3d81e1270a4dc8ccce7f570c5e2dd1ba templating: Make the 'categories' taxonomy use a 'pccaturl' function again. diff -r 9231172e3d81 -r 7705b3d981ca piecrust/__init__.py --- a/piecrust/__init__.py Thu Jun 02 20:26:51 2016 -0700 +++ b/piecrust/__init__.py Fri Jun 03 20:21:58 2016 -0700 @@ -18,7 +18,7 @@ PIECRUST_URL = 'https://bolt80.com/piecrust/' -CACHE_VERSION = 26 +CACHE_VERSION = 27 try: from piecrust.__version__ import APP_VERSION diff -r 9231172e3d81 -r 7705b3d981ca piecrust/appconfig.py --- a/piecrust/appconfig.py Thu Jun 02 20:26:51 2016 -0700 +++ b/piecrust/appconfig.py Fri Jun 03 20:21:58 2016 -0700 @@ -14,7 +14,8 @@ from piecrust.cache import NullCache from piecrust.configuration import ( Configuration, ConfigurationError, ConfigurationLoader, - try_get_dict_value, set_dict_value, merge_dicts, visit_dict) + try_get_dict_value, try_get_dict_values, + set_dict_value, merge_dicts, visit_dict) from piecrust.sources.base import REALM_USER, REALM_THEME @@ -373,7 +374,8 @@ 'term': 'tag' }), ('categories', { - 'term': 'category' + 'term': 'category', + 'func_name': 'pccaturl' }) ]) }) @@ -502,18 +504,20 @@ # Route. tax_url_cfg_name = '%s_url' % term - tax_url = blog_cfg.get(tax_url_cfg_name, - try_get_dict_value( - user_overrides, - 'site/%s' % tax_url_cfg_name, - values['site'].get( - tax_url_cfg_name, - '%s/%%%s%%' % (term, term)))) + tax_url = try_get_dict_values( + (blog_cfg, tax_url_cfg_name), + (user_overrides, 'site/%s' % tax_url_cfg_name), + (values, 'site/%s' % tax_url_cfg_name), + default=('%s/%%%s%%' % (term, term))) tax_url = '/' + url_prefix + tax_url.lstrip('/') term_arg = term if tax_cfg.get('multiple') is True: term_arg = '+' + term - tax_func = '%s%surl(%s)' % (tpl_func_prefix, term, term_arg) + tax_func_name = try_get_dict_values( + (user_overrides, 'site/taxonomies/%s/func_name' % tax_name), + (values, 'site/taxonomies/%s/func_name' % tax_name), + default=('%s%surl' % (tpl_func_prefix, term))) + tax_func = '%s(%s)' % (tax_func_name, term_arg) tax_route = collections.OrderedDict({ 'url': tax_url, 'generator': tax_gen_name, diff -r 9231172e3d81 -r 7705b3d981ca piecrust/configuration.py --- a/piecrust/configuration.py Thu Jun 02 20:26:51 2016 -0700 +++ b/piecrust/configuration.py Fri Jun 03 20:21:58 2016 -0700 @@ -131,6 +131,15 @@ return default +def try_get_dict_values(*args, default=None): + for d, key in args: + try: + return get_dict_value(d, key) + except KeyError: + continue + return default + + def set_dict_value(d, key, value): bits = key.split('/') bitslen = len(bits) diff -r 9231172e3d81 -r 7705b3d981ca tests/bakes/test_simple_categories.yaml --- a/tests/bakes/test_simple_categories.yaml Thu Jun 02 20:26:51 2016 -0700 +++ b/tests/bakes/test_simple_categories.yaml Fri Jun 03 20:21:58 2016 -0700 @@ -23,6 +23,7 @@ {% for p in pagination.posts -%} {{p.title}} {% endfor %} + pages/link.md: 'Link: {{pccaturl("bar")}}' pages/_index.md: '' out: index.html: '' @@ -34,6 +35,7 @@ post02.html: '' '03': post03.html: '' + link.html: 'Link: /cat/bar.html' cat: foo.html: | Pages in foo