Mercurial > piecrust2
comparison 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 |
comparison
equal
deleted
inserted
replaced
185:139179dc7abd | 186:e61fbae61402 |
---|---|
1 import os | 1 import os |
2 import os.path | 2 import os.path |
3 import logging | 3 import logging |
4 from piecrust.sources.base import ( | 4 from piecrust.sources.base import ( |
5 SimplePageSource, SimplePaginationSourceMixin) | 5 SimplePageSource, SimplePaginationSourceMixin, |
6 MODE_CREATING) | |
6 | 7 |
7 | 8 |
8 logger = logging.getLogger(__name__) | 9 logger = logging.getLogger(__name__) |
9 | 10 |
10 | 11 |
14 | 15 |
15 def __init__(self, app, name, config): | 16 def __init__(self, app, name, config): |
16 super(ProseSource, self).__init__(app, name, config) | 17 super(ProseSource, self).__init__(app, name, config) |
17 self.config_recipe = config.get('config', {}) | 18 self.config_recipe = config.get('config', {}) |
18 | 19 |
19 def _populateMetadata(self, rel_path, metadata): | 20 def _populateMetadata(self, rel_path, metadata, mode=None): |
20 metadata['config'] = self._makeConfig(rel_path) | 21 metadata['config'] = self._makeConfig(rel_path, mode) |
21 | 22 |
22 def _makeConfig(self, rel_path): | 23 def _makeConfig(self, rel_path, mode): |
23 c = dict(self.config_recipe) | 24 c = dict(self.config_recipe) |
24 if c.get('title') == '%first_line%': | 25 if c.get('title') == '%first_line%' and mode != MODE_CREATING: |
25 path = os.path.join(self.fs_endpoint_path, rel_path) | 26 path = os.path.join(self.fs_endpoint_path, rel_path) |
26 c['title'] = get_first_line(path) | 27 c['title'] = get_first_line(path) |
27 return c | 28 return c |
28 | 29 |
29 | 30 |