paul@309 | 1 | # -*- coding: iso-8859-1 -*- |
paul@309 | 2 | """ |
paul@309 | 3 | MoinMoin - event (EventAggregator) |
paul@309 | 4 | |
paul@434 | 5 | @copyright: 2012, 2013, 2014 by Paul Boddie <paul@boddie.org.uk> |
paul@309 | 6 | @license: GNU GPL (v2 or later), see COPYING.txt for details. |
paul@309 | 7 | """ |
paul@309 | 8 | |
paul@366 | 9 | from MoinSupport import parseAttributes |
paul@366 | 10 | from EventAggregatorSupport.Formatting import formatEvent, formatEventsForOutputType |
paul@395 | 11 | from EventAggregatorSupport.Types import parseEventsInPage, EventPage |
paul@309 | 12 | |
paul@309 | 13 | Dependencies = ["pages"] |
paul@309 | 14 | |
paul@309 | 15 | # Parser support. |
paul@309 | 16 | |
paul@309 | 17 | class Parser: |
paul@309 | 18 | |
paul@434 | 19 | """ |
paul@434 | 20 | Interpret and show event information expressed as wiki text in different |
paul@434 | 21 | ways. |
paul@434 | 22 | """ |
paul@309 | 23 | |
paul@309 | 24 | Dependencies = Dependencies |
paul@309 | 25 | extensions = [] |
paul@309 | 26 | |
paul@309 | 27 | # Output content types preferred by this parser. |
paul@309 | 28 | |
paul@309 | 29 | output_mimetypes = ["text/html", "text/calendar"] |
paul@309 | 30 | |
paul@309 | 31 | def __init__(self, raw, request, **kw): |
paul@309 | 32 | |
paul@309 | 33 | """ |
paul@309 | 34 | Initialise the parser with the given 'raw' data, 'request' and any |
paul@309 | 35 | keyword arguments that may have been supplied. |
paul@309 | 36 | """ |
paul@309 | 37 | |
paul@309 | 38 | self.raw = raw |
paul@309 | 39 | self.request = request |
paul@323 | 40 | attrs = parseAttributes(kw.get("format_args", ""), False) |
paul@323 | 41 | |
paul@323 | 42 | self.fragment = attrs.get("fragment") |
paul@309 | 43 | |
paul@310 | 44 | def format(self, fmt, write=None): |
paul@309 | 45 | |
paul@310 | 46 | """ |
paul@310 | 47 | Format an event using the given formatter 'fmt'. If the 'write' |
paul@310 | 48 | parameter is specified, use it to write output; otherwise, write output |
paul@310 | 49 | using the request. |
paul@310 | 50 | """ |
paul@309 | 51 | |
paul@428 | 52 | for event in parseEventsInPage(self.raw, EventPage(self.request.page), self.fragment).getEvents(): |
paul@310 | 53 | formatEvent(event, self.request, fmt, write=write) |
paul@309 | 54 | |
paul@309 | 55 | # Extra API methods. |
paul@309 | 56 | |
paul@310 | 57 | def formatForOutputType(self, mimetype, write=None): |
paul@309 | 58 | |
paul@310 | 59 | """ |
paul@310 | 60 | Format an event for the given 'mimetype'. If the 'write' parameter is |
paul@310 | 61 | specified, use it to write output; otherwise, write output using the |
paul@310 | 62 | request. |
paul@310 | 63 | """ |
paul@309 | 64 | |
paul@428 | 65 | events = parseEventsInPage(self.raw, EventPage(self.request.page), self.fragment).getEvents() |
paul@310 | 66 | formatEventsForOutputType(events, self.request, mimetype, write=write) |
paul@309 | 67 | |
paul@309 | 68 | # Class methods. |
paul@309 | 69 | |
paul@309 | 70 | def getOutputTypes(self): |
paul@309 | 71 | return self.output_mimetypes |
paul@309 | 72 | |
paul@309 | 73 | getOutputTypes = classmethod(getOutputTypes) |
paul@309 | 74 | |
paul@309 | 75 | # vim: tabstop=4 expandtab shiftwidth=4 |