diff piecrust/sources/prose.py @ 170:c3831a762bc2

sources: Make the `SimplePageSource` more extensible, fix bugs in `prose` source. The `SimplePageSource` now calls a `_populateMetadata` function that subclasses can override to add/edit their custom metadata everwhere it would be returned to the system.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 03 Jan 2015 20:49:00 -0800
parents 55910ab4bfea
children e61fbae61402
line wrap: on
line diff
--- a/piecrust/sources/prose.py	Sat Jan 03 18:06:52 2015 -0800
+++ b/piecrust/sources/prose.py	Sat Jan 03 20:49:00 2015 -0800
@@ -16,22 +16,13 @@
         super(ProseSource, self).__init__(app, name, config)
         self.config_recipe = config.get('config', {})
 
-    def buildPageFactories(self):
-        factories = super(ProseSource, self).buildPageFactories()
-        for f in factories:
-            f.metadata['config'] = self._makeConfig(f.path)
-            logger.debug(f.__dict__)
-            yield f
+    def _populateMetadata(self, rel_path, metadata):
+        metadata['config'] = self._makeConfig(rel_path)
 
-    def findPagePath(self, metadata, mode):
-        rel_path, metadata = super(ProseSource, self).findPagePath(metadata, mode)
-        if rel_path:
-            metadata['config'] = self._makeConfig(self.resolveRef(rel_path))
-        return rel_path, metadata
-
-    def _makeConfig(self, path):
+    def _makeConfig(self, rel_path):
         c = dict(self.config_recipe)
         if c.get('title') == '%first_line%':
+            path = os.path.join(self.fs_endpoint_path, rel_path)
             c['title'] = get_first_line(path)
         return c