import os from xml.dom.minidom import parse globalHeaderMain = "" globalHeaderMain += "\n" globalHeaderMain += "\t\n" globalHeaderMain += "\t\tPolycode Documentation\n" globalHeaderMain += "\t\t\n" globalHeaderMain += "\t\t" globalHeaderMain += "\t\n" globalHeaderMain += "\t\n" globalHeaderMain += "\t\t
\n" globalHeaderMain += "\t\t
\n" globalHeader = "" globalFooter = "" globalHeader += "\n" globalHeader += "\t\n" globalHeader += "\t\tPolycode Documentation\n" globalHeader += "\t\t\n" globalHeader += "\t\t" globalHeader += "\t\n" globalHeader += "\t\n" globalHeader += "\t\t
\n" globalHeader += "\t\t
\n" globalFooter += "\t\t
\n" globalFooter += "\t\n" globalFooter += "\t\n" def createMethods(className, item, static): html = "" html += "\t\t\t\t\t
\n" if static == True: html += "\t\t\t\t\t\t
Static Functions
\n" else: html += "\t\t\t\t\t\t
Functions
\n" html += "\t\t\t\t\t\t
\n" for subitem in item.getElementsByTagName('method'): if static == True and subitem.hasAttribute("static") == False: continue if static == False and subitem.hasAttribute("static") == True: continue html += "\t\t\t\t\t\t\t
\n" paramList = "" paramIndex = 0 if len(subitem.getElementsByTagName('param')) > 0: for param in subitem.getElementsByTagName('param'): if paramIndex != 0: paramList += ", " paramList += " %s %s " % (param.attributes["type"].value, param.attributes["name"].value) paramIndex = paramIndex + 1 if static == True: html += "\t\t\t\t\t\t\t\t
%s.%s (%s)
\n" % (className, subitem.attributes["name"].value, paramList) else: html += "\t\t\t\t\t\t\t\t
%s (%s)
\n" % (subitem.attributes["name"].value, paramList) html += "\t\t\t\t\t\t\t\t
%s
\n" % (subitem.attributes["return_type"].value) desc = subitem.getElementsByTagName('desc') descText = "No description." if len(desc) > 0: descText = desc[0].childNodes[0].data html += "\t\t\t\t\t\t\t\t
%s
\n" % (descText) if len(subitem.getElementsByTagName('param')) > 0: html += "\t\t\t\t\t\t\t\t
\n" html += "\t\t\t\t\t\t\t\t
Parameters
\n" for param in subitem.getElementsByTagName('param'): html += "\t\t\t\t\t\t\t\t
\n" html += "\t\t\t\t\t\t\t\t\t
%s
\n" % (param.attributes["name"].value) html += "\t\t\t\t\t\t\t\t\t
%s
\n" % (param.attributes["type"].value) desc = param.getElementsByTagName('desc') descText = "No description." if len(desc) > 0: if len(desc[0].childNodes) > 0: descText = desc[0].childNodes[0].data html += "\t\t\t\t\t\t\t\t\t
%s
\n" % (descText) html += "\t\t\t\t\t\t\t\t
\n" html += "\t\t\t\t\t\t\t\t
\n" html += "\t\t\t\t\t\t\t
\n" html += "\t\t\t\t\t\t
\n" html += "\t\t\t\t\t
\n" return html def makePage(item, classList, classListPlain, moduleName): html = globalHeader html += classList html += "\t\t\t\t
\n" if item.hasAttribute("extends"): extendModulePrefix = moduleName if item.attributes["extends"].value not in classListPlain: extendModulePrefix = "Polycode" html += "\t\t\t\t\t
%s extends %s
\n" % (item.attributes["name"].value, extendModulePrefix, item.attributes["extends"].value, item.attributes["extends"].value) else: html += "\t\t\t\t\t
%s
\n" % (item.attributes["name"].value) desc = item.getElementsByTagName('desc') descText = "No description." if len(desc) > 0: descText = desc[0].childNodes[0].data html += "\t\t\t\t\t
%s
\n" % descText html += "\t\t\t\t\t
\n" html += "\t\t\t\t\t\t
Static Properties
\n" html += "\t\t\t\t\t\t
\n" for subitem in item.getElementsByTagName('static_member'): html += "\t\t\t\t\t\t\t
\n" html += "\t\t\t\t\t\t\t\t
%s.%s = %s
\n" % (item.attributes["name"].value, subitem.attributes["name"].value, subitem.attributes["value"].value) html += "\t\t\t\t\t\t\t\t
%s
\n" % (subitem.attributes["type"].value) desc = subitem.getElementsByTagName('desc') descText = "No description." if len(desc) > 0: descText = desc[0].childNodes[0].data html += "\t\t\t\t\t\t\t\t
%s
\n" % (descText) html += "\t\t\t\t\t\t\t
\n" html += "\t\t\t\t\t\t
\n" html += "\t\t\t\t\t
\n" html += "\t\t\t\t\t
\n" html += "\t\t\t\t\t\t
Properties
\n" html += "\t\t\t\t\t\t
\n" for subitem in item.getElementsByTagName('member'): html += "\t\t\t\t\t\t\t
\n" html += "\t\t\t\t\t\t\t\t
%s
\n" % (subitem.attributes["name"].value) html += "\t\t\t\t\t\t\t\t
%s
\n" % (subitem.attributes["type"].value) desc = subitem.getElementsByTagName('desc') descText = "No description." if len(desc) > 0: descText = desc[0].childNodes[0].data html += "\t\t\t\t\t\t\t\t
%s
\n" % (descText) html += "\t\t\t\t\t\t\t
\n" html += "\t\t\t\t\t\t
\n" html += "\t\t\t\t\t
\n" html += createMethods(item.attributes["name"].value, item, True) html += createMethods(item.attributes["name"].value, item, False) html += "\t\t\t\t
\n" return html def makeHTML(fileName, moduleName): print ("Parsing %s\n" % fileName) sourceXML = open(fileName) dom = parse(sourceXML) sourceXML.close() classList = "" classList += "\t\t\t
\n" classListPlain = [] for item in dom.documentElement.getElementsByTagName('class'): classList += "\t\t\t\t\n" % (item.attributes["name"].value, item.attributes["name"].value) classListPlain.append(item.attributes["name"].value) classList += "\t\t\t
\n" classList += "\n" directory = "../html/%s" % (moduleName) if not os.path.exists(directory): os.makedirs(directory) html = globalHeader html += classList html += globalFooter f = open("../html/%s/index.html" % (moduleName), 'w') f.write(html) f.close() for item in dom.documentElement.getElementsByTagName('class'): f = open("../html/%s/%s.html" % (moduleName, item.attributes["name"].value), 'w') html = makePage(item, classList, classListPlain, moduleName) f.write(html) f.close() dirList = os.listdir("../xml") indexhtml = globalHeaderMain indexhtml += "\t
\n" for fname in dirList: if len(fname.split(".")) > 1: if fname.split(".")[1] == "xml": moduleName = fname.split(".")[0] makeHTML("../xml/%s" % (fname), moduleName) indexhtml += "\t\t\t\n" % (moduleName, moduleName) indexhtml += "\t
\n" f = open("../html/index.html", 'w') f.write(indexhtml) f.close() indexhtml += globalFooter