Permalink
Browse files

Added a titlecase filter

Requires Stuart Colville's titlecase.py to be installed
http://muffinresearch.co.uk/archives/2008/05/27/titlecasepy-titlecase-in-python/

Thanks to  Myles.Braithwaite for the patch

git-svn-id: https://typogrify.googlecode.com/svn/trunk@15 a37c9311-d62f-0410-a16a-c50513983d21
  • Loading branch information...
1 parent 0bac8fb commit d8fb7607b8551875c4fa12aac30cee1b50dc606c mintxian committed Aug 29, 2008
Showing with 20 additions and 0 deletions.
  1. +20 −0 typogrify/templatetags/typogrify.py
@@ -181,6 +181,25 @@ def smartypants(text):
return mark_safe(output)
smartypants.is_safe = True
+def titlecase(text):
+ """Support for titlecase.py's titlecasing
+
+ >>> titlecase("this V that")
+ u'This v That'
+
+ >>> titlecase("this is just an example.com")
+ u'This Is Just an example.com'
+ """
+ text = force_unicode(text)
+ try:
+ import titlecase
+ except ImportError:
+ if settings.DEBUG:
+ raise template.TemplateSyntaxError, "Error in {% titlecase %} filter: The titlecase.py library isn't installed."
+ return text
+ else:
+ return titlecase.titlecase(text)
+
def typogrify(text):
"""The super typography filter
@@ -257,6 +276,7 @@ def widont(text):
register.filter('caps', caps)
register.filter('initial_quotes', initial_quotes)
register.filter('smartypants', smartypants)
+register.filter('titlecase', titlecase)
register.filter('typogrify', typogrify)
register.filter('widont', widont)

0 comments on commit d8fb760

Please sign in to comment.