make_html.py 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. import os
  2. from xml.dom.minidom import parse
  3. globalHeaderMain = ""
  4. globalHeaderMain += "<html>\n"
  5. globalHeaderMain += "\t<head>\n"
  6. globalHeaderMain += "\t\t<title>Polycode Documentation</title>\n"
  7. globalHeaderMain += "\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"css/docs.css\" />\n"
  8. globalHeaderMain += "\t\t<link href='http://fonts.googleapis.com/css?family=Roboto:400,300' rel='stylesheet' type='text/css'>\n"
  9. globalHeaderMain += "\t\t<script type=\"text/javascript\" src=\"js/docs.js\"></script>"
  10. globalHeaderMain += "\t</head>\n"
  11. globalHeaderMain += "\t<body>\n"
  12. globalHeaderMain += "\t\t<div id=\"global_header\"><a href=\"index.html\"><img border=\"0\" src=\"images/docs_header.png\"/></a></div>\n"
  13. globalHeaderMain += "\t\t<div id=\"content\">\n"
  14. globalHeader = ""
  15. globalFooter = ""
  16. globalHeader += "<html>\n"
  17. globalHeader += "\t<head>\n"
  18. globalHeader += "\t\t<title>Polycode Documentation</title>\n"
  19. globalHeader += "\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"../css/docs.css\" />\n"
  20. globalHeader += "\t\t<script type=\"text/javascript\" src=\"js/docs.js\"></script>"
  21. globalHeader += "\t</head>\n"
  22. globalHeader += "\t<body>\n"
  23. globalHeader += "\t\t<div id=\"global_header\"><a href=\"../index.html\"><img border=\"0\" src=\"../images/docs_header.png\"/></a></div>\n"
  24. globalHeader += "\t\t<div id=\"content\">\n"
  25. globalFooter += "\t\t</div>\n"
  26. globalFooter += "\t</body>\n"
  27. globalFooter += "\t</html>\n"
  28. def createMethods(className, item, static):
  29. numStatic = 0
  30. numRegular = 0
  31. for subitem in item.getElementsByTagName('method'):
  32. if subitem.hasAttribute("static") == True:
  33. numStatic = numStatic + 1
  34. else:
  35. numRegular = numRegular + 1
  36. if static == True and numStatic == 0:
  37. return ""
  38. if static == False and numRegular == 0:
  39. return ""
  40. html = ""
  41. html += "\t\t\t\t\t<div class=\"class_methods\">\n"
  42. if static == True:
  43. html += "\t\t\t\t\t\t<div class=\"class_methods_title\">Static Functions</div>\n"
  44. else:
  45. html += "\t\t\t\t\t\t<div class=\"class_methods_title\">Functions</div>\n"
  46. html += "\t\t\t\t\t\t<div class=\"class_methods_list\">\n"
  47. for subitem in item.getElementsByTagName('method'):
  48. if static == True and subitem.hasAttribute("static") == False:
  49. continue
  50. if static == False and subitem.hasAttribute("static") == True:
  51. continue
  52. html += "\t\t\t\t\t\t\t<div class=\"class_method\">\n"
  53. paramList = ""
  54. paramIndex = 0
  55. if len(subitem.getElementsByTagName('param')) > 0:
  56. for param in subitem.getElementsByTagName('param'):
  57. if paramIndex != 0:
  58. paramList += ", "
  59. paramList += " <span class=\"inline_type\">%s</span> <span class=\"inline_param\">%s</span> " % (param.attributes["type"].value, param.attributes["name"].value)
  60. paramIndex = paramIndex + 1
  61. if static == True:
  62. html += "\t\t\t\t\t\t\t\t<div class=\"class_method_name\">%s.%s (%s) </div>\n" % (className, subitem.attributes["name"].value, paramList)
  63. else:
  64. html += "\t\t\t\t\t\t\t\t<div class=\"class_method_name\">%s (%s) </div>\n" % (subitem.attributes["name"].value, paramList)
  65. html += "\t\t\t\t\t\t\t\t<div class=\"class_method_type\">%s</div>\n" % (subitem.attributes["return_type"].value)
  66. desc = subitem.getElementsByTagName('desc')
  67. descText = "No description."
  68. if len(desc) > 0:
  69. descText = desc[0].childNodes[0].data
  70. html += "\t\t\t\t\t\t\t\t<div class=\"class_method_desc\">%s</div>\n" % (descText)
  71. if len(subitem.getElementsByTagName('param')) > 0:
  72. html += "\t\t\t\t\t\t\t\t<div class=\"class_method_params\">\n"
  73. html += "\t\t\t\t\t\t\t\t<div class=\"class_method_params_title\">Parameters</div>\n"
  74. for param in subitem.getElementsByTagName('param'):
  75. html += "\t\t\t\t\t\t\t\t<div class=\"class_method_param\">\n"
  76. html += "\t\t\t\t\t\t\t\t\t<div class=\"class_method_param_name\">%s</div>\n" % (param.attributes["name"].value)
  77. html += "\t\t\t\t\t\t\t\t\t<div class=\"class_method_param_type\">%s</div>\n" % (param.attributes["type"].value)
  78. desc = param.getElementsByTagName('desc')
  79. descText = "No description."
  80. if len(desc) > 0:
  81. if len(desc[0].childNodes) > 0:
  82. descText = desc[0].childNodes[0].data
  83. html += "\t\t\t\t\t\t\t\t\t<div class=\"class_method_param_desc\">%s</div>\n" % (descText)
  84. html += "\t\t\t\t\t\t\t\t</div>\n"
  85. html += "\t\t\t\t\t\t\t\t</div>\n"
  86. html += "\t\t\t\t\t\t\t</div>\n"
  87. html += "\t\t\t\t\t\t</div>\n"
  88. html += "\t\t\t\t\t</div>\n"
  89. return html
  90. def makePage(item, classList, classListPlain, moduleName):
  91. html = globalHeader
  92. html += classList
  93. html += "\t\t\t\t<div class=\"class_main\">\n"
  94. if item.hasAttribute("extends"):
  95. extendModulePrefix = moduleName
  96. if item.attributes["extends"].value not in classListPlain:
  97. extendModulePrefix = "Polycode"
  98. html += "\t\t\t\t\t<div class=\"class_name\">%s <span class=\"class_extends\">extends</span> <span class=\"class_extends_class\"><a href=\"../%s/%s.html\">%s</a></span></div>\n" % (item.attributes["name"].value, extendModulePrefix, item.attributes["extends"].value, item.attributes["extends"].value)
  99. else:
  100. html += "\t\t\t\t\t<div class=\"class_name\">%s</div>\n" % (item.attributes["name"].value)
  101. desc = item.getElementsByTagName('desc')
  102. descText = "No description."
  103. if len(desc) > 0:
  104. descText = desc[0].childNodes[0].data
  105. html += "\t\t\t\t\t<div class=\"class_desc\">%s</div>\n" % descText
  106. if len(item.getElementsByTagName('static_member')) > 0:
  107. html += "\t\t\t\t\t<div class=\"class_properties\">\n"
  108. html += "\t\t\t\t\t\t<div class=\"class_properties_title\">Static Properties</div>\n"
  109. html += "\t\t\t\t\t\t<div class=\"class_properties_list\">\n"
  110. for subitem in item.getElementsByTagName('static_member'):
  111. html += "\t\t\t\t\t\t\t<div class=\"class_property\">\n"
  112. html += "\t\t\t\t\t\t\t\t<div class=\"class_property_name\">%s.%s <span class=\"static_value\">= %s</span></div>\n" % (item.attributes["name"].value, subitem.attributes["name"].value, subitem.attributes["value"].value)
  113. html += "\t\t\t\t\t\t\t\t<div class=\"class_property_type\">%s</div>\n" % (subitem.attributes["type"].value)
  114. desc = subitem.getElementsByTagName('desc')
  115. descText = "No description."
  116. if len(desc) > 0:
  117. descText = desc[0].childNodes[0].data
  118. html += "\t\t\t\t\t\t\t\t<div class=\"class_property_desc\">%s</div>\n" % (descText)
  119. html += "\t\t\t\t\t\t\t</div>\n"
  120. html += "\t\t\t\t\t\t</div>\n"
  121. html += "\t\t\t\t\t</div>\n"
  122. if len(item.getElementsByTagName('member')) > 0:
  123. html += "\t\t\t\t\t<div class=\"class_properties\">\n"
  124. html += "\t\t\t\t\t\t<div class=\"class_properties_title\">Properties</div>\n"
  125. html += "\t\t\t\t\t\t<div class=\"class_properties_list\">\n"
  126. for subitem in item.getElementsByTagName('member'):
  127. html += "\t\t\t\t\t\t\t<div class=\"class_property\">\n"
  128. html += "\t\t\t\t\t\t\t\t<div class=\"class_property_name\">%s</div>\n" % (subitem.attributes["name"].value)
  129. html += "\t\t\t\t\t\t\t\t<div class=\"class_property_type\">%s</div>\n" % (subitem.attributes["type"].value)
  130. desc = subitem.getElementsByTagName('desc')
  131. descText = "No description."
  132. if len(desc) > 0:
  133. descText = desc[0].childNodes[0].data
  134. html += "\t\t\t\t\t\t\t\t<div class=\"class_property_desc\">%s</div>\n" % (descText)
  135. html += "\t\t\t\t\t\t\t</div>\n"
  136. html += "\t\t\t\t\t\t</div>\n"
  137. html += "\t\t\t\t\t</div>\n"
  138. html += createMethods(item.attributes["name"].value, item, True)
  139. html += createMethods(item.attributes["name"].value, item, False)
  140. html += "\t\t\t\t</div>\n"
  141. return html
  142. def makeHTML(fileName, moduleName):
  143. print ("Parsing %s\n" % fileName)
  144. sourceXML = open(fileName)
  145. dom = parse(sourceXML)
  146. sourceXML.close()
  147. classList = ""
  148. classList += "\t\t\t<div id=\"class_list\">\n"
  149. classListPlain = []
  150. for item in dom.documentElement.getElementsByTagName('class'):
  151. classList += "\t\t\t\t<div class=\"class_entry\"><a href=\"%s.html\">%s</a></div>\n" % (item.attributes["name"].value, item.attributes["name"].value)
  152. classListPlain.append(item.attributes["name"].value)
  153. classList += "\t\t\t</div>\n"
  154. classList += "\n"
  155. directory = "../html/%s" % (moduleName)
  156. if not os.path.exists(directory):
  157. os.makedirs(directory)
  158. html = globalHeader
  159. html += classList
  160. html += globalFooter
  161. f = open("../html/%s/index.html" % (moduleName), 'w')
  162. f.write(html)
  163. f.close()
  164. for item in dom.documentElement.getElementsByTagName('class'):
  165. f = open("../html/%s/%s.html" % (moduleName, item.attributes["name"].value), 'w')
  166. html = makePage(item, classList, classListPlain, moduleName)
  167. f.write(html)
  168. f.close()
  169. dirList = os.listdir("../xml")
  170. indexhtml = globalHeaderMain
  171. indexhtml += "\t<div id=\"module_links\">\n"
  172. for fname in dirList:
  173. if len(fname.split(".")) > 1:
  174. if fname.split(".")[1] == "xml":
  175. moduleName = fname.split(".")[0]
  176. makeHTML("../xml/%s" % (fname), moduleName)
  177. indexhtml += "\t\t\t<div class=\"module_link\"><a href=\"%s/index.html\">%s</a></div>\n" % (moduleName, moduleName)
  178. indexhtml += "\t</div>\n"
  179. f = open("../html/index.html", 'w')
  180. f.write(indexhtml)
  181. f.close()
  182. indexhtml += globalFooter