Mercurial > piecrust2
diff piecrust/sources/base.py @ 11:617191dec18e
Fixes for Windows, make `findPagePath` return a ref path.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 18 Aug 2014 16:47:44 -0700 |
parents | 343d08ef5668 |
children | 105f24f490cb |
line wrap: on
line diff
--- a/piecrust/sources/base.py Sun Aug 17 21:18:48 2014 -0700 +++ b/piecrust/sources/base.py Mon Aug 18 16:47:44 2014 -0700 @@ -294,6 +294,7 @@ self.fs_endpoint = config.get('fs_endpoint', name) self.fs_endpoint_path = os.path.join(self.root_dir, CONTENT_DIR, self.fs_endpoint) self.supported_extensions = list(app.config.get('site/auto_formats').keys()) + self.default_auto_format = app.config.get('site/default_auto_format') def buildPageFactories(self): logger.debug("Scanning for pages in: %s" % self.fs_endpoint_path) @@ -313,22 +314,26 @@ fac_path = f if rel_dirpath != '.': fac_path = os.path.join(rel_dirpath, f) + fac_path = fac_path.replace('\\', '/') yield PageFactory(self, fac_path, metadata) def resolveRef(self, ref_path): - return os.path.join(self.fs_endpoint_path, ref_path) + return os.path.normpath( + os.path.join(self.fs_endpoint_path, ref_path)) def findPagePath(self, metadata, mode): uri_path = metadata['path'] if uri_path == '': uri_path = '_index' - path = os.path.join(self.fs_endpoint_path, uri_path) + path = os.path.normpath(os.path.join(self.fs_endpoint_path, uri_path)) _, ext = os.path.splitext(path) if mode == MODE_CREATING: if ext == '': - return '%s.*' % path - return path, metadata + path = '%s.%s' % (path, self.default_auto_format) + rel_path = os.path.relpath(path, self.fs_endpoint_path) + rel_path = rel_path.replace('\\', '/') + return rel_path, metadata if ext == '': paths_to_check = ['%s.%s' % (path, e) @@ -337,7 +342,9 @@ paths_to_check = [path] for path in paths_to_check: if os.path.isfile(path): - return path, metadata + rel_path = os.path.relpath(path, self.fs_endpoint_path) + rel_path = rel_path.replace('\\', '/') + return rel_path, metadata return None, None @@ -393,5 +400,8 @@ def __iter__(self): for page in self.it: - yield PaginationData(page) + if page is None: + yield None + else: + yield PaginationData(page)