Mercurial > piecrust2
comparison piecrust/sources/mixins.py @ 853:f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
The asset pipeline is still the only function pipeline at this point.
* No more `QualifiedPage`, and several other pieces of code deleted.
* Data providers are simpler and more focused. For instance, the page iterator
doesn't try to support other types of items.
* Route parameters are proper known source metadata to remove the confusion
between the two.
* Make the baker and pipeline more correctly manage records and record
histories.
* Add support for record collapsing and deleting stale outputs in the asset
pipeline.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 21 May 2017 00:06:59 -0700 |
parents | 4850f8c21b6e |
children | fddaf43424e2 |
comparison
equal
deleted
inserted
replaced
852:4850f8c21b6e | 853:f070a4fc033c |
---|---|
1 import os.path | 1 import os.path |
2 import logging | 2 import logging |
3 from piecrust import osutil | 3 from piecrust import osutil |
4 from piecrust.data.paginationdata import PaginationData | |
5 from piecrust.sources.base import ContentItem | 4 from piecrust.sources.base import ContentItem |
6 from piecrust.sources.interfaces import IPaginationSource | |
7 | 5 |
8 | 6 |
9 logger = logging.getLogger(__name__) | 7 logger = logging.getLogger(__name__) |
10 | 8 |
11 assets_suffix = '-assets' | 9 assets_suffix = '-assets' |
12 | |
13 | |
14 class ContentSourceIterator(object): | |
15 def __init__(self, source): | |
16 self.source = source | |
17 | |
18 # This is to permit recursive traversal of the | |
19 # iterator chain. It acts as the end. | |
20 self.it = None | |
21 | |
22 def __iter__(self): | |
23 return self.source.getAllContentItems() | |
24 | |
25 | |
26 class DateSortIterator(object): | |
27 def __init__(self, it, reverse=True): | |
28 self.it = it | |
29 self.reverse = reverse | |
30 | |
31 def __iter__(self): | |
32 return iter(sorted(self.it, | |
33 key=lambda x: x.datetime, reverse=self.reverse)) | |
34 | |
35 | |
36 class PaginationDataBuilderIterator(object): | |
37 def __init__(self, it): | |
38 self.it = it | |
39 | |
40 def __iter__(self): | |
41 for page in self.it: | |
42 if page is not None: | |
43 yield PaginationData(page) | |
44 else: | |
45 yield None | |
46 | |
47 | |
48 class SimplePaginationSourceMixin(IPaginationSource): | |
49 """ Implements the `IPaginationSource` interface in a standard way that | |
50 should fit most page sources. | |
51 """ | |
52 def getItemsPerPage(self): | |
53 return self.config['items_per_page'] | |
54 | |
55 def getSourceIterator(self): | |
56 return ContentSourceIterator(self) | |
57 | |
58 def getSorterIterator(self, it): | |
59 return DateSortIterator(it) | |
60 | |
61 def getTailIterator(self, it): | |
62 return PaginationDataBuilderIterator(it) | |
63 | 10 |
64 | 11 |
65 class SimpleAssetsSubDirMixin: | 12 class SimpleAssetsSubDirMixin: |
66 def _getRelatedAssetsContents(self, item, relationship): | 13 def _getRelatedAssetsContents(self, item, relationship): |
67 if not item.metadata.get('__has_assets', False): | 14 if not item.metadata.get('__has_assets', False): |