Documentation for the Tree output formatter project

Data formats

This project introduces a new data format for internal usage. Also it changes the way some other data formats are used internaly.

Internal format

MIME-type: application/x-moin-document

A high-level, semantic data format for representing all kinds of data. For compatibility and performance reasons it includes HTML. Native output is XML. It is used in form of a ET tree internal.

HTML

MIME-types: application/xhtml+xml application/x-xhtml-moin-page

HTML as defined by the W3. Native output is XML. It is used in form of a ET tree internal.

Converters

Converters are used to convert data from one type to another. They define the conversion based on MIME types with optional arguments.

Interface

Converters are implemented as modules in MoinMoin.converter2. They are loaded during startup and have to register a factory for themself to the converter registry. The factory have to return a type object.

   1 class Converter(object):
   2     @classmethod
   3     def factory(cls, _request, type_input, type_output):
   4         if (type_input == 'text/plain' and
   5                 type_output == 'application/x-moin-document'):
   6             return cls
   7 
   8 from MoinMoin.converter2._registry import default_registry
   9 default_registry.register(Converter.factory)

For the real work they are first instantiated with the request and then called with the current content and optionally the page IRI and the arguments. The content can be depending on the type either a sequence (iterator) over unicode strings or an ET-node.

   1 class Converter(object):
   2     def __init__(self, request):
   3         """
   4         @param request: The current request
   5         """
   6 
   7     def __call__(self, content, arguments=None):
   8         """
   9         @param content: The input to be converted.
  10         @type content: ElementTree-Node or iteratable over unicode
  11         @param arguments: The wrapped arguments for the converter.
  12         @return The converted content
  13         @rtype ElementTree-Node or iteratable over unicode
  14         """

Macros

Macros are still handled seperate in the MoinMoin.macro2 package (or via an compatiblity layer in MoinMoin.macro).

Base interface

   1 class Macro(object):
   2     def __init__(self, request):
   3         """
   4         @param request: The current request
   5         """
   6 
   7     def __call__(self, content, arguments=None, page_url=None, alt=None, context_block=False):
   8         """
   9         @param content: The input to be converted. Currently empty.
  10         @param arguments: The wrapped arguments for the converter.
  11         @param page_url: The URL/IRI of the page the content is part of, can be empty.
  12         @param alt: Alternative text (TODO, do we need this?)
  13         @param context_block: If this macro is called in block context.
  14         @type context_block: bool
  15         @rtype ElementTree-Node
  16         """

Context-sensitive interface

There are three base classes that handles context dependend macros.

MacroBlockBase handles macros which only have a meaningfull output in block context.

   1 class Macro(MacroXXXBase):
   2     def macro(self, content, page_url=None, arguments=None, alt=None):
   3         """
   4         @param content: The input to be converted. Currently empty.
   5         @param page_url: The URL/IRI of the page the content is part of, can be empty.
   6         @param arguments: The wrapped arguments for the converter.
   7         @param alt: Alternative text (TODO, do we need this?)
   8         @param context_block: If this macro is called in block context.
   9         @type context_block: bool
  10         @rtype ElementTree-Node
  11         """

MoinMoin: BastianBlank/TreeOutputFormatter/Documentation (last edited 2009-07-08 20:44:28 by BastianBlank)