1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 """
22 Citation formatting layer.
23
24 Rationale: the difficult part in formatting the records is not how the
25 records are actually laid out on a page, the keys,... but rather the
26 actual layout of the authors, the publication information,...
27 especially given that all the records are not complete.
28
29 So, this module is only intended to handle I{this specific aspect},
30 not to compose a whole page.
31
32 The code here allows the writing of citation styles with a convenient
33 syntax:
34
35 >>> authors = lastFirst(all('author'))
36
37 >>> location = join(', ')['vol. ' + one ('volume'),
38 ... 'num. ' + one ('number'), ]
39
40 >>> citation = join(', ')[ authors , I[one('title') | 'untitled'] ]
41
42
43 Citing a reference is a multi-stage operation:
44
45 - B{stage 1:} the citation is written by the programmer in a
46 convenient Domain Specific Language (DSL)
47
48 >>> citation = join(', ')['vol. ' + one('volume'),
49 ... 'num. ' + one('number')]
50
51 - B{stage 2:} the formatter of stage 1 is 'compiled' on a specific
52 database (which allows for some initial checks (existence of the
53 requested fields and txo for instance)
54
55 >>> formatter = citation(db)
56
57 - B{stage 3:} the compiled formatter can accept records, and return an
58 abstract representation of the citation, with style indications
59
60 >>> cited = formatter(record)
61
62 - B{stage 4:} the abstract representation is turned into a concrete
63 representations (plain text, HTML,...)
64
65 >>> html = HTML.generate(cited)
66
67
68 The ideas for the syntax have been heavily borrowed from nevow's stan.
69
70 """
71
72
73 from Pyblio.Format.DSL import join, one, all, switch, i18n, record_key
74 from Pyblio.Format.DSL import A, B, I, BR, Small, Span
75 from Pyblio.Format.DSL import Missing, lazy
76