diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/piecrust/sources/generator.py	Tue Jun 06 01:23:25 2017 -0700
@@ -0,0 +1,35 @@
+import io
+import time
+from werkzeug.utils import cached_property
+from piecrust.configuration import ConfigurationError
+from piecrust.sources.base import ContentSource, GeneratedContentException
+
+
+class GeneratorSourceBase(ContentSource):
+    def __init__(self, app, name, config):
+        super().__init__(app, name, config)
+
+        source_name = config.get('source')
+        if source_name is None:
+            raise ConfigurationError(
+                "Taxonomy source '%s' requires an inner source." % name)
+        self._inner_source_name = source_name
+
+        self._raw_item = ''
+
+    @cached_property
+    def inner_source(self):
+        return self.app.getSource(self._inner_source_name)
+
+    def getContents(self, group):
+        # Our content is procedurally generated from other content sources,
+        # so we really don't support listing anything here -- it would be
+        # typically quite costly.
+        raise GeneratedContentException()
+
+    def openItem(self, item, mode='r', **kwargs):
+        return io.StringIO(self._raw_item)
+
+    def getItemMtime(self, item):
+        return time.time()
+