Example #1
0
    def testJoin(self):
        """ The join function takes lists of items and joins them """

        v = join(", ")[Person.lastFirst(all("author"))]
        self._cmp(v, u"Gobry, Frédéric, Fobry, Grédéric, Dobry, Lrédéric")

        v = join(", ")["a", "b", "c"]
        self._cmp(v, u"a, b, c")

        v = join(", ", last="; ")["a", "b", "c"]
        self._cmp(v, u"a, b; c")

        v = join(", ")["a", "b", "c"] + " ok"
        self._cmp(v, u"a, b, c ok")

        # join skip missing values
        v = join(", ")[one("title"), one("journal"), one("gronf")]
        self._cmp(v, u"My title")

        # join fails when _no_ value is available
        v = join(", ")[one("gronf"), one("regronf")]
        phase2 = v(self.db)
        try:
            phase2(self.rec)
            assert False
        except DSL.Missing:
            pass

        # Join with a weird tag in the middle.
        v = "a " + join(BR)["toto", "tutu"] + " b"

        self._cmp(v, u"a toto<br>tutu b")
        return
Example #2
0
    def testInitials(self):

        self.failUnlessEqual(Person.initials(u"Frédéric"), "F.")
        self.failUnlessEqual(Person.initials(u"Jean-Pierre"), "J.-P.")
        self.failUnlessEqual(Person.initials(u"Jean Pierre"), "J.P.")
        self.failUnlessEqual(Person.initials(u"J.Pierre"), "J.P.")
        self.failUnlessEqual(Person.initials(u"JP"), "J.P.")
        self.failUnlessEqual(Person.initials(u"J"), "J.")
        self.failUnlessEqual(Person.initials(u"J."), "J.")
Example #3
0
Registry.load_default_settings()

# This will output the database in BibTeX format
w = Writer()


# Define a simple citation format
from Pyblio.Format import one, all, join, switch, I, B, A
from Pyblio.Format import Person, Date
from Pyblio.Format.HTML import generate

title = B[one('title') | u'(no title)']

title = A(href=one('url'))[title] | title

authors = join(', ', last=' and ')[Person.initialLast(all('author'))]

article = join(u', ')[
    I[one('journal')],
    
    u'vol. ' + one('volume'),
    u'nr. '  + one('number'),
    u'pp. '  + one('pages'),
    
    Date.year(one('date'))
    ]

default = Date.year(one('date'))

place = switch('doctype')