# Path: django_fortunes/templatetags/fortune_extras.py
# @register.filter
# @stringfilter
# def fortunize(value):
#     """
#     Transforms a fortune plain text into htmlized (but safe) one.
#     """
#     r = ""
#     for i, line in enumerate(value.splitlines()):
#         m = re.findall(r"^<(\w+)>\s?(.*)$", line.strip())
#         className = "odd" if i % 2 == 0 else "even"
#         if (len(m) > 0):
#             for match in m:
#                 nick = match[0]
#                 quote = escape(match[1])
#                 r += "<dt class=\"%s\">&lt;%s&gt;</dt><dd><q>%s</q></dd>\n" % (className, nick, quote)
#         else:
#             r += "<dt>&nbsp;</dt><dd>%s</dd>\n" % (escape(line))
#     return "<dl>%s</dl>" % r
# 
# @register.inclusion_tag('partials/topcontributors.html')
# def top_contributors():
#     """
#     Displays the list of MAX_TOP_CONTRIBUTORS top contributors
#     """
#     max = getattr(settings, 'FORTUNES_MAX_TOP_CONTRIBUTORS', 5)
#     return {'authors': Fortune.objects.top_authors()[:max]}


import unittest
from django.test.testcases import TestCase
from django_fortunes.templatetags.fortune_extras import fortunize, top_contributors


class FortuneExtraTest(TestCase):
    def test_fortunize(self):
        self.assertEquals(fortunize(u'<niko> foo'), u'<dl><dt class="odd">&lt;niko&gt;</dt><dd><q>foo</q></dd>\n</dl>')

# Path: django_fortunes/templatetags/fortune_extras.py
# @register.filter
# @stringfilter
# def fortunize(value):
#     """
#     Transforms a fortune plain text into htmlized (but safe) one.
#     """
#     r = ""
#     for i, line in enumerate(value.splitlines()):
#         m = re.findall(r"^<(\w+)>\s?(.*)$", line.strip())
#         className = "odd" if i % 2 == 0 else "even"
#         if (len(m) > 0):
#             for match in m:
#                 nick = match[0]
#                 quote = escape(match[1])
#                 r += "<dt class=\"%s\">&lt;%s&gt;</dt><dd><q>%s</q></dd>\n" % (className, nick, quote)
#         else:
#             r += "<dt>&nbsp;</dt><dd>%s</dd>\n" % (escape(line))
#     return "<dl>%s</dl>" % r
# 
# @register.inclusion_tag('partials/topcontributors.html')
# def top_contributors():
#     """
#     Displays the list of MAX_TOP_CONTRIBUTORS top contributors
#     """
#     max = getattr(settings, 'FORTUNES_MAX_TOP_CONTRIBUTORS', 5)
#     return {'authors': Fortune.objects.top_authors()[:max]}


# Path: django_fortunes/tests/templatetags.py
import unittest
from django.test.testcases import TestCase
from django_fortunes.templatetags.fortune_extras import fortunize, top_contributors



class FortuneExtraTest(TestCase):
    def test_fortunize(self):
        self.assertEquals(fortunize(u'<niko> foo'), u'<dl><dt class="odd">&lt;niko&gt;</dt><dd><q>foo</q></dd>\n</dl>')

        self.assertEquals(fortunize(u'<niko> foo\n<david> bar'), u'<dl><dt class="odd">&lt;niko&gt;</dt><dd><q>foo</q></dd>\n<dt class="even">&lt;david&gt;</dt><dd><q>bar</q></dd>\n</dl>')