Mercurial > piecrust2
changeset 939:abc52a6262a1
bake: Support the `draft` setting.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 04 Oct 2017 20:40:43 -0700 |
parents | 7ecb946bfafd |
children | bfc1b2bdc747 |
files | piecrust/dataproviders/pageiterator.py piecrust/pipelines/_pagerecords.py piecrust/pipelines/page.py |
diffstat | 3 files changed, 27 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/piecrust/dataproviders/pageiterator.py Wed Oct 04 09:15:16 2017 -0700 +++ b/piecrust/dataproviders/pageiterator.py Wed Oct 04 20:40:43 2017 -0700 @@ -219,12 +219,20 @@ if self._has_sorter: return if self._is_content_source: + # For content sources, the default sorting is reverse + # date/time sorting. self._it = DateSortIterator(self._it, reverse=True) self._has_sorter = True def _initIterator(self): if self._is_content_source: self._it = PageContentSourceIterator(self._source) + app = self._source.app + if app.config.get('baker/is_baking'): + # While baking, automatically exclude any page with + # the `draft` setting. + draft_setting = app.config['baker/no_bake_setting'] + self._it = NoDraftsIterator(self._it, draft_setting) else: self._it = GenericSourceIterator(self._source) @@ -365,6 +373,16 @@ yield from source.getAllPages() +class NoDraftsIterator: + def __init__(self, source, no_draft_setting): + self.it = source + self.no_draft_setting = no_draft_setting + + def __iter__(self): + nds = self.no_draft_setting + yield from filter(lambda i: not i.config.get(nds), self.it) + + class PaginationDataBuilderIterator: def __init__(self, it): self.it = it
--- a/piecrust/pipelines/_pagerecords.py Wed Oct 04 09:15:16 2017 -0700 +++ b/piecrust/pipelines/_pagerecords.py Wed Oct 04 20:40:43 2017 -0700 @@ -45,6 +45,7 @@ FLAG_SOURCE_MODIFIED = 2**1 FLAG_OVERRIDEN = 2**2 FLAG_COLLAPSED_FROM_LAST_RUN = 2**3 + FLAG_IS_DRAFT = 2**4 def __init__(self): super().__init__() @@ -122,7 +123,8 @@ PagePipelineRecordEntry.FLAG_NEW: 'new', PagePipelineRecordEntry.FLAG_SOURCE_MODIFIED: 'touched', PagePipelineRecordEntry.FLAG_OVERRIDEN: 'overriden', - PagePipelineRecordEntry.FLAG_COLLAPSED_FROM_LAST_RUN: 'from last run'} + PagePipelineRecordEntry.FLAG_COLLAPSED_FROM_LAST_RUN: 'from last run', + PagePipelineRecordEntry.FLAG_IS_DRAFT: 'draft'} sub_flag_descriptions = {
--- a/piecrust/pipelines/page.py Wed Oct 04 09:15:16 2017 -0700 +++ b/piecrust/pipelines/page.py Wed Oct 04 20:40:43 2017 -0700 @@ -16,6 +16,7 @@ super().__init__(source, ppctx) self._pagebaker = None self._stats = source.app.env.stats + self._draft_setting = self.app.config['baker/no_bake_setting'] def initialize(self): stats = self.app.env.stats @@ -114,7 +115,11 @@ record_entry = result.record_entry record_entry.config = page.config.getAll() record_entry.timestamp = page.datetime.timestamp() - result.next_step_job = self.createJob(content_item) + + if not page.config.get(self._draft_setting): + result.next_step_job = self.createJob(content_item) + else: + record_entry.flags |= PagePipelineRecordEntry.FLAG_IS_DRAFT def _renderOrPostpone(self, content_item, ctx, result): # Here our job is to render the page's segments so that they're