MoinLight

Annotated moinformat/serialisers/__init__.py

176:47af441b48bf
2018-11-26 Paul Boddie Support linking to stylesheets based on the collection of available files.
paul@38 1
#!/usr/bin/env python
paul@38 2
paul@38 3
"""
paul@38 4
Moin wiki serialisers.
paul@38 5
paul@46 6
Copyright (C) 2017, 2018 Paul Boddie <paul@boddie.org.uk>
paul@38 7
paul@38 8
This program is free software; you can redistribute it and/or modify it under
paul@38 9
the terms of the GNU General Public License as published by the Free Software
paul@38 10
Foundation; either version 3 of the License, or (at your option) any later
paul@38 11
version.
paul@38 12
paul@38 13
This program is distributed in the hope that it will be useful, but WITHOUT
paul@38 14
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
paul@38 15
FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
paul@38 16
details.
paul@38 17
paul@38 18
You should have received a copy of the GNU General Public License along with
paul@38 19
this program.  If not, see <http://www.gnu.org/licenses/>.
paul@38 20
"""
paul@38 21
paul@40 22
from moinformat.serialisers.manifest import serialisers
paul@38 23
paul@38 24
# Top-level functions.
paul@38 25
paul@96 26
def get_serialiser(name):
paul@96 27
paul@96 28
    "Return the main serialiser class for the format having the given 'name'."
paul@96 29
paul@96 30
    return serialisers["%s.moin" % name]
paul@96 31
paul@165 32
def make_serialiser(metadata, format=None):
paul@96 33
paul@96 34
    """
paul@165 35
    Return a serialiser instance using the given 'metadata' and optional
paul@165 36
    'format'.
paul@96 37
    """
paul@96 38
paul@165 39
    return metadata.get_serialiser(format)
paul@96 40
paul@165 41
def serialise(doc, serialiser):
paul@46 42
paul@165 43
    "Serialise 'doc' using the given 'serialiser' instance."
paul@46 44
paul@165 45
    serialiser.reset()
paul@94 46
    doc.to_string(serialiser)
paul@100 47
    return serialiser.get_output()
paul@38 48
paul@38 49
# vim: tabstop=4 expandtab shiftwidth=4