From 108b67282ad41416bef48125249ff293efaa8469 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Tue, 16 Jun 2015 22:33:39 +0100 Subject: [PATCH] Export hidden pages in context The `PageGenerator` was building hidden pages, but was not making them available in the context. This makes it difficult for other plugins to operate on hidden pages. This patch updates `PageGenerator` to export the hidden pages it finds in the context as `hidden_pages`. It also updates the article generator to export `drafts`. --- docs/themes.rst | 2 ++ pelican/generators.py | 4 ++-- pelican/tests/test_generators.py | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/themes.rst b/docs/themes.rst index d64683bb..6ca753c6 100644 --- a/docs/themes.rst +++ b/docs/themes.rst @@ -77,11 +77,13 @@ articles The list of articles, ordered descending by date. in the `all_articles` variable. dates The same list of articles, but ordered by date, ascending. +drafts The list of draft articles tags A list of (tag, articles) tuples, containing all the tags. categories A list of (category, articles) tuples, containing all the categories and corresponding articles (values) pages The list of pages +hidden_pages The list of hidden pages ============= =================================================== diff --git a/pelican/generators.py b/pelican/generators.py index a29555a5..0a5298e4 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -577,7 +577,7 @@ class ArticlesGenerator(CachingGenerator): self.authors.sort() self._update_context(('articles', 'dates', 'tags', 'categories', - 'authors', 'related_posts')) + 'authors', 'related_posts', 'drafts')) self.save_cache() self.readers.save_cache() signals.article_generator_finalized.send(self) @@ -643,7 +643,7 @@ class PagesGenerator(CachingGenerator): self.hidden_pages, self.hidden_translations = ( process_translations(hidden_pages)) - self._update_context(('pages', )) + self._update_context(('pages', 'hidden_pages')) self.context['PAGES'] = self.pages self.save_cache() diff --git a/pelican/tests/test_generators.py b/pelican/tests/test_generators.py index e93c8c14..c424b60f 100644 --- a/pelican/tests/test_generators.py +++ b/pelican/tests/test_generators.py @@ -491,7 +491,13 @@ class TestPageGenerator(unittest.TestCase): ] self.assertEqual(sorted(pages_expected), sorted(pages)) + self.assertEqual( + sorted(pages_expected), + sorted(self.distill_pages(generator.context['pages']))) self.assertEqual(sorted(hidden_pages_expected), sorted(hidden_pages)) + self.assertEqual( + sorted(hidden_pages_expected), + sorted(self.distill_pages(generator.context['hidden_pages']))) def test_generate_sorted(self): settings = get_settings(filenames={})