diff piecrust/sources/array.py @ 242:f130365568ff

internal: Code reorganization to put less stuff in `sources.base`. Interfaces that sources can implement are in `sources.interfaces`. The default page source is in `sources.default`. The `SimplePageSource` is gone since most subclasses only wanted to do *some* stuff the same, but *lots* of stuff slightly different. I may have to revisit the code to extract exactly the code that's in common.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 18 Feb 2015 18:35:03 -0800
parents
children e7b865f8f335
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/piecrust/sources/array.py	Wed Feb 18 18:35:03 2015 -0800
@@ -0,0 +1,43 @@
+from piecrust.sources.base import PageSource
+from piecrust.sources.mixins import SimplePaginationSourceMixin
+
+
+class CachedPageFactory(object):
+    """ A `PageFactory` (in appearance) that already has a page built.
+    """
+    def __init__(self, page):
+        self._page = page
+
+    @property
+    def rel_path(self):
+        return self._page.rel_path
+
+    @property
+    def metadata(self):
+        return self._page.source_metadata
+
+    @property
+    def ref_spec(self):
+        return self._page.ref_spec
+
+    @property
+    def path(self):
+        return self._page.path
+
+    def buildPage(self):
+        return self._page
+
+
+class ArraySource(PageSource, SimplePaginationSourceMixin):
+    def __init__(self, app, inner_source, name='array', config=None):
+        super(ArraySource, self).__init__(app, name, config or {})
+        self.inner_source = inner_source
+
+    @property
+    def page_count(self):
+        return len(self.inner_source)
+
+    def getPageFactories(self):
+        for p in self.inner_source:
+            yield CachedPageFactory(p)
+