コード例 #1
0
ファイル: ut_format.py プロジェクト: zkota/pyblio-core-1.3
    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
コード例 #2
0
ファイル: BibTeX.py プロジェクト: zkota/pyblio-core-1.3
def Chicago(people):
    return plural(people,
                  one  = join ('') [ people ],
                  two  = join (' and ') [ people ],
                  more = join (', ', last = ', and ') [ people ])
コード例 #3
0
ファイル: BibTeX.py プロジェクト: zkota/pyblio-core-1.3
# 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')]]
コード例 #4
0
ファイル: pubmed.py プロジェクト: zkota/pyblio-core-1.3
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')