Mercurial > piecrust2
diff piecrust/sources/prose.py @ 186:e61fbae61402
sources: Pass any current mode to `_populateMetadata` when finding pages.
Page sources like the `prose` source may need to open an existing page's
file to read stuff from it. This won't work if the metadata is populated as
part of finding a path to create a page (like when running `chef prepare`).
We pass the mode to `_populateMetadata` so the underlying class now knows
the current context in which it is called.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 04 Jan 2015 15:48:29 -0800 |
parents | c3831a762bc2 |
children | f130365568ff |
line wrap: on
line diff
--- a/piecrust/sources/prose.py Sun Jan 04 14:59:12 2015 -0800 +++ b/piecrust/sources/prose.py Sun Jan 04 15:48:29 2015 -0800 @@ -2,7 +2,8 @@ import os.path import logging from piecrust.sources.base import ( - SimplePageSource, SimplePaginationSourceMixin) + SimplePageSource, SimplePaginationSourceMixin, + MODE_CREATING) logger = logging.getLogger(__name__) @@ -16,12 +17,12 @@ super(ProseSource, self).__init__(app, name, config) self.config_recipe = config.get('config', {}) - def _populateMetadata(self, rel_path, metadata): - metadata['config'] = self._makeConfig(rel_path) + def _populateMetadata(self, rel_path, metadata, mode=None): + metadata['config'] = self._makeConfig(rel_path, mode) - def _makeConfig(self, rel_path): + def _makeConfig(self, rel_path, mode): c = dict(self.config_recipe) - if c.get('title') == '%first_line%': + if c.get('title') == '%first_line%' and mode != MODE_CREATING: path = os.path.join(self.fs_endpoint_path, rel_path) c['title'] = get_first_line(path) return c