Mercurial > piecrust2
view piecrust/sources/prose.py @ 979:45ad976712ec
tests: Big push to get the tests to pass again.
- Lots of fixes everywhere in the code.
- Try to handle debug logging in the multiprocessing worker pool when running in pytest. Not perfect, but usable for now.
- Replace all `.md` test files with `.html` since now a auto-format extension always sets the format.
- Replace `out` with `outfiles` in most places since now blog archives are added to the bake output and I don't want to add expected outputs for blog archives everywhere.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 29 Oct 2017 22:51:57 -0700 |
parents | d9059257743c |
children | a4d7ff2cdc5c |
line wrap: on
line source
import copy import logging from piecrust.sources.default import DefaultContentSource logger = logging.getLogger(__name__) class ProseSource(DefaultContentSource): SOURCE_NAME = 'prose' def __init__(self, app, name, config): super().__init__(app, name, config) self.config_recipe = config.get('config', {}) def _doCreateItemMetadata(self, path): metadata = super()._doCreateItemMetadata(path) config = metadata.setdefault('config', {}) config.update(self._makeConfig(path)) return metadata def _makeConfig(self, path): c = copy.deepcopy(self.config_recipe) if c.get('title') == '%first_line%': c['title'] = get_first_line(path) return c def get_first_line(path): with open(path, 'r') as f: while True: l = f.readline() if not l: break l = l.strip() if not l: continue return l return None