Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
refactor filter to body_to_div, change test accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
retrorabbitWD committed Aug 18, 2014
1 parent 5d15238 commit 8e72ed9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
18 changes: 9 additions & 9 deletions oneplus/templatetags/oneplus_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,8 @@ def align(value):

if soup.body:
body = get_content(soup)
remove_bodytags(body)
output = soup.new_tag("div")
list = body.contents[:]
for content in list:
output.append(content)
output['style'] = \
'vertical-align:middle;display:inline-block;width:80%'
return body_to_div(body, soup)

return u'%s' % output

register.filter('align', align)

Expand All @@ -55,6 +48,13 @@ def get_content(value):
return value.body.extract()


def remove_bodytags(body):
def body_to_div(body, soup):
remove_tags(str(body), "body")
output = soup.new_tag("div")
list = body.contents[:]
for content in list:
output.append(content)
output['style'] = \
'vertical-align:middle;display:inline-block;width:80%'

return u'%s' % output
4 changes: 1 addition & 3 deletions oneplus/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,5 @@ def test_filters_empty(self):
content = ""
result = align(content)
output = strip_tags(result)
self.assertEquals(output, u'<div style="vertical-align:middle;'
u'display:inline-block;width:80%">'
u'</div>')
self.assertEquals(output, u'<div></div>')

0 comments on commit 8e72ed9

Please sign in to comment.