comparison piecrust/appconfig.py @ 787:f6f9a284a5f3

routing: Simplify how route functions are declared and handled. * Site config now only has to declare the function name. * Simply code for running route functions.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 01 Sep 2016 23:00:58 -0700
parents 7dbddfed8129
children 58ebf50235a5
comparison
equal deleted inserted replaced
786:97c1dc568810 787:f6f9a284a5f3
285 }), 285 }),
286 'routes': [ 286 'routes': [
287 { 287 {
288 'url': '/%path:slug%', 288 'url': '/%path:slug%',
289 'source': 'theme_pages', 289 'source': 'theme_pages',
290 'func': 'pcurl(slug)' 290 'func': 'pcurl'
291 } 291 }
292 ], 292 ],
293 'theme_tag_page': 'theme_pages:_tag.%ext%', 293 'theme_tag_page': 'theme_pages:_tag.%ext%',
294 'theme_category_page': 'theme_pages:_category.%ext%', 294 'theme_category_page': 'theme_pages:_category.%ext%',
295 'theme_month_page': 'theme_pages:_month.%ext%', 295 'theme_month_page': 'theme_pages:_month.%ext%',
337 'posts_fs': DEFAULT_POSTS_FS, 337 'posts_fs': DEFAULT_POSTS_FS,
338 'default_page_layout': 'default', 338 'default_page_layout': 'default',
339 'default_post_layout': 'post', 339 'default_post_layout': 'post',
340 'post_url': '/%int4:year%/%int2:month%/%int2:day%/%slug%', 340 'post_url': '/%int4:year%/%int2:month%/%int2:day%/%slug%',
341 'year_url': '/archives/%int4:year%', 341 'year_url': '/archives/%int4:year%',
342 'tag_url': '/tag/%path:tag%', 342 'tag_url': '/tag/%+tag%',
343 'category_url': '/%category%', 343 'category_url': '/%category%',
344 'posts_per_page': 5 344 'posts_per_page': 5
345 }) 345 })
346 }) 346 })
347 347
363 }), 363 }),
364 'routes': [ 364 'routes': [
365 { 365 {
366 'url': '/%path:slug%', 366 'url': '/%path:slug%',
367 'source': 'pages', 367 'source': 'pages',
368 'func': 'pcurl(slug)' 368 'func': 'pcurl'
369 } 369 }
370 ], 370 ],
371 'taxonomies': collections.OrderedDict([ 371 'taxonomies': collections.OrderedDict([
372 ('tags', { 372 ('tags', {
373 'multiple': True, 373 'multiple': True,
465 }), 465 }),
466 'routes': [ 466 'routes': [
467 { 467 {
468 'url': post_url, 468 'url': post_url,
469 'source': blog_name, 469 'source': blog_name,
470 'func': ( 470 'func': ('%sposturl' % tpl_func_prefix)
471 '%sposturl(int:year,int:month,int:day,slug)' %
472 tpl_func_prefix)
473 }, 471 },
474 { 472 {
475 'url': year_url, 473 'url': year_url,
476 'generator': ('%s_archives' % blog_name), 474 'generator': ('%s_archives' % blog_name),
477 'func': ('%syearurl(year)' % tpl_func_prefix) 475 'func': ('%syearurl' % tpl_func_prefix)
478 } 476 }
479 ] 477 ]
480 }) 478 })
481 }) 479 })
482 480
508 (blog_cfg, tax_url_cfg_name), 506 (blog_cfg, tax_url_cfg_name),
509 (user_overrides, 'site/%s' % tax_url_cfg_name), 507 (user_overrides, 'site/%s' % tax_url_cfg_name),
510 (values, 'site/%s' % tax_url_cfg_name), 508 (values, 'site/%s' % tax_url_cfg_name),
511 default=('%s/%%%s%%' % (term, term))) 509 default=('%s/%%%s%%' % (term, term)))
512 tax_url = '/' + url_prefix + tax_url.lstrip('/') 510 tax_url = '/' + url_prefix + tax_url.lstrip('/')
513 term_arg = term
514 if tax_cfg.get('multiple') is True:
515 term_arg = '+' + term
516 tax_func_name = try_get_dict_values( 511 tax_func_name = try_get_dict_values(
517 (user_overrides, 'site/taxonomies/%s/func_name' % tax_name), 512 (user_overrides, 'site/taxonomies/%s/func_name' % tax_name),
518 (values, 'site/taxonomies/%s/func_name' % tax_name), 513 (values, 'site/taxonomies/%s/func_name' % tax_name),
519 default=('%s%surl' % (tpl_func_prefix, term))) 514 default=('%s%surl' % (tpl_func_prefix, term)))
520 tax_func = '%s(%s)' % (tax_func_name, term_arg)
521 tax_route = collections.OrderedDict({ 515 tax_route = collections.OrderedDict({
522 'url': tax_url, 516 'url': tax_url,
523 'generator': tax_gen_name, 517 'generator': tax_gen_name,
524 'taxonomy': tax_name, 518 'taxonomy': tax_name,
525 'func': tax_func 519 'func': tax_func_name
526 }) 520 })
527 cfg['site']['routes'].append(tax_route) 521 cfg['site']['routes'].append(tax_route)
528 522
529 return cfg 523 return cfg
530 524