Mercurial > piecrust2
changeset 730:8c3c2b949b82
routing: Fix problems with route functions.
Instead of using merged functions with multiblog sites, use different
functions. Add some options to customize the function names.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 01 Jun 2016 22:10:47 -0700 |
parents | e35407c60e00 |
children | dafb7d76c2ba |
files | piecrust/__init__.py piecrust/appconfig.py piecrust/routing.py |
diffstat | 3 files changed, 22 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/piecrust/__init__.py Wed Jun 01 22:09:21 2016 -0700 +++ b/piecrust/__init__.py Wed Jun 01 22:10:47 2016 -0700 @@ -18,7 +18,7 @@ PIECRUST_URL = 'https://bolt80.com/piecrust/' -CACHE_VERSION = 25 +CACHE_VERSION = 26 try: from piecrust.__version__ import APP_VERSION
--- a/piecrust/appconfig.py Wed Jun 01 22:09:21 2016 -0700 +++ b/piecrust/appconfig.py Wed Jun 01 22:10:47 2016 -0700 @@ -398,6 +398,7 @@ fs_endpoint = 'posts' data_endpoint = 'blog' item_name = 'post' + tpl_func_prefix = 'pc' if theme_site: # If this is a theme site, show posts from a `sample` directory @@ -407,9 +408,14 @@ else: url_prefix = blog_name + '/' page_prefix = blog_name + '/' + data_endpoint = blog_name fs_endpoint = 'posts/%s' % blog_name - data_endpoint = blog_name - item_name = '%s-post' % blog_name + item_name = try_get_dict_value(user_overrides, + '%s/item_name' % blog_name, + '%spost' % blog_name) + tpl_func_prefix = try_get_dict_value(user_overrides, + '%s/func_prefix' % blog_name, + 'pc%s' % blog_name) # Figure out the settings values for this blog, specifically. # The value could be set on the blog config itself, globally, or left at @@ -459,12 +465,14 @@ { 'url': post_url, 'source': blog_name, - 'func': 'pcposturl(int:year,int:month,int:day,slug)' + 'func': ( + '%sposturl(int:year,int:month,int:day,slug)' % + tpl_func_prefix) }, { 'url': year_url, 'generator': ('%s_archives' % blog_name), - 'func': 'pcyearurl(archive_year)' + 'func': ('%syearurl(year)' % tpl_func_prefix) } ] }) @@ -505,7 +513,7 @@ term_arg = term if tax_cfg.get('multiple') is True: term_arg = '+' + term - tax_func = 'pc%surl(%s)' % (term, term_arg) + tax_func = '%s%surl(%s)' % (tpl_func_prefix, term, term_arg) tax_route = collections.OrderedDict({ 'url': tax_url, 'generator': tax_gen_name,
--- a/piecrust/routing.py Wed Jun 01 22:09:21 2016 -0700 +++ b/piecrust/routing.py Wed Jun 01 22:10:47 2016 -0700 @@ -12,7 +12,7 @@ route_re = re.compile(r'%((?P<qual>[\w\d]+):)?(?P<name>\w+)%') route_esc_re = re.compile(r'\\%((?P<qual>[\w\d]+)\\:)?(?P<name>\w+)\\%') template_func_re = re.compile(r'^(?P<name>\w+)\((?P<args>.*)\)\s*$') -template_func_arg_re = re.compile(r'(?P<arg>\+?\w+)') +template_func_arg_re = re.compile(r'((?P<qual>[\w\d]+):)?(?P<arg>\+?\w+)') ugly_url_cleaner = re.compile(r'\.html$') @@ -288,7 +288,9 @@ self.template_func_args = [] arg_list = m.group('args') if arg_list: - self.template_func_args = template_func_arg_re.findall(arg_list) + self.template_func_args = [] + for m2 in template_func_arg_re.finditer(arg_list): + self.template_func_args.append(m2.group('arg')) for i in range(len(self.template_func_args) - 1): if self.template_func_args[i][0] == '+': raise Exception("Only the last route parameter can be a " @@ -303,15 +305,15 @@ if not is_variable and len(args) != len(self.template_func_args): raise Exception( "Route function '%s' expected %d arguments, " - "got %d." % + "got %d: %s" % (func_def, len(self.template_func_args), - len(args))) + len(args), args)) elif is_variable and len(args) < len(self.template_func_args): raise Exception( "Route function '%s' expected at least %d arguments, " - "got %d." % + "got %d: %s" % (func_def, len(self.template_func_args), - len(args))) + len(args), args)) metadata = {} non_var_args = list(self.template_func_args)