Package Pyblio :: Package Format
[hide private]
[frames] | no frames]

Source Code for Package Pyblio.Format

 1  # This file is part of pybliographer 
 2  #  
 3  # Copyright (C) 1998-2006 Frederic GOBRY 
 4  # Email : gobry@pybliographer.org 
 5  #           
 6  # This program is free software; you can redistribute it and/or 
 7  # modify it under the terms of the GNU General Public License 
 8  # as published by the Free Software Foundation; either version 2  
 9  # of the License, or (at your option) any later version. 
10  #    
11  # This program is distributed in the hope that it will be useful, 
12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
14  # GNU General Public License for more details.  
15  #  
16  # You should have received a copy of the GNU General Public License 
17  # along with this program; if not, write to the Free Software 
18  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
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