Permalink
Browse files

Do not create feeds when their filenames are set to None.

  • Loading branch information...
draftcode committed Mar 10, 2012
1 parent a7ea166 commit 1194764ed1ddcce797fb1895668ccc5e97137c93
Showing with 63 additions and 20 deletions.
  1. +3 −1 docs/settings.rst
  2. +24 −19 pelican/generators.py
  3. +36 −0 tests/test_generators.py
View
@@ -199,7 +199,6 @@ Pelican generates category feeds as well as feeds for all your articles. It does
not generate feeds for tags by default, but it is possible to do so using
the ``TAG_FEED`` and ``TAG_FEED_RSS`` settings:
-
================================================ =====================================================
Setting name (default value) What does it do?
================================================ =====================================================
@@ -214,6 +213,9 @@ Setting name (default value) What does it do?
quantity is unrestricted by default.
================================================ =====================================================
+If you don't want to generate some of these feeds, set ``None`` to the
+variables above.
+
.. [2] %s is the name of the category.
Pagination
View
@@ -118,41 +118,46 @@ def __init__(self, *args, **kwargs):
def generate_feeds(self, writer):
"""Generate the feeds from the current context, and output files."""
- writer.write_feed(self.articles, self.context, self.settings['FEED'])
+ if self.settings.get('FEED'):
+ writer.write_feed(self.articles, self.context,
+ self.settings['FEED'])
- if 'FEED_RSS' in self.settings:
+ if self.settings.get('FEED_RSS'):
writer.write_feed(self.articles, self.context,
- self.settings['FEED_RSS'], feed_type='rss')
+ self.settings['FEED_RSS'], feed_type='rss')
for cat, arts in self.categories:
arts.sort(key=attrgetter('date'), reverse=True)
- writer.write_feed(arts, self.context,
- self.settings['CATEGORY_FEED'] % cat)
+ if self.settings.get('CATEGORY_FEED'):
+ writer.write_feed(arts, self.context,
+ self.settings['CATEGORY_FEED'] % cat)
- if 'CATEGORY_FEED_RSS' in self.settings:
+ if self.settings.get('CATEGORY_FEED_RSS'):
writer.write_feed(arts, self.context,
- self.settings['CATEGORY_FEED_RSS'] % cat,
- feed_type='rss')
+ self.settings['CATEGORY_FEED_RSS'] % cat,
+ feed_type='rss')
- if 'TAG_FEED' in self.settings:
+ if self.settings.get('TAG_FEED') or self.settings.get('TAG_FEED_RSS'):
for tag, arts in self.tags.items():
arts.sort(key=attrgetter('date'), reverse=True)
- writer.write_feed(arts, self.context,
- self.settings['TAG_FEED'] % tag)
+ if self.settings.get('TAG_FEED'):
+ writer.write_feed(arts, self.context,
+ self.settings['TAG_FEED'] % tag)
- if 'TAG_FEED_RSS' in self.settings:
+ if self.settings.get('TAG_FEED_RSS'):
writer.write_feed(arts, self.context,
self.settings['TAG_FEED_RSS'] % tag,
feed_type='rss')
- translations_feeds = defaultdict(list)
- for article in chain(self.articles, self.translations):
- translations_feeds[article.lang].append(article)
+ if self.settings.get('TRANSLATION_FEED'):
+ translations_feeds = defaultdict(list)
+ for article in chain(self.articles, self.translations):
+ translations_feeds[article.lang].append(article)
- for lang, items in translations_feeds.items():
- items.sort(key=attrgetter('date'), reverse=True)
- writer.write_feed(items, self.context,
- self.settings['TRANSLATION_FEED'] % lang)
+ for lang, items in translations_feeds.items():
+ items.sort(key=attrgetter('date'), reverse=True)
+ writer.write_feed(items, self.context,
+ self.settings['TRANSLATION_FEED'] % lang)
def generate_pages(self, writer):
"""Generate the pages on the disk"""
View
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+from __future__ import with_statement
+try:
+ from unittest2 import TestCase
+except ImportError, e:
+ from unittest import TestCase
+
+from pelican.generators import ArticlesGenerator
+from pelican.settings import _DEFAULT_CONFIG
+
+class TestArticlesGenerator(TestCase):
+
+ def test_generate_feeds(self):
+
+ class FakeWriter(object):
+ def __init__(self):
+ self.called = False
+
+ def write_feed(self, *args, **kwargs):
+ self.called = True
+
+ generator = ArticlesGenerator(None, {'FEED': _DEFAULT_CONFIG['FEED']},
+ None, _DEFAULT_CONFIG['THEME'], None,
+ None)
+ writer = FakeWriter()
+ generator.generate_feeds(writer)
+ assert writer.called, ("The feed should be written, "
+ "if settings['FEED'] is specified.")
+
+ generator = ArticlesGenerator(None, {'FEED': None}, None,
+ _DEFAULT_CONFIG['THEME'], None, None)
+ writer = FakeWriter()
+ generator.generate_feeds(writer)
+ assert not writer.called, ("If settings['FEED'] is None, "
+ "the feed should not be generated.")
+

0 comments on commit 1194764

Please sign in to comment.