Package Pyblio :: Package Cite :: Package Style :: Module BibTeX
[hide private]
[frames] | no frames]

Source Code for Module Pyblio.Cite.Style.BibTeX

 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  from Pyblio.Format import join, one, all, I, switch, BR, B, Span 
21  from Pyblio.Format.Misc import plural 
22  from Pyblio.Format.Date import year 
23  from Pyblio.Format.Person import firstLast 
24   
25  from Pyblio.Cite.Style.Base import Alpha 
26       
27 -class AlphaKey(Alpha):
28 """ Generate keys based on authors and year. """ 29
30 - def _generate(self, uid):
31 rec = self.db[uid] 32 if not ('date' in rec or 'author' in rec): 33 return 'Unknown' 34 35 k = [] 36 if 'author' in rec: 37 au = rec['author'] 38 if len(au) == 1: 39 k.append(au[0].last[:3]) 40 else: 41 k.append(''.join([a.last[0] for a in au[:3]])) 42 43 if 'date' in rec: 44 k.append(str(rec['date'][0].year)[-2:]) 45 46 return ''.join(k)
47 48 # This formats a list of authors according to the Chicago manual of 49 # style.
50 -def Chicago(people):
51 return plural(people, 52 one = join ('') [ people ], 53 two = join (' and ') [ people ], 54 more = join (', ', last = ', and ') [ people ])
55 56 57 # Definitions of the "Plain" (and derived) citation format. 58 plain_author = Chicago(firstLast(all('author'))) 59 60 plain_journal = join(', ')[ 61 I[one('journal')], 62 join('')[join(':')[one('volume'), one('number')], 63 '(' + one('pages') + ')'], 64 year(one('date')) 65 ] 66 67 plain_place = switch('doctype') 68 plain_place = plain_place.case(article=plain_journal) 69 plain_place = plain_place.default(year(one('date'))) 70 71 plain = join('. ')[plain_author, one('title'), plain_place] + '.' 72 73 # The "full" format also provides an abstract. 74 full = join('\n')[Span(size='large', weight='bold')[one('title')], 75 Span(size='large')[plain_author], 76 Span(size='large')[plain_place], 77 Span(color='#505050')[one('abstract')]] 78