make_html.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 = subitem.getElementsByTagName('desc')
  80. descText = "No description."
  81. if len(desc) > 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. html += "\t\t\t\t</div>\n"
  90. return html
  91. def makeHTML(fileName, moduleName):
  92. print ("Parsing %s\n" % fileName)
  93. sourceXML = open(fileName)
  94. dom = parse(sourceXML)
  95. sourceXML.close()
  96. classList = ""
  97. classList += "\t\t\t<div id=\"class_list\">\n"
  98. for item in dom.documentElement.getElementsByTagName('class'):
  99. 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)
  100. classList += "\t\t\t</div>\n"
  101. classList += "\n"
  102. directory = "../html/%s" % (moduleName)
  103. if not os.path.exists(directory):
  104. os.makedirs(directory)
  105. html = globalHeader
  106. html += classList
  107. html += globalFooter
  108. f = open("../html/%s/index.html" % (moduleName), 'w')
  109. f.write(html)
  110. f.close()
  111. for item in dom.documentElement.getElementsByTagName('class'):
  112. f = open("../html/%s/%s.html" % (moduleName, item.attributes["name"].value), 'w')
  113. html = makePage(item, classList)
  114. f.write(html)
  115. f.close()
  116. dirList = os.listdir("../xml")
  117. indexhtml = globalHeaderMain
  118. indexhtml += "\t<div id=\"module_links\">\n"
  119. for fname in dirList:
  120. if len(fname.split(".")) > 1:
  121. if fname.split(".")[1] == "xml":
  122. moduleName = fname.split(".")[0]
  123. makeHTML("../xml/%s" % (fname), moduleName)
  124. indexhtml += "\t\t\t<div class=\"module_link\"><a href=\"%s/index.html\">%s</a></div>\n" % (moduleName, moduleName)
  125. indexhtml += "\t</div>\n"
  126. f = open("../html/index.html", 'w')
  127. f.write(indexhtml)
  128. f.close()
  129. indexhtml += globalFooter