Skip to content

Commit

Permalink
Blog post titles are consistently smartified.
Browse files Browse the repository at this point in the history
Fixes #68
  • Loading branch information
mblayman committed Jan 26, 2017
1 parent f81f736 commit b32303d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
6 changes: 2 additions & 4 deletions handroll/extensions/blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, **kwargs):
self.date = kwargs['date']
self.source_file = kwargs['source_file']
self.summary = kwargs['summary']
self.title = kwargs['title']
self.title = smartypants.smartypants(kwargs['title'])
self.route = kwargs['route']
self.url = kwargs['url']

Expand Down Expand Up @@ -212,11 +212,9 @@ def add(self, posts):
"""Add the posts and generate a blog list."""
li_html = []
for post in posts:
# Put the smartified title back into the post.
post.title = title = smartypants.smartypants(post.title)
li_html.append(
u'<li><a href="{route}">{title}</a></li>'.format(
route=post.route, title=title))
route=post.route, title=post.title))
self._blog_list = u'\n'.join(li_html)
self._posts = posts

Expand Down
7 changes: 4 additions & 3 deletions handroll/tests/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
class Factory(object):
"""A factory to produce commonly needed objects"""

def make_blog_post(self):
kwargs = {
def make_blog_post(self, **kwargs):
parameters = {
'date': datetime.datetime.today(),
'source_file': 'a_source_file.md',
'summary': 'The post summary',
'title': 'A Blog Post',
'route': '/a_source_file.html',
'url': 'http://www.example.com/a_source_file.html',
}
return BlogPost(**kwargs)
parameters.update(kwargs)
return BlogPost(**parameters)

def make_configuration(self):
config = Configuration()
Expand Down
3 changes: 1 addition & 2 deletions handroll/tests/test_blog_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,7 @@ def test_adds_posts_to_blog_list_html(self):
builder._blog_list)

def test_smartypants_conversion_on_title(self):
post = self.factory.make_blog_post()
post.title = 'Emdash -- Post'
post = self.factory.make_blog_post(title='Emdash -- Post')
builder = ListPageBuilder(None)
builder.add([post])
self.assertEqual(
Expand Down

0 comments on commit b32303d

Please sign in to comment.