# HG changeset patch # User Paul Boddie # Date 1533563111 -7200 # Node ID a20caaa18295b842392f6d02a7984deca86db9dd # Parent 699a2d4c84ca0fa7795c088fcbd85103e54085c0 Add the pagename as an attribute on serialiser instances. diff -r 699a2d4c84ca -r a20caaa18295 moinformat/serialisers/__init__.py --- a/moinformat/serialisers/__init__.py Mon Aug 06 15:44:10 2018 +0200 +++ b/moinformat/serialisers/__init__.py Mon Aug 06 15:45:11 2018 +0200 @@ -33,7 +33,7 @@ return serialisers["%s.moin" % name] -def make_serialiser(name, output=None, linker=None): +def make_serialiser(name, output=None, linker=None, pagename=None): """ Return a serialiser instance for the format having the given 'name'. @@ -43,11 +43,14 @@ The optional 'linker' is used to control which linking scheme is used with the serialiser, with the default having the same name as the serialiser. + + The optional 'pagename' indicates the name details of the page to be + serialised. """ output = output or make_output("standalone") linker = linker or make_linker(name, "") - return get_serialiser(name)(output, serialisers, linker) + return get_serialiser(name)(output, serialisers, linker, pagename) def serialise(doc, serialiser=None): diff -r 699a2d4c84ca -r a20caaa18295 moinformat/serialisers/common.py --- a/moinformat/serialisers/common.py Mon Aug 06 15:44:10 2018 +0200 +++ b/moinformat/serialisers/common.py Mon Aug 06 15:45:11 2018 +0200 @@ -25,17 +25,18 @@ format = None # defined by subclasses - def __init__(self, output, formats=None, linker=None): + def __init__(self, output, formats=None, linker=None, pagename=None): """ Initialise the serialiser with an 'output' context, an optional - 'formats' mapping from names to serialiser classes, and an optional - 'linker' object for translating links. + 'formats' mapping from names to serialiser classes, an optional 'linker' + object for translating links, and an optional 'pagename'. """ self.output = output self.formats = formats self.linker = linker + self.pagename = pagename # Initialise a callable for use in serialisation. @@ -52,8 +53,8 @@ pass def __repr__(self): - return "%s(%r, %r, %r)" % (self.__class__.__name__, self.output, - self.formats, self.linker) + return "%s(%r, %r, %r, %r)" % (self.__class__.__name__, self.output, + self.formats, self.linker, self.pagename) def get_serialiser(self, format): @@ -84,7 +85,7 @@ if cls is self.__class__: return self else: - return cls(self.output, self.formats, self.linker) + return cls(self.output, self.formats, self.linker, self.pagename) def escape_attr(s):