Mercurial > piecrust2
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 241:85a6c7ba5e3b | 242:f130365568ff |
|---|---|
| 1 from piecrust.sources.base import PageSource | |
| 2 from piecrust.sources.mixins import SimplePaginationSourceMixin | |
| 3 | |
| 4 | |
| 5 class CachedPageFactory(object): | |
| 6 """ A `PageFactory` (in appearance) that already has a page built. | |
| 7 """ | |
| 8 def __init__(self, page): | |
| 9 self._page = page | |
| 10 | |
| 11 @property | |
| 12 def rel_path(self): | |
| 13 return self._page.rel_path | |
| 14 | |
| 15 @property | |
| 16 def metadata(self): | |
| 17 return self._page.source_metadata | |
| 18 | |
| 19 @property | |
| 20 def ref_spec(self): | |
| 21 return self._page.ref_spec | |
| 22 | |
| 23 @property | |
| 24 def path(self): | |
| 25 return self._page.path | |
| 26 | |
| 27 def buildPage(self): | |
| 28 return self._page | |
| 29 | |
| 30 | |
| 31 class ArraySource(PageSource, SimplePaginationSourceMixin): | |
| 32 def __init__(self, app, inner_source, name='array', config=None): | |
| 33 super(ArraySource, self).__init__(app, name, config or {}) | |
| 34 self.inner_source = inner_source | |
| 35 | |
| 36 @property | |
| 37 def page_count(self): | |
| 38 return len(self.inner_source) | |
| 39 | |
| 40 def getPageFactories(self): | |
| 41 for p in self.inner_source: | |
| 42 yield CachedPageFactory(p) | |
| 43 |
