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
def Chicago(people): return plural(people, one = join ('') [ people ], two = join (' and ') [ people ], more = join (', ', last = ', and ') [ people ])
# This formats a list of authors according to the Chicago manual of # style. def Chicago(people): return plural(people, one = join ('') [ people ], two = join (' and ') [ people ], more = join (', ', last = ', and ') [ people ]) # Definitions of the "Plain" (and derived) citation format. plain_author = Chicago(firstLast(all('author'))) plain_journal = join(', ')[ I[one('journal')], join('')[join(':')[one('volume'), one('number')], '(' + one('pages') + ')'], year(one('date')) ] plain_place = switch('doctype') plain_place = plain_place.case(article=plain_journal) plain_place = plain_place.default(year(one('date'))) plain = join('. ')[plain_author, one('title'), plain_place] + '.' # The "full" format also provides an abstract. full = join('\n')[Span(size='large', weight='bold')[one('title')], Span(size='large')[plain_author], Span(size='large')[plain_place], Span(color='#505050')[one('abstract')]]
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')