Back to index

moin  1.9.0~rc2
TeudView.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - Teud Macro
00004 
00005     This integrates the "Teud" documentation system into
00006     MoinMoin. Besides Teud, you need 4XSLT.
00007 
00008     Teud: http://purl.net/wiki/python/TeudProject
00009     4XSLT: http://4suite.org/
00010 
00011     @copyright: 2001 Juergen Hermann <jh@web.de>
00012     @license: GNU GPL, see COPYING for details.
00013 """
00014 
00015 _imperr = None
00016 try:
00017     from teud import xmldoc, pydoc
00018 except ImportError, _imperr:
00019     pass
00020 try:
00021     from xml.xslt.Processor import Processor
00022 except ImportError, _imperr:
00023     pass
00024 
00025 from MoinMoin import config, wikiutil
00026 
00027 Dependencies = ["time"]
00028 
00029 def macro_TeudView(macro):
00030     if _imperr: return "Error in TeudView macro: " + str(_imperr)
00031 
00032     #dtdfile = xmldoc.getDTDPath()
00033     xslfile = xmldoc.getDataPath('webde.xsl')
00034     pagename = macro.formatter.page.page_name
00035 
00036     if 'module' in macro.request.args:
00037         modname = macro.request.args["module"]
00038         try:
00039             obj = pydoc.locate(modname)
00040         except pydoc.ErrorDuringImport, value:
00041             return "Error while loading module %s: %s" % (modname, value)
00042         else:
00043             xmlstr = xmldoc.xml.document(obj, encoding=config.charset)
00044 
00045         navigation = '<a href="%s">Index</a>' % pagename
00046         pathlen = modname.count('.')
00047         if pathlen:
00048             navigation = navigation + ' | '
00049             modparts = modname.split('.')
00050             for pathidx in range(pathlen):
00051                 path = '.'.join(modparts[:pathidx+1])
00052                 navigation = navigation + '<a href="%s?module=%s">%s</a>' % (
00053                     pagename, path, modparts[pathidx])
00054                 if pathidx < pathlen:
00055                     navigation = navigation + '.'
00056         navigation = navigation + '<hr size="1">'
00057     else:
00058         # generate index
00059         xmlstr = xmldoc.xml.document(None, encoding=config.charset)
00060         navigation = ''
00061 
00062     processor = Processor()
00063     processor.appendStylesheetFile(xslfile)
00064     try:
00065         result = processor.runString(xmlstr,
00066             topLevelParams={
00067                 'uri-prefix': pagename + "?module=",
00068                 'uri-suffix': "",
00069             }
00070         )
00071     except:
00072         print wikiutil.escape(xmlstr)
00073         raise
00074 
00075     return navigation + result
00076