paul@0 | 1 | # -*- coding: iso-8859-1 -*- |
paul@0 | 2 | """ |
paul@0 | 3 | MoinMoin - table (ImprovedTableParser) |
paul@0 | 4 | |
paul@0 | 5 | @copyright: 2012 by Paul Boddie <paul@boddie.org.uk> |
paul@0 | 6 | @license: GNU GPL (v2 or later), see COPYING.txt for details. |
paul@0 | 7 | """ |
paul@0 | 8 | |
paul@0 | 9 | from ImprovedTableParser import * |
paul@0 | 10 | |
paul@0 | 11 | Dependencies = ["pages"] |
paul@0 | 12 | |
paul@0 | 13 | # Parser support. |
paul@0 | 14 | |
paul@0 | 15 | class Parser: |
paul@0 | 16 | |
paul@0 | 17 | "Support a more flexible table syntax." |
paul@0 | 18 | |
paul@0 | 19 | Dependencies = Dependencies |
paul@0 | 20 | extensions = [] |
paul@0 | 21 | |
paul@35 | 22 | # Output content types preferred by this parser. |
paul@35 | 23 | |
paul@35 | 24 | output_mimetypes = ["text/html"] |
paul@35 | 25 | |
paul@0 | 26 | def __init__(self, raw, request, **kw): |
paul@0 | 27 | |
paul@0 | 28 | """ |
paul@0 | 29 | Initialise the parser with the given 'raw' data, 'request' and any |
paul@0 | 30 | keyword arguments that may have been supplied. |
paul@0 | 31 | """ |
paul@0 | 32 | |
paul@0 | 33 | self.raw = raw |
paul@0 | 34 | self.request = request |
paul@0 | 35 | self.attrs = parseAttributes(kw.get("format_args", ""), False) |
paul@0 | 36 | |
paul@35 | 37 | def format(self, fmt, write=None): |
paul@35 | 38 | |
paul@35 | 39 | """ |
paul@35 | 40 | Format a table using the given formatter 'fmt'. If the 'write' parameter |
paul@35 | 41 | is specified, use it to write output; otherwise, write output using the |
paul@35 | 42 | request. |
paul@35 | 43 | """ |
paul@35 | 44 | |
paul@35 | 45 | formatTable(self.raw, self.request, fmt, self.attrs, write=write) |
paul@35 | 46 | |
paul@35 | 47 | # Extra API methods. |
paul@35 | 48 | |
paul@35 | 49 | def formatForOutputType(self, mimetype, write=None): |
paul@0 | 50 | |
paul@35 | 51 | """ |
paul@35 | 52 | Format a table for the given 'mimetype'. If the 'write' parameter is |
paul@35 | 53 | specified, use it to write output; otherwise, write output using the |
paul@35 | 54 | request. |
paul@35 | 55 | """ |
paul@0 | 56 | |
paul@35 | 57 | formatTableForOutputType(self.raw, self.request, mimetype, self.attrs, write=write) |
paul@35 | 58 | |
paul@35 | 59 | # Class methods. |
paul@35 | 60 | |
paul@35 | 61 | def getOutputTypes(self): |
paul@35 | 62 | return self.output_mimetypes |
paul@35 | 63 | |
paul@35 | 64 | getOutputTypes = classmethod(getOutputTypes) |
paul@0 | 65 | |
paul@0 | 66 | # vim: tabstop=4 expandtab shiftwidth=4 |