Skip to content

Commit

Permalink
Add HTML listing configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
mblayman committed Jul 6, 2015
1 parent 73b7280 commit 0e3ca2f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
10 changes: 10 additions & 0 deletions handroll/extensions/blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,26 @@ def __init__(self, config):
self.posts = {}
self.atom_metadata = {}
self.atom_output = ''
self.list_template = None
self.list_output = None
self._resolver = None

def on_pre_composition(self, director):
"""Check that all the required configuration exists."""
if not self._config.parser.has_section('blog'):
raise AbortError(
_('A blog section is missing in the configuration file.'))

# Collect atom feed configuration.
for metadata, option in self.required_metadata.items():
self._add_atom_metadata(metadata, option)
self.atom_output = self._get_option('atom_output')

# Collect HTML listing configuration.
if self._config.parser.has_option('blog', 'list_template'):
self.list_template = self._get_option('list_template')
self.list_output = self._get_option('list_output')

# Grab the resolver from the director for determining URLs for posts.
self._resolver = director.resolver

Expand Down
33 changes: 33 additions & 0 deletions handroll/tests/test_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def _add_blog_section(self, parser, exclude=None):
'atom_output': 'feed.xml',
'atom_title': 'Amazing blog',
'atom_url': 'https://www.example.com/archive.html',
'list_template': 'archive.j2',
'list_output': 'archive.html',
}
for option, value in configuration.items():
if option == exclude:
Expand Down Expand Up @@ -307,6 +309,37 @@ def test_posts_added_to_builder_by_date(self, builder_add):
self.assertEqual(older, builder_add.call_args_list[1][0][0])
self.assertEqual(current, builder_add.call_args_list[2][0][0])

def test_list_template_not_required(self):
director = self.factory.make_director()
self._add_blog_section(director.config.parser, exclude='list_template')
extension = BlogExtension(director.config)
extension.on_pre_composition(director)
self.assertIsNone(extension.list_template)

def test_has_list_template_in_extension(self):
director = self.factory.make_director()
self._add_blog_section(director.config.parser)
extension = BlogExtension(director.config)
extension.on_pre_composition(director)
self.assertEqual('archive.j2', extension.list_template)

def test_has_list_output_in_extension(self):
director = self.factory.make_director()
self._add_blog_section(director.config.parser)
extension = BlogExtension(director.config)
extension.on_pre_composition(director)
self.assertEqual('archive.html', extension.list_output)

def test_list_output_required_with_list_template(self):
director = self.factory.make_director()
self._add_blog_section(director.config.parser, exclude='list_output')
extension = BlogExtension(director.config)
try:
extension.on_pre_composition(director)
self.fail()
except AbortError as ae:
self.assertTrue('list_output' in str(ae))


class TestFeedBuilder(TestCase):

Expand Down
4 changes: 4 additions & 0 deletions handroll/tests/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ class TestCase(unittest.TestCase):
def __init__(self, methodName='runTest'):
super(TestCase, self).__init__(methodName)
self.factory = Factory()

def assertIsNone(self, x):
"""Backport for Python 2.6."""
self.assertTrue(x is None)

0 comments on commit 0e3ca2f

Please sign in to comment.