/tags/jsdoc_toolkit-1.3.3/app/JsDoc.js

http://jsdoc-toolkit.googlecode.com/ · JavaScript · 98 lines · 54 code · 17 blank · 27 comment · 9 complexity · d9e8450be83830c2adefa720fe468eb5 MD5 · raw file

  1. /**
  2. * @fileOverview
  3. * @name JsDoc Toolkit
  4. * @author Michael Mathews micmath@gmail.com
  5. * @url $HeadURL: http://jsdoc-toolkit.googlecode.com/svn/tags/jsdoc_toolkit-1.3.3/app/JsDoc.js $
  6. * @revision $Id: JsDoc.js 276 2007-10-16 23:32:57Z micmath $
  7. * @license <a href="http://en.wikipedia.org/wiki/MIT_License">X11/MIT License</a>
  8. * (See the accompanying README file for full details.)
  9. */
  10. /** @class Handle reporting messages to the user
  11. @static
  12. */
  13. LOG = {
  14. warn: function(msg, e) {
  15. if (e) msg = e.fileName+", line "+e.lineNumber+": "+msg;
  16. msg = ">> WARNING: "+msg;
  17. if (LOG.out) LOG.out.write(msg+"\n");
  18. else print(msg);
  19. },
  20. inform: function(msg) {
  21. msg = " > "+msg;
  22. if (LOG.out) LOG.out.write(msg+"\n");
  23. else print(msg);
  24. }
  25. };
  26. /**
  27. @class An automated documentation publishing system for JavaScript.
  28. @static
  29. @author Michael Mathews <a href="mailto:micmath@gmail.com">micmath@gmail.com</a>
  30. */
  31. JsDoc = {
  32. VERSION: "1.3.3",
  33. /**
  34. * Print out the expected usage syntax for this script on the command
  35. * line. This is called automatically by using the -h/--help option.
  36. */
  37. usage: function() {
  38. print("USAGE: java -jar app/js.jar app/jsdoc.js [OPTIONS] <SRC_DIR> <SRC_FILE> ...");
  39. print("");
  40. print("OPTIONS:");
  41. print(" -t=<PATH> or --template=<PATH>\n Required. Use this template to format the output.\n");
  42. print(" -d=<PATH> or --directory=<PATH>\n Output to this directory (defaults to js_docs_out).\n");
  43. print(" -r=<DEPTH> or --recurse=<DEPTH>\n Descend into src directories.\n");
  44. print(" -x=<EXT>[,EXT]... or --ext=<EXT>[,EXT]...\n Scan source files with the given extension/s (defaults to js).\n");
  45. print(" -a or --allfunctions\n Include all functions, even undocumented ones.\n");
  46. print(" -A or --Allfunctions\n Include all functions, even undocumented, underscored ones.\n");
  47. print(" -p or --private\n Include symbols tagged as private.\n");
  48. print(" -o=<PATH> or --out=<PATH>\n Print log messages to a file (defaults to stdout).\n");
  49. print(" -h or --help\n Show this message and exit.\n");
  50. java.lang.System.exit(0);
  51. },
  52. /**
  53. * @param {string[]} srcFiles Paths to files to be documented
  54. * @return {DocFile[]}
  55. */
  56. parse: function(srcFiles) {
  57. var files = [];
  58. if (typeof srcFiles == "string") srcFiles = [srcFiles];
  59. var parser = new JsParse();
  60. srcFiles = srcFiles.sort();
  61. var docs = new DocFileGroup();
  62. // handle setting up relationships between symbols here
  63. for (var f = 0; f < srcFiles.length; f++) {
  64. var srcFile = srcFiles[f];
  65. LOG.inform("Tokenizing: file "+(f+1)+", "+srcFile);
  66. var src = IO.readFile(srcFile);
  67. var tokens = new TokenReader(src).tokenize();
  68. LOG.inform("\t"+tokens.length+" tokens found.");
  69. var ts = new TokenStream(tokens);
  70. var file = new DocFile(srcFile);
  71. parser.parse(ts);
  72. LOG.inform("\t"+parser.symbols.length+" symbols found.");
  73. file.addSymbols(parser.symbols, JsDoc.opt);
  74. if (parser.overview) file.overview = parser.overview;
  75. docs.addDocFile(file);
  76. }
  77. return docs;
  78. }
  79. };
  80. /** Override this dummy function in your template. */
  81. function publish() {}