PageRenderTime 39ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/jsdoc_toolkit-2.2.1/jsdoc-toolkit/templates/jsdoc/publish.js

http://jsdoc-toolkit.googlecode.com/
JavaScript | 184 lines | 129 code | 34 blank | 21 comment | 25 complexity | 36f5145a1bfa554e9b68f09f6758f686 MD5 | raw file
  1. /** Called automatically by JsDoc Toolkit. */
  2. function publish(symbolSet) {
  3. publish.conf = { // trailing slash expected for dirs
  4. ext: ".html",
  5. outDir: JSDOC.opt.d || SYS.pwd+"../out/jsdoc/",
  6. templatesDir: JSDOC.opt.t || SYS.pwd+"../templates/jsdoc/",
  7. symbolsDir: "symbols/",
  8. srcDir: "symbols/src/"
  9. };
  10. // is source output is suppressed, just display the links to the source file
  11. if (JSDOC.opt.s && defined(Link) && Link.prototype._makeSrcLink) {
  12. Link.prototype._makeSrcLink = function(srcFilePath) {
  13. return "<"+srcFilePath+">";
  14. }
  15. }
  16. // create the folders and subfolders to hold the output
  17. IO.mkPath((publish.conf.outDir+"symbols/src").split("/"));
  18. // used to allow Link to check the details of things being linked to
  19. Link.symbolSet = symbolSet;
  20. // create the required templates
  21. try {
  22. var classTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"class.tmpl");
  23. var classesTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"allclasses.tmpl");
  24. }
  25. catch(e) {
  26. print("Couldn't create the required templates: "+e);
  27. quit();
  28. }
  29. // some ustility filters
  30. function hasNoParent($) {return ($.memberOf == "")}
  31. function isaFile($) {return ($.is("FILE"))}
  32. function isaClass($) {return ($.is("CONSTRUCTOR") || $.isNamespace)}
  33. // get an array version of the symbolset, useful for filtering
  34. var symbols = symbolSet.toArray();
  35. // create the hilited source code files
  36. var files = JSDOC.opt.srcFiles;
  37. for (var i = 0, l = files.length; i < l; i++) {
  38. var file = files[i];
  39. var srcDir = publish.conf.outDir + "symbols/src/";
  40. makeSrcFile(file, srcDir);
  41. }
  42. // get a list of all the classes in the symbolset
  43. var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
  44. // create a class index, displayed in the left-hand column of every class page
  45. Link.base = "../";
  46. publish.classesIndex = classesTemplate.process(classes); // kept in memory
  47. // create each of the class pages
  48. for (var i = 0, l = classes.length; i < l; i++) {
  49. var symbol = classes[i];
  50. symbol.events = symbol.getEvents(); // 1 order matters
  51. symbol.methods = symbol.getMethods(); // 2
  52. var output = "";
  53. output = classTemplate.process(symbol);
  54. IO.saveFile(publish.conf.outDir+"symbols/", symbol.alias+publish.conf.ext, output);
  55. }
  56. // regenerate the index with different relative links, used in the index pages
  57. Link.base = "";
  58. publish.classesIndex = classesTemplate.process(classes);
  59. // create the class index page
  60. try {
  61. var classesindexTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"index.tmpl");
  62. }
  63. catch(e) { print(e.message); quit(); }
  64. var classesIndex = classesindexTemplate.process(classes);
  65. IO.saveFile(publish.conf.outDir, "index"+publish.conf.ext, classesIndex);
  66. classesindexTemplate = classesIndex = classes = null;
  67. // create the file index page
  68. try {
  69. var fileindexTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"allfiles.tmpl");
  70. }
  71. catch(e) { print(e.message); quit(); }
  72. var documentedFiles = symbols.filter(isaFile); // files that have file-level docs
  73. var allFiles = []; // not all files have file-level docs, but we need to list every one
  74. for (var i = 0; i < files.length; i++) {
  75. allFiles.push(new JSDOC.Symbol(files[i], [], "FILE", new JSDOC.DocComment("/** */")));
  76. }
  77. for (var i = 0; i < documentedFiles.length; i++) {
  78. var offset = files.indexOf(documentedFiles[i].alias);
  79. allFiles[offset] = documentedFiles[i];
  80. }
  81. allFiles = allFiles.sort(makeSortby("name"));
  82. // output the file index page
  83. var filesIndex = fileindexTemplate.process(allFiles);
  84. IO.saveFile(publish.conf.outDir, "files"+publish.conf.ext, filesIndex);
  85. fileindexTemplate = filesIndex = files = null;
  86. }
  87. /** Just the first sentence (up to a full stop). Should not break on dotted variable names. */
  88. function summarize(desc) {
  89. if (typeof desc != "undefined")
  90. return desc.match(/([\w\W]+?\.)[^a-z0-9_$]/i)? RegExp.$1 : desc;
  91. }
  92. /** Make a symbol sorter by some attribute. */
  93. function makeSortby(attribute) {
  94. return function(a, b) {
  95. if (a[attribute] != undefined && b[attribute] != undefined) {
  96. a = a[attribute].toLowerCase();
  97. b = b[attribute].toLowerCase();
  98. if (a < b) return -1;
  99. if (a > b) return 1;
  100. return 0;
  101. }
  102. }
  103. }
  104. /** Pull in the contents of an external file at the given path. */
  105. function include(path) {
  106. var path = publish.conf.templatesDir+path;
  107. return IO.readFile(path);
  108. }
  109. /** Turn a raw source file into a code-hilited page in the docs. */
  110. function makeSrcFile(path, srcDir, name) {
  111. if (JSDOC.opt.s) return;
  112. if (!name) {
  113. name = path.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
  114. name = name.replace(/\:/g, "_");
  115. }
  116. var src = {path: path, name:name, charset: IO.encoding, hilited: ""};
  117. if (defined(JSDOC.PluginManager)) {
  118. JSDOC.PluginManager.run("onPublishSrc", src);
  119. }
  120. if (src.hilited) {
  121. IO.saveFile(srcDir, name+publish.conf.ext, src.hilited);
  122. }
  123. }
  124. /** Build output for displaying function parameters. */
  125. function makeSignature(params) {
  126. if (!params) return "()";
  127. var signature = "("
  128. +
  129. params.filter(
  130. function($) {
  131. return $.name.indexOf(".") == -1; // don't show config params in signature
  132. }
  133. ).map(
  134. function($) {
  135. return $.name;
  136. }
  137. ).join(", ")
  138. +
  139. ")";
  140. return signature;
  141. }
  142. /** Find symbol {@link ...} strings in text and turn into html links */
  143. function resolveLinks(str, from) {
  144. str = str.replace(/\{@link ([^} ]+) ?\}/gi,
  145. function(match, symbolName) {
  146. return new Link().toSymbol(symbolName);
  147. }
  148. );
  149. return str;
  150. }