|
| 1 | +from pybtex.style.formatting import toplevel |
| 2 | +from pybtex.style.formatting.plain import Style |
| 3 | +from pybtex.style.names.lastfirst import NameStyle as LastFirst |
| 4 | +from pybtex.style.sorting.none import SortingStyle as NoSort |
| 5 | +from pybtex.style.template import field, href, join, optional, \ |
| 6 | + optional_field, sentence, tag, words |
| 7 | + |
| 8 | +date = words[field('year'), optional_field('month')] |
| 9 | + |
| 10 | + |
| 11 | +class CPAC_DocsStyle(Style): |
| 12 | + def __init__(self, *args, **kwargs): |
| 13 | + super().__init__( |
| 14 | + abbreviate_names=True, |
| 15 | + name_style=LastFirst, |
| 16 | + sorting_style=NoSort |
| 17 | + ) |
| 18 | + |
| 19 | + def get_book_template(self, entry): |
| 20 | + template = toplevel[optional[ |
| 21 | + sentence[self.format_names('author')]], |
| 22 | + optional[sentence[date]], |
| 23 | + optional[sentence[href[ |
| 24 | + field('url'), |
| 25 | + optional[tag('em')[self.format_title(entry, 'title')]] |
| 26 | + ]]] if entry.fields.get('url') else optional[sentence[ |
| 27 | + tag('em')[self.format_title(entry, 'title')] |
| 28 | + ]], |
| 29 | + optional[sentence[ |
| 30 | + join(sep=': ')[ |
| 31 | + optional_field('address'), |
| 32 | + optional_field('publisher') |
| 33 | + ], |
| 34 | + ]], |
| 35 | + sentence[optional_field('note')], |
| 36 | + ] |
| 37 | + return template |
| 38 | + |
| 39 | + def get_misc_template(self, entry): |
| 40 | + template = toplevel[ |
| 41 | + optional[sentence[self.format_names('author')]], |
| 42 | + optional[sentence[ |
| 43 | + optional[field('howpublished')], |
| 44 | + optional[date], |
| 45 | + ]], |
| 46 | + optional[sentence[join(sep=', ')[href[ |
| 47 | + optional_field('url'), |
| 48 | + optional[self.format_title(entry, 'title', as_sentence=False)]] |
| 49 | + if entry.fields.get('url') else optional[ |
| 50 | + self.format_title(entry, 'title') |
| 51 | + ], |
| 52 | + optional[tag('em')[self.format_title(entry, 'journal')]], |
| 53 | + ]]], |
| 54 | + sentence[optional_field('note')], |
| 55 | + ] |
| 56 | + return template |
0 commit comments