Mercurial > piecrust2
diff piecrust/sources/default.py @ 577:ff404adfcf45
sources: Add method to get a page factory from a path.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 30 Dec 2015 14:45:57 -0800 |
parents | 0c74a6c4533d |
children | 58ebf50235a5 |
line wrap: on
line diff
--- a/piecrust/sources/default.py Sat Dec 19 18:07:21 2015 -0800 +++ b/piecrust/sources/default.py Wed Dec 30 14:45:57 2015 -0800 @@ -58,6 +58,17 @@ self._populateMetadata(fac_path, metadata) yield PageFactory(self, fac_path, metadata) + def buildPageFactory(self, path): + if not path.startswith(self.fs_endpoint_path): + raise Exception("Page path '%s' isn't inside '%s'." % ( + path, self.fs_enpoint_path)) + rel_path = path[len(self.fs_endpoint_path):].lstrip('\\/') + slug = self._makeSlug(rel_path) + metadata = {'slug': slug} + fac_path = rel_path.replace('\\', '/') + self._populateMetadata(fac_path, metadata) + return PageFactory(self, fac_path, metadata) + def resolveRef(self, ref_path): path = os.path.normpath( os.path.join(self.fs_endpoint_path, ref_path.lstrip("\\/")))