/tags/jsdoc_toolkit-1.3.3/templates/sunny/publish.js

http://jsdoc-toolkit.googlecode.com/ · JavaScript · 73 lines · 61 code · 11 blank · 1 comment · 16 complexity · b03c73dec667b691984d4e5588a09cd3 MD5 · raw file

  1. require("app/JsHilite.js");
  2. function basename(filename) {
  3. filename.match(/([^\/\\]+)\.[^\/\\]+$/);
  4. return RegExp.$1;
  5. }
  6. function publish(fileGroup, context) {
  7. var classTemplate = new JsPlate(context.t+"class.tmpl");
  8. var indexTemplate = new JsPlate(context.t+"index.tmpl");
  9. var allFiles = {};
  10. var allClasses = {};
  11. var globals = {methods:[], properties:[], alias:"GLOBALS", isStatic:true};
  12. for (var i = 0; i < fileGroup.files.length; i++) {
  13. var file_basename = basename(fileGroup.files[i].filename);
  14. var file_srcname = file_basename+".src.html";
  15. for (var s = 0; s < fileGroup.files[i].symbols.length; s++) {
  16. if (fileGroup.files[i].symbols[s].isa == "CONSTRUCTOR") {
  17. var thisClass = fileGroup.files[i].symbols[s];
  18. // sort inherited methods by class
  19. var inheritedMethods = fileGroup.files[i].symbols[s].getInheritedMethods();
  20. if (inheritedMethods.length > 0) {
  21. thisClass.inherited = {};
  22. for (var n = 0; n < inheritedMethods.length; n++) {
  23. if (! thisClass.inherited[inheritedMethods[n].memberof]) thisClass.inherited[inheritedMethods[n].memberof] = [];
  24. thisClass.inherited[inheritedMethods[n].memberof].push(inheritedMethods[n]);
  25. }
  26. }
  27. thisClass.name = fileGroup.files[i].symbols[s].alias;
  28. thisClass.source = file_srcname;
  29. thisClass.filename = fileGroup.files[i].filename;
  30. thisClass.docs = thisClass.name+".html";
  31. if (!allClasses[thisClass.name]) allClasses[thisClass.name] = [];
  32. allClasses[thisClass.name].push(thisClass);
  33. }
  34. else if (fileGroup.files[i].symbols[s].alias == fileGroup.files[i].symbols[s].name) {
  35. if (fileGroup.files[i].symbols[s].isa == "FUNCTION") {
  36. globals.methods.push(fileGroup.files[i].symbols[s]);
  37. }
  38. else {
  39. globals.properties.push(fileGroup.files[i].symbols[s]);
  40. }
  41. }
  42. }
  43. if (!allFiles[fileGroup.files[i].path]) {
  44. var hiliter = new JsHilite(IO.readFile(fileGroup.files[i].path));
  45. IO.saveFile(context.d, file_srcname, hiliter.hilite());
  46. }
  47. fileGroup.files[i].source = file_srcname;
  48. allFiles[fileGroup.files[i].path] = true;
  49. }
  50. for (var c in allClasses) {
  51. outfile = c+".html";
  52. allClasses[c].outfile = outfile;
  53. var output = classTemplate.process(allClasses[c]);
  54. IO.saveFile(context.d, outfile, output);
  55. }
  56. output = classTemplate.process([globals]);
  57. IO.saveFile(context.d, "globals.html", output);
  58. var output = indexTemplate.process(allClasses);
  59. IO.saveFile(context.d, "allclasses-frame.html", output);
  60. IO.copyFile(context.t+"index.html", context.d);
  61. IO.copyFile(context.t+"splash.html", context.d);
  62. }