Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.x Support #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions anora/templatetags/anora.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import re

from django import template
from django.conf import settings
from django.utils.encoding import force_unicode
from django.template.defaultfilters import stringfilter

register = template.Library()

CONSONANT_SOUND = re.compile(r'''one(![ir])''', re.IGNORECASE|re.VERBOSE)
VOWEL_SOUND = re.compile(r'''[aeio]|u([aeiou]|[^n][^aeiou]|ni[^dmnl]|nil[^l])|h(ier|onest|onou?r|ors\b|our(!i))|[fhlmnrsx]\b''', re.IGNORECASE|re.VERBOSE)
CONSONANT_SOUND = re.compile(r'''one(![ir])''', re.IGNORECASE | re.VERBOSE)
VOWEL_SOUND = re.compile(r'''[aeio]|u([aeiou]|[^n][^aeiou]|ni[^dmnl]|nil[^l])|h(ier|onest|onou?r|ors\b|our(!i))|[fhlmnrsx]\b''', re.IGNORECASE | re.VERBOSE)


@register.filter
def anora(text):
text = force_unicode(text)
anora = 'an' if not CONSONANT_SOUND.match(text) and VOWEL_SOUND.match(text) else 'a'
return anora + ' ' + text
anora = 'an' if not CONSONANT_SOUND.match(text) and VOWEL_SOUND.match(text) else 'a'
return anora + ' ' + text
5 changes: 3 additions & 2 deletions anora/tests.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from django.utils import unittest
from anora.templatetags.anora import anora

class AnoraTestCase(unittest.TestCase):

class AnoraTestCase(unittest.TestCase):

def test_anora(self):
awords = ['rabbit', 'mole', 'fox']
anwords = ['owl', 'ox', 'octopus']

for an_a, word_list in (('a', awords), ('an', anwords)):
for word in word_list:
self.assertEqual(' '.join((an_a, word)), anora(word))
self.assertEqual(' '.join((an_a, word)), anora(word))