diff piecrust/app.py @ 329:422052d2e978

internal: Try handling URLs in a consistent way. * Now URLs passed to, and returned from, routes will always be absolute URLs, i.e. URLs including the site root. * Validate the site root at config loading time to make sure it starts and ends with a slash. * Get rid of unused stuff. * Add tests.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 31 Mar 2015 23:03:28 -0700
parents edcc9dc17b37
children b034f6f15e22
line wrap: on
line diff
--- a/piecrust/app.py	Tue Mar 31 22:38:56 2015 -0700
+++ b/piecrust/app.py	Tue Mar 31 23:03:28 2015 -0700
@@ -28,7 +28,7 @@
 logger = logging.getLogger(__name__)
 
 
-CACHE_VERSION = 17
+CACHE_VERSION = 18
 
 
 class VariantNotFoundError(Exception):
@@ -136,6 +136,12 @@
         cachec = collections.OrderedDict()
         values['__cache'] = cachec
 
+        # Make sure the site root starts and ends with a slash.
+        if not sitec['root'].startswith('/'):
+            raise ConfigurationError("The `site/root` setting must start "
+                                     "with a slash.")
+        sitec['root'] = sitec['root'].rstrip('/') + '/'
+
         # Cache auto-format regexes.
         if not isinstance(sitec['auto_formats'], dict):
             raise ConfigurationError("The 'site/auto_formats' setting must be "