Mercurial > piecrust2
comparison piecrust/sources/generator.py @ 856:9bb22bbe093c
refactor: Make the blog archives functional again.
The blog archives are using the same pattern as the taxonomy support.
| author | Ludovic Chabant <ludovic@chabant.com> |
|---|---|
| date | Tue, 06 Jun 2017 01:23:25 -0700 |
| parents | |
| children | d1095774bfcf |
comparison
equal
deleted
inserted
replaced
| 855:448710d84121 | 856:9bb22bbe093c |
|---|---|
| 1 import io | |
| 2 import time | |
| 3 from werkzeug.utils import cached_property | |
| 4 from piecrust.configuration import ConfigurationError | |
| 5 from piecrust.sources.base import ContentSource, GeneratedContentException | |
| 6 | |
| 7 | |
| 8 class GeneratorSourceBase(ContentSource): | |
| 9 def __init__(self, app, name, config): | |
| 10 super().__init__(app, name, config) | |
| 11 | |
| 12 source_name = config.get('source') | |
| 13 if source_name is None: | |
| 14 raise ConfigurationError( | |
| 15 "Taxonomy source '%s' requires an inner source." % name) | |
| 16 self._inner_source_name = source_name | |
| 17 | |
| 18 self._raw_item = '' | |
| 19 | |
| 20 @cached_property | |
| 21 def inner_source(self): | |
| 22 return self.app.getSource(self._inner_source_name) | |
| 23 | |
| 24 def getContents(self, group): | |
| 25 # Our content is procedurally generated from other content sources, | |
| 26 # so we really don't support listing anything here -- it would be | |
| 27 # typically quite costly. | |
| 28 raise GeneratedContentException() | |
| 29 | |
| 30 def openItem(self, item, mode='r', **kwargs): | |
| 31 return io.StringIO(self._raw_item) | |
| 32 | |
| 33 def getItemMtime(self, item): | |
| 34 return time.time() | |
| 35 |
