make_html.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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<script type=\"text/javascript\" src=\"js/docs.js\"></script>"
  9. globalHeaderMain += "\t</head>\n"
  10. globalHeaderMain += "\t<body>\n"
  11. globalHeaderMain += "\t\t<div id=\"global_header\"></div>\n"
  12. globalHeaderMain += "\t\t<div id=\"content\">\n"
  13. globalHeader = ""
  14. globalFooter = ""
  15. globalHeader += "<html>\n"
  16. globalHeader += "\t<head>\n"
  17. globalHeader += "\t\t<title>Polycode Documentation</title>\n"
  18. globalHeader += "\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"../css/docs.css\" />\n"
  19. globalHeader += "\t\t<script type=\"text/javascript\" src=\"js/docs.js\"></script>"
  20. globalHeader += "\t</head>\n"
  21. globalHeader += "\t<body>\n"
  22. globalHeader += "\t\t<div id=\"global_header\"></div>\n"
  23. globalHeader += "\t\t<div id=\"content\">\n"
  24. globalFooter += "\t\t</div>\n"
  25. globalFooter += "\t</body>\n"
  26. globalFooter += "\t</html>\n"
  27. def makePage(item, classList):
  28. html = globalHeader
  29. html += classList
  30. html += "\t\t\t\t<div class=\"class_main\">\n"
  31. html += "\t\t\t\t\t<div class=\"class_name\">%s</div>\n" % (item.attributes["name"].value)
  32. desc = item.getElementsByTagName('desc')
  33. descText = "No description."
  34. if len(desc) > 0:
  35. descText = desc[0].childNodes[0].data
  36. html += "\t\t\t\t\t<div class=\"class_desc\">%s</div>\n" % descText
  37. html += "\t\t\t\t\t<div class=\"class_properies\">\n"
  38. html += "\t\t\t\t\t\t<div class=\"class_properies_title\">Properties</div>\n"
  39. html += "\t\t\t\t\t\t<div class=\"class_properies_list\">\n"
  40. for subitem in item.getElementsByTagName('member'):
  41. html += "\t\t\t\t\t\t\t<div class=\"class_property\">\n"
  42. html += "\t\t\t\t\t\t\t\t<div class=\"class_property_name\">%s</div>\n" % (subitem.attributes["name"].value)
  43. html += "\t\t\t\t\t\t\t\t<div class=\"class_property_type\">%s</div>\n" % (subitem.attributes["type"].value)
  44. desc = subitem.getElementsByTagName('desc')
  45. descText = "No description."
  46. if len(desc) > 0:
  47. descText = desc[0].childNodes[0].data
  48. html += "\t\t\t\t\t\t\t\t<div class=\"class_property_desc\">%s</div>\n" % (descText)
  49. html += "\t\t\t\t\t\t\t</div>\n"
  50. html += "\t\t\t\t\t\t</div>\n"
  51. html += "\t\t\t\t\t</div>\n"
  52. html += "\t\t\t\t\t<div class=\"class_methods\">\n"
  53. html += "\t\t\t\t\t\t<div class=\"class_methods_title\">Functions</div>\n"
  54. html += "\t\t\t\t\t\t<div class=\"class_methods_list\">\n"
  55. for subitem in item.getElementsByTagName('method'):
  56. html += "\t\t\t\t\t\t\t<div class=\"class_method\">\n"
  57. paramList = ""
  58. paramIndex = 0
  59. if len(subitem.getElementsByTagName('param')) > 0:
  60. for param in subitem.getElementsByTagName('param'):
  61. if paramIndex != 0:
  62. paramList += ", "
  63. paramList += " <span class=\"inline_type\">%s</span> <span class=\"inline_param\">%s</span> " % (param.attributes["type"].value, param.attributes["name"].value)
  64. paramIndex = paramIndex + 1
  65. html += "\t\t\t\t\t\t\t\t<div class=\"class_method_name\">%s (%s) </div>\n" % (subitem.attributes["name"].value, paramList)
  66. html += "\t\t\t\t\t\t\t\t<div class=\"class_method_type\">%s</div>\n" % (subitem.attributes["return_type"].value)
  67. desc = subitem.getElementsByTagName('desc')
  68. descText = "No description."
  69. if len(desc) > 0:
  70. descText = desc[0].childNodes[0].data
  71. html += "\t\t\t\t\t\t\t\t<div class=\"class_method_desc\">%s</div>\n" % (descText)
  72. if len(subitem.getElementsByTagName('param')) > 0:
  73. html += "\t\t\t\t\t\t\t\t<div class=\"class_method_params\">\n"
  74. html += "\t\t\t\t\t\t\t\t<div class=\"class_method_params_title\">Parameters</div>\n"
  75. for param in subitem.getElementsByTagName('param'):
  76. html += "\t\t\t\t\t\t\t\t<div class=\"class_method_param\">\n"
  77. html += "\t\t\t\t\t\t\t\t\t<div class=\"class_method_param_name\">%s</div>\n" % (param.attributes["name"].value)
  78. html += "\t\t\t\t\t\t\t\t\t<div class=\"class_method_param_type\">%s</div>\n" % (param.attributes["type"].value)
  79. desc = param.getElementsByTagName('desc')
  80. descText = "No description."
  81. if len(desc) > 0:
  82. if len(desc[0].childNodes) > 0:
  83. descText = desc[0].childNodes[0].data
  84. html += "\t\t\t\t\t\t\t\t\t<div class=\"class_method_param_desc\">%s</div>\n" % (descText)
  85. html += "\t\t\t\t\t\t\t\t</div>\n"
  86. html += "\t\t\t\t\t\t\t\t</div>\n"
  87. html += "\t\t\t\t\t\t\t</div>\n"
  88. html += "\t\t\t\t\t\t</div>\n"
  89. html += "\t\t\t\t\t</div>\n"
  90. html += "\t\t\t\t</div>\n"
  91. return html
  92. def makeHTML(fileName, moduleName):
  93. print ("Parsing %s\n" % fileName)
  94. sourceXML = open(fileName)
  95. dom = parse(sourceXML)
  96. sourceXML.close()
  97. classList = ""
  98. classList += "\t\t\t<div id=\"class_list\">\n"
  99. for item in dom.documentElement.getElementsByTagName('class'):
  100. 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)
  101. classList += "\t\t\t</div>\n"
  102. classList += "\n"
  103. directory = "../html/%s" % (moduleName)
  104. if not os.path.exists(directory):
  105. os.makedirs(directory)
  106. html = globalHeader
  107. html += classList
  108. html += globalFooter
  109. f = open("../html/%s/index.html" % (moduleName), 'w')
  110. f.write(html)
  111. f.close()
  112. for item in dom.documentElement.getElementsByTagName('class'):
  113. f = open("../html/%s/%s.html" % (moduleName, item.attributes["name"].value), 'w')
  114. html = makePage(item, classList)
  115. f.write(html)
  116. f.close()
  117. dirList = os.listdir("../xml")
  118. indexhtml = globalHeaderMain
  119. indexhtml += "\t<div id=\"module_links\">\n"
  120. for fname in dirList:
  121. if len(fname.split(".")) > 1:
  122. if fname.split(".")[1] == "xml":
  123. moduleName = fname.split(".")[0]
  124. makeHTML("../xml/%s" % (fname), moduleName)
  125. indexhtml += "\t\t\t<div class=\"module_link\"><a href=\"%s/index.html\">%s</a></div>\n" % (moduleName, moduleName)
  126. indexhtml += "\t</div>\n"
  127. f = open("../html/index.html", 'w')
  128. f.write(indexhtml)
  129. f.close()
  130. indexhtml += globalFooter