2
0

make_html.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. import os
  2. import sys
  3. from xml.dom.minidom import parse
  4. siteDocs = False
  5. if len(sys.argv) > 1:
  6. if sys.argv[1] == "site":
  7. siteDocs = True
  8. globalHeaderMain = ""
  9. if siteDocs == True:
  10. header_f = open("site_header.html", 'r')
  11. globalHeaderMain = header_f.read()
  12. globalHeader = globalHeaderMain
  13. footer_f = open("site_footer.html", 'r')
  14. globalFooter = footer_f.read()
  15. else:
  16. header_f = open("local_header.html", 'r')
  17. globalHeaderMain = header_f.read()
  18. globalHeader = globalHeaderMain
  19. footer_f = open("local_footer.html", 'r')
  20. globalFooter = footer_f.read()
  21. def createMethods(className, item, static):
  22. numStatic = 0
  23. numRegular = 0
  24. for subitem in item.getElementsByTagName('method'):
  25. if subitem.hasAttribute("static") == True:
  26. numStatic = numStatic + 1
  27. else:
  28. numRegular = numRegular + 1
  29. if static == True and numStatic == 0:
  30. return ""
  31. if static == False and numRegular == 0:
  32. return ""
  33. html = ""
  34. html += "\t\t\t\t\t<div class=\"class_methods\">\n"
  35. if static == True:
  36. html += "\t\t\t\t\t\t<h3 class=\"class_methods_title\">Static Functions</h3>\n"
  37. else:
  38. html += "\t\t\t\t\t\t<h3 class=\"class_methods_title\">Functions</h3>\n"
  39. html += "\t\t\t\t\t\t<div class=\"well\">\n"
  40. for subitem in item.getElementsByTagName('method'):
  41. if static == True and subitem.hasAttribute("static") == False:
  42. continue
  43. if static == False and subitem.hasAttribute("static") == True:
  44. continue
  45. paramList = ""
  46. paramIndex = 0
  47. if len(subitem.getElementsByTagName('param')) > 0:
  48. for param in subitem.getElementsByTagName('param'):
  49. if paramIndex != 0:
  50. paramList += ", "
  51. paramList += "<span class=\"inline_param\">%s</span> " % (param.attributes["name"].value)
  52. paramIndex = paramIndex + 1
  53. if static == True:
  54. html += "\t\t\t\t\t\t\t\t<h4 style=\"margin-top: 40px\"><span class=\"badge\">%s</span> %s.%s (%s)</h4>\n" % (subitem.attributes["return_type"].value, className, subitem.attributes["name"].value, paramList)
  55. else:
  56. html += "\t\t\t\t\t\t\t\t<h4 style=\"margin-top: 40px\"><span class=\"badge\">%s</span> %s (%s)</h4>\n" % (subitem.attributes["return_type"].value, subitem.attributes["name"].value, paramList)
  57. desc = subitem.getElementsByTagName('desc')
  58. descText = "No description."
  59. if len(desc) > 0:
  60. descText = desc[0].childNodes[0].data
  61. html += "\t\t\t\t\t\t\t\t<p>%s</p>\n" % (descText)
  62. if len(subitem.getElementsByTagName('param')) > 0:
  63. for param in subitem.getElementsByTagName('param'):
  64. desc = param.getElementsByTagName('desc')
  65. descText = "No description."
  66. if len(desc) > 0:
  67. if len(desc[0].childNodes) > 0:
  68. descText = desc[0].childNodes[0].data
  69. html += "\t\t\t\t\t\t\t\t\t<p><span class=\"badge\">%s</span> %s - %s</p>\n" % ( param.attributes["type"].value, param.attributes["name"].value, descText)
  70. html += "\t\t\t\t\t\t</div>\n"
  71. html += "\t\t\t\t\t</div>\n"
  72. return html
  73. def makePage(item, classList, classListPlain, moduleName):
  74. html = globalHeader
  75. html += classList
  76. html += "\t<div class=\"col-md-9\">"
  77. if item.hasAttribute("extends"):
  78. extendModulePrefix = moduleName
  79. if item.attributes["extends"].value not in classListPlain:
  80. extendModulePrefix = "Polycode"
  81. html += "\t\t\t\t\t<h1>%s <span class=\"class_extends\"> (extends</span> <span class=\"class_extends_class\"><a href=\"../%s/%s.html\">%s</a>)</span></h1>\n" % (item.attributes["name"].value, extendModulePrefix, item.attributes["extends"].value, item.attributes["extends"].value)
  82. else:
  83. html += "\t\t\t\t\t<h1 class=\"class_name\">%s</h1>\n" % (item.attributes["name"].value)
  84. desc = item.getElementsByTagName('desc')
  85. descText = "No description."
  86. if len(desc) > 0:
  87. descText = desc[0].childNodes[0].data
  88. html += "\t\t\t\t\t<p class=\"lead\">%s</p>\n" % descText
  89. classNotes = item.getElementsByTagName('class_notes')
  90. for nn in classNotes:
  91. html += "\t\t\t\t\t<div class=\"class_desc\">%s</div>\n" % nn.childNodes[0].data
  92. if len(item.getElementsByTagName('static_member')) > 0:
  93. html += "\t\t\t\t\t<div class=\"class_properties\">\n"
  94. html += "\t\t\t\t\t\t<h3 style=\"\">Static Properties</h3>\n"
  95. html += "\t\t\t\t\t\t<div class=\"well\">\n"
  96. for subitem in item.getElementsByTagName('static_member'):
  97. html += "\t\t\t\t\t\t\t\t<h5 style=\"margin-top: 25px\">%s.%s = %s</h5>\n" % (item.attributes["name"].value, subitem.attributes["name"].value, subitem.attributes["value"].value)
  98. desc = subitem.getElementsByTagName('desc')
  99. descText = "No description."
  100. if len(desc) > 0:
  101. descText = desc[0].childNodes[0].data
  102. html += "\t\t\t\t\t\t\t\t<p><span class=\"badge\">%s</span> %s</p>\n" % (subitem.attributes["type"].value, descText)
  103. html += "\t\t\t\t\t\t</div>\n"
  104. html += "\t\t\t\t\t</div>\n"
  105. if len(item.getElementsByTagName('member')) > 0:
  106. html += "\t\t\t\t\t<div class=\"class_properties\">\n"
  107. html += "\t\t\t\t\t\t<h3>Properties</h3>\n"
  108. html += "\t\t\t\t\t\t<div class=\"well\">\n"
  109. for subitem in item.getElementsByTagName('member'):
  110. html += "\t\t\t\t\t\t\t\t<h5 style=\"margin-top: 25px\">%s</h5>\n" % (subitem.attributes["name"].value)
  111. desc = subitem.getElementsByTagName('desc')
  112. descText = "No description."
  113. if len(desc) > 0:
  114. descText = desc[0].childNodes[0].data
  115. html += "\t\t\t\t\t\t\t\t<p><span class=\"badge\">%s</span> %s</p>\n" % (subitem.attributes["type"].value, descText)
  116. html += "\t\t\t\t\t\t</div>\n"
  117. html += "\t\t\t\t\t</div>\n"
  118. html += createMethods(item.attributes["name"].value, item, True)
  119. html += createMethods(item.attributes["name"].value, item, False)
  120. html += "\t\t\t\t</div>\n"
  121. return html
  122. def makeHTML(fileName, moduleName):
  123. print ("Parsing %s\n" % fileName)
  124. sourceXML = open(fileName)
  125. dom = parse(sourceXML)
  126. sourceXML.close()
  127. classList = ""
  128. classList += "\t<div class=\"col-md-3\">"
  129. classList += "\t<ul class=\"list-group\">\n"
  130. classListPlain = []
  131. for item in dom.documentElement.getElementsByTagName('class'):
  132. classList += "<a href=\"%s.html\" class=\"list-group-item\">%s</a>" % (item.attributes["name"].value, item.attributes["name"].value)
  133. classListPlain.append(item.attributes["name"].value)
  134. classList += "\t\t\t</ul>\n"
  135. classList += "\t\t\t</div>\n"
  136. classList += "\n"
  137. if siteDocs == True:
  138. directory = "../site_html/%s" % (moduleName)
  139. else:
  140. directory = "../html/%s" % (moduleName)
  141. if not os.path.exists(directory):
  142. os.makedirs(directory)
  143. html = globalHeader
  144. html += classList
  145. html += globalFooter
  146. if siteDocs == True:
  147. f = open("../site_html/%s/index.html" % (moduleName), 'w')
  148. else:
  149. f = open("../html/%s/index.html" % (moduleName), 'w')
  150. f.write(html)
  151. f.close()
  152. for item in dom.documentElement.getElementsByTagName('class'):
  153. if siteDocs == True:
  154. f = open("../site_html/%s/%s.html" % (moduleName, item.attributes["name"].value), 'w')
  155. else:
  156. f = open("../html/%s/%s.html" % (moduleName, item.attributes["name"].value), 'w')
  157. html = makePage(item, classList, classListPlain, moduleName)
  158. f.write(html)
  159. f.close()
  160. dirList = os.listdir("../xml")
  161. indexhtml = globalHeaderMain
  162. indexhtml += "\t<div class=\"col-md-3\">"
  163. indexhtml += "\t<ul class=\"list-group\">\n"
  164. for fname in dirList:
  165. if len(fname.split(".")) > 1:
  166. if fname.split(".")[1] == "xml":
  167. moduleName = fname.split(".")[0]
  168. makeHTML("../xml/%s" % (fname), moduleName)
  169. indexhtml += "<a href=\"%s/index.html\" class=\"list-group-item\">%s</a>" % (moduleName, moduleName)
  170. indexhtml += "\t</ul>\n"
  171. indexhtml += "\t</div>\n"
  172. if siteDocs == True:
  173. f = open("../site_html/index.html", 'w')
  174. else:
  175. f = open("../html/index.html", 'w')
  176. f.write(indexhtml)
  177. f.close()
  178. indexhtml += globalFooter