MoinLight

Annotated moinformat/serialisers/__init__.py

143:a20caaa18295
2018-08-06 Paul Boddie Add the pagename as an attribute on serialiser instances.
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@96 22
from moinformat.links import make_linker
paul@104 23
from moinformat.output import make_output
paul@40 24
from moinformat.serialisers.manifest import serialisers
paul@85 25
from moinformat.serialisers.moin.moin import MoinSerialiser
paul@100 26
from os.path import curdir
paul@38 27
paul@38 28
# Top-level functions.
paul@38 29
paul@96 30
def get_serialiser(name):
paul@96 31
paul@96 32
    "Return the main serialiser class for the format having the given 'name'."
paul@96 33
paul@96 34
    return serialisers["%s.moin" % name]
paul@96 35
paul@143 36
def make_serialiser(name, output=None, linker=None, pagename=None):
paul@96 37
paul@96 38
    """
paul@96 39
    Return a serialiser instance for the format having the given 'name'.
paul@96 40
paul@100 41
    The optional 'output' context is used to control where separate resources
paul@104 42
    are stored, with the default being no storage of such resources.
paul@100 43
paul@96 44
    The optional 'linker' is used to control which linking scheme is used with
paul@96 45
    the serialiser, with the default having the same name as the serialiser.
paul@143 46
paul@143 47
    The optional 'pagename' indicates the name details of the page to be
paul@143 48
    serialised.
paul@96 49
    """
paul@96 50
paul@104 51
    output = output or make_output("standalone")
paul@96 52
    linker = linker or make_linker(name, "")
paul@143 53
    return get_serialiser(name)(output, serialisers, linker, pagename)
paul@96 54
paul@94 55
def serialise(doc, serialiser=None):
paul@46 56
paul@94 57
    """
paul@94 58
    Serialise 'doc' using the given 'serialiser' instance or the Moin serialiser
paul@94 59
    if omitted.
paul@94 60
    """
paul@46 61
paul@100 62
    if not serialiser:
paul@104 63
        output = make_output("standalone")
paul@100 64
        serialiser = MoinSerialiser(output, serialisers)
paul@100 65
paul@94 66
    doc.to_string(serialiser)
paul@100 67
    return serialiser.get_output()
paul@38 68
paul@38 69
# vim: tabstop=4 expandtab shiftwidth=4