jsdoc 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +17 -0
  3. data/VERSION +1 -0
  4. data/bin/jsdoc +5 -0
  5. data/jsdoc.gemspec +162 -0
  6. data/lib/jsdoc-toolkit-2.4.0/README.txt +183 -0
  7. data/lib/jsdoc-toolkit-2.4.0/app/frame.js +33 -0
  8. data/lib/jsdoc-toolkit-2.4.0/app/frame/Chain.js +102 -0
  9. data/lib/jsdoc-toolkit-2.4.0/app/frame/Dumper.js +144 -0
  10. data/lib/jsdoc-toolkit-2.4.0/app/frame/Hash.js +84 -0
  11. data/lib/jsdoc-toolkit-2.4.0/app/frame/Link.js +173 -0
  12. data/lib/jsdoc-toolkit-2.4.0/app/frame/Namespace.js +10 -0
  13. data/lib/jsdoc-toolkit-2.4.0/app/frame/Opt.js +134 -0
  14. data/lib/jsdoc-toolkit-2.4.0/app/frame/Reflection.js +26 -0
  15. data/lib/jsdoc-toolkit-2.4.0/app/frame/String.js +93 -0
  16. data/lib/jsdoc-toolkit-2.4.0/app/frame/Testrun.js +129 -0
  17. data/lib/jsdoc-toolkit-2.4.0/app/handlers/FOODOC.js +26 -0
  18. data/lib/jsdoc-toolkit-2.4.0/app/handlers/XMLDOC.js +26 -0
  19. data/lib/jsdoc-toolkit-2.4.0/app/handlers/XMLDOC/DomReader.js +159 -0
  20. data/lib/jsdoc-toolkit-2.4.0/app/handlers/XMLDOC/XMLDoc.js +16 -0
  21. data/lib/jsdoc-toolkit-2.4.0/app/handlers/XMLDOC/XMLParse.js +292 -0
  22. data/lib/jsdoc-toolkit-2.4.0/app/lib/JSDOC.js +106 -0
  23. data/lib/jsdoc-toolkit-2.4.0/app/lib/JSDOC/DocComment.js +204 -0
  24. data/lib/jsdoc-toolkit-2.4.0/app/lib/JSDOC/DocTag.js +294 -0
  25. data/lib/jsdoc-toolkit-2.4.0/app/lib/JSDOC/JsDoc.js +140 -0
  26. data/lib/jsdoc-toolkit-2.4.0/app/lib/JSDOC/JsPlate.js +109 -0
  27. data/lib/jsdoc-toolkit-2.4.0/app/lib/JSDOC/Lang.js +144 -0
  28. data/lib/jsdoc-toolkit-2.4.0/app/lib/JSDOC/Parser.js +146 -0
  29. data/lib/jsdoc-toolkit-2.4.0/app/lib/JSDOC/PluginManager.js +33 -0
  30. data/lib/jsdoc-toolkit-2.4.0/app/lib/JSDOC/Symbol.js +644 -0
  31. data/lib/jsdoc-toolkit-2.4.0/app/lib/JSDOC/SymbolSet.js +243 -0
  32. data/lib/jsdoc-toolkit-2.4.0/app/lib/JSDOC/TextStream.js +41 -0
  33. data/lib/jsdoc-toolkit-2.4.0/app/lib/JSDOC/Token.js +18 -0
  34. data/lib/jsdoc-toolkit-2.4.0/app/lib/JSDOC/TokenReader.js +332 -0
  35. data/lib/jsdoc-toolkit-2.4.0/app/lib/JSDOC/TokenStream.js +133 -0
  36. data/lib/jsdoc-toolkit-2.4.0/app/lib/JSDOC/Util.js +32 -0
  37. data/lib/jsdoc-toolkit-2.4.0/app/lib/JSDOC/Walker.js +507 -0
  38. data/lib/jsdoc-toolkit-2.4.0/app/main.js +111 -0
  39. data/lib/jsdoc-toolkit-2.4.0/app/plugins/commentSrcJson.js +20 -0
  40. data/lib/jsdoc-toolkit-2.4.0/app/plugins/frameworkPrototype.js +16 -0
  41. data/lib/jsdoc-toolkit-2.4.0/app/plugins/functionCall.js +10 -0
  42. data/lib/jsdoc-toolkit-2.4.0/app/plugins/publishSrcHilite.js +62 -0
  43. data/lib/jsdoc-toolkit-2.4.0/app/plugins/symbolLink.js +10 -0
  44. data/lib/jsdoc-toolkit-2.4.0/app/plugins/tagParamConfig.js +31 -0
  45. data/lib/jsdoc-toolkit-2.4.0/app/plugins/tagSynonyms.js +43 -0
  46. data/lib/jsdoc-toolkit-2.4.0/app/run.js +348 -0
  47. data/lib/jsdoc-toolkit-2.4.0/app/t/TestDoc.js +144 -0
  48. data/lib/jsdoc-toolkit-2.4.0/app/t/runner.js +13 -0
  49. data/lib/jsdoc-toolkit-2.4.0/app/test.js +342 -0
  50. data/lib/jsdoc-toolkit-2.4.0/app/test/addon.js +24 -0
  51. data/lib/jsdoc-toolkit-2.4.0/app/test/anon_inner.js +14 -0
  52. data/lib/jsdoc-toolkit-2.4.0/app/test/augments.js +31 -0
  53. data/lib/jsdoc-toolkit-2.4.0/app/test/augments2.js +26 -0
  54. data/lib/jsdoc-toolkit-2.4.0/app/test/borrows.js +46 -0
  55. data/lib/jsdoc-toolkit-2.4.0/app/test/borrows2.js +23 -0
  56. data/lib/jsdoc-toolkit-2.4.0/app/test/config.js +22 -0
  57. data/lib/jsdoc-toolkit-2.4.0/app/test/constructs.js +18 -0
  58. data/lib/jsdoc-toolkit-2.4.0/app/test/encoding.js +10 -0
  59. data/lib/jsdoc-toolkit-2.4.0/app/test/encoding_other.js +12 -0
  60. data/lib/jsdoc-toolkit-2.4.0/app/test/event.js +54 -0
  61. data/lib/jsdoc-toolkit-2.4.0/app/test/exports.js +14 -0
  62. data/lib/jsdoc-toolkit-2.4.0/app/test/functions_anon.js +39 -0
  63. data/lib/jsdoc-toolkit-2.4.0/app/test/functions_nested.js +33 -0
  64. data/lib/jsdoc-toolkit-2.4.0/app/test/global.js +13 -0
  65. data/lib/jsdoc-toolkit-2.4.0/app/test/globals.js +25 -0
  66. data/lib/jsdoc-toolkit-2.4.0/app/test/ignore.js +10 -0
  67. data/lib/jsdoc-toolkit-2.4.0/app/test/inner.js +16 -0
  68. data/lib/jsdoc-toolkit-2.4.0/app/test/jsdoc_test.js +477 -0
  69. data/lib/jsdoc-toolkit-2.4.0/app/test/lend.js +33 -0
  70. data/lib/jsdoc-toolkit-2.4.0/app/test/memberof.js +19 -0
  71. data/lib/jsdoc-toolkit-2.4.0/app/test/memberof2.js +38 -0
  72. data/lib/jsdoc-toolkit-2.4.0/app/test/memberof3.js +33 -0
  73. data/lib/jsdoc-toolkit-2.4.0/app/test/memberof_constructor.js +17 -0
  74. data/lib/jsdoc-toolkit-2.4.0/app/test/module.js +17 -0
  75. data/lib/jsdoc-toolkit-2.4.0/app/test/multi_methods.js +25 -0
  76. data/lib/jsdoc-toolkit-2.4.0/app/test/name.js +19 -0
  77. data/lib/jsdoc-toolkit-2.4.0/app/test/namespace_nested.js +23 -0
  78. data/lib/jsdoc-toolkit-2.4.0/app/test/nocode.js +13 -0
  79. data/lib/jsdoc-toolkit-2.4.0/app/test/oblit_anon.js +20 -0
  80. data/lib/jsdoc-toolkit-2.4.0/app/test/overview.js +20 -0
  81. data/lib/jsdoc-toolkit-2.4.0/app/test/param_inline.js +37 -0
  82. data/lib/jsdoc-toolkit-2.4.0/app/test/params_optional.js +8 -0
  83. data/lib/jsdoc-toolkit-2.4.0/app/test/prototype.js +17 -0
  84. data/lib/jsdoc-toolkit-2.4.0/app/test/prototype_nested.js +9 -0
  85. data/lib/jsdoc-toolkit-2.4.0/app/test/prototype_oblit.js +13 -0
  86. data/lib/jsdoc-toolkit-2.4.0/app/test/prototype_oblit_constructor.js +24 -0
  87. data/lib/jsdoc-toolkit-2.4.0/app/test/public.js +10 -0
  88. data/lib/jsdoc-toolkit-2.4.0/app/test/scripts/code.js +5 -0
  89. data/lib/jsdoc-toolkit-2.4.0/app/test/scripts/notcode.txt +5 -0
  90. data/lib/jsdoc-toolkit-2.4.0/app/test/shared.js +42 -0
  91. data/lib/jsdoc-toolkit-2.4.0/app/test/shared2.js +2 -0
  92. data/lib/jsdoc-toolkit-2.4.0/app/test/shortcuts.js +22 -0
  93. data/lib/jsdoc-toolkit-2.4.0/app/test/static_this.js +13 -0
  94. data/lib/jsdoc-toolkit-2.4.0/app/test/synonyms.js +31 -0
  95. data/lib/jsdoc-toolkit-2.4.0/app/test/tosource.js +23 -0
  96. data/lib/jsdoc-toolkit-2.4.0/app/test/variable_redefine.js +14 -0
  97. data/lib/jsdoc-toolkit-2.4.0/changes.txt +124 -0
  98. data/lib/jsdoc-toolkit-2.4.0/conf/sample.conf +31 -0
  99. data/lib/jsdoc-toolkit-2.4.0/java/build.xml +36 -0
  100. data/lib/jsdoc-toolkit-2.4.0/java/build_1.4.xml +36 -0
  101. data/lib/jsdoc-toolkit-2.4.0/java/classes/js.jar +0 -0
  102. data/lib/jsdoc-toolkit-2.4.0/java/src/JsDebugRun.java +21 -0
  103. data/lib/jsdoc-toolkit-2.4.0/java/src/JsRun.java +21 -0
  104. data/lib/jsdoc-toolkit-2.4.0/jsdebug.jar +0 -0
  105. data/lib/jsdoc-toolkit-2.4.0/jsrun.jar +0 -0
  106. data/lib/jsdoc-toolkit-2.4.0/jsrun.sh +52 -0
  107. data/lib/jsdoc-toolkit-2.4.0/templates/jsdoc/allclasses.tmpl +17 -0
  108. data/lib/jsdoc-toolkit-2.4.0/templates/jsdoc/allfiles.tmpl +56 -0
  109. data/lib/jsdoc-toolkit-2.4.0/templates/jsdoc/class.tmpl +649 -0
  110. data/lib/jsdoc-toolkit-2.4.0/templates/jsdoc/index.tmpl +39 -0
  111. data/lib/jsdoc-toolkit-2.4.0/templates/jsdoc/publish.js +201 -0
  112. data/lib/jsdoc-toolkit-2.4.0/templates/jsdoc/static/default.css +162 -0
  113. data/lib/jsdoc-toolkit-2.4.0/templates/jsdoc/static/header.html +2 -0
  114. data/lib/jsdoc-toolkit-2.4.0/templates/jsdoc/static/index.html +19 -0
  115. data/lib/jsdoc-toolkit-2.4.0/templates/jsdoc/symbol.tmpl +35 -0
  116. data/lib/jsdoc.rb +23 -0
  117. data/test/helper.rb +10 -0
  118. data/test/test_jsdoc.rb +7 -0
  119. metadata +199 -0
@@ -0,0 +1,111 @@
1
+ /**
2
+ * @version $Id: main.js 818 2009-11-08 14:51:41Z micmath $
3
+ */
4
+
5
+ function main() {
6
+ IO.include("lib/JSDOC.js");
7
+ IO.includeDir("plugins/");
8
+
9
+ // process the options
10
+
11
+ // the -c option: options are defined in a configuration file
12
+ if (JSDOC.opt.c) {
13
+ eval("JSDOC.conf = " + IO.readFile(JSDOC.opt.c));
14
+
15
+ LOG.inform("Using configuration file at '"+JSDOC.opt.c+"'.");
16
+
17
+ for (var c in JSDOC.conf) {
18
+ if (c !== "D" && !defined(JSDOC.opt[c])) { // commandline overrules config file
19
+ JSDOC.opt[c] = JSDOC.conf[c];
20
+ }
21
+ }
22
+
23
+ if (typeof JSDOC.conf["_"] != "undefined") {
24
+ JSDOC.opt["_"] = JSDOC.opt["_"].concat(JSDOC.conf["_"]);
25
+ }
26
+
27
+ LOG.inform("With configuration: ");
28
+ for (var o in JSDOC.opt) {
29
+ LOG.inform(" "+o+": "+JSDOC.opt[o]);
30
+ }
31
+ }
32
+
33
+ // be verbose
34
+ if (JSDOC.opt.v) LOG.verbose = true;
35
+
36
+ // send log messages to a file
37
+ if (JSDOC.opt.o) LOG.out = IO.open(JSDOC.opt.o);
38
+
39
+ // run the unit tests
40
+ if (JSDOC.opt.T) {
41
+ LOG.inform("JsDoc Toolkit running in test mode at "+new Date()+".");
42
+ IO.include("frame/Testrun.js");
43
+ IO.include("test.js");
44
+ }
45
+ else {
46
+ // a template must be defined and must be a directory path
47
+ if (!JSDOC.opt.t && System.getProperty("jsdoc.template.dir")) {
48
+ JSDOC.opt.t = System.getProperty("jsdoc.template.dir");
49
+ }
50
+ if (JSDOC.opt.t && SYS.slash != JSDOC.opt.t.slice(-1)) {
51
+ JSDOC.opt.t += SYS.slash;
52
+ }
53
+
54
+ // verbose messages about the options we were given
55
+ LOG.inform("JsDoc Toolkit main() running at "+new Date()+".");
56
+ LOG.inform("With options: ");
57
+ for (var o in JSDOC.opt) {
58
+ LOG.inform(" "+o+": "+JSDOC.opt[o]);
59
+ }
60
+
61
+ // initialize and build a symbolSet from your code
62
+ JSDOC.JsDoc();
63
+
64
+ // debugger's option: dump the entire symbolSet produced from your code
65
+ if (JSDOC.opt.Z) {
66
+ LOG.warn("So you want to see the data structure, eh? This might hang if you have circular refs...");
67
+ IO.include("frame/Dumper.js");
68
+ var symbols = JSDOC.JsDoc.symbolSet.toArray();
69
+ for (var i = 0, l = symbols.length; i < l; i++) {
70
+ var symbol = symbols[i];
71
+ print("// symbol: " + symbol.alias);
72
+ print(symbol.serialize());
73
+ }
74
+ }
75
+ else {
76
+ if (typeof JSDOC.opt.t != "undefined") {
77
+ try {
78
+ // a file named "publish.js" must exist in the template directory
79
+ load(JSDOC.opt.t+"publish.js");
80
+
81
+ // and must define a function named "publish"
82
+ if (!publish) {
83
+ LOG.warn("No publish() function is defined in that template so nothing to do.");
84
+ }
85
+ else {
86
+ // which will be called with the symbolSet produced from your code
87
+ publish(JSDOC.JsDoc.symbolSet);
88
+ }
89
+ }
90
+ catch(e) {
91
+ LOG.warn("Sorry, that doesn't seem to be a valid template: "+JSDOC.opt.t+"publish.js : "+e);
92
+ }
93
+ }
94
+ else {
95
+ LOG.warn("No template given. Might as well read the usage notes.");
96
+ JSDOC.usage();
97
+ }
98
+ }
99
+ }
100
+
101
+ // notify of any warnings
102
+ if (!JSDOC.opt.q && LOG.warnings.length) {
103
+ print(LOG.warnings.length+" warning"+(LOG.warnings.length != 1? "s":"")+".");
104
+ }
105
+
106
+ // stop sending log messages to a file
107
+ if (LOG.out) {
108
+ LOG.out.flush();
109
+ LOG.out.close();
110
+ }
111
+ }
@@ -0,0 +1,20 @@
1
+ JSDOC.PluginManager.registerPlugin(
2
+ "JSDOC.commentSrcJson",
3
+ {
4
+ onDocCommentSrc: function(comment) {
5
+ var json;
6
+ if (/^\s*@json\b/.test(comment)) {
7
+ comment.src = new String(comment.src).replace("@json", "");
8
+
9
+ eval("json = "+comment.src);
10
+ var tagged = "";
11
+ for (var i in json) {
12
+ var tag = json[i];
13
+ // todo handle cases where tag is an object
14
+ tagged += "@"+i+" "+tag+"\n";
15
+ }
16
+ comment.src = tagged;
17
+ }
18
+ }
19
+ }
20
+ );
@@ -0,0 +1,16 @@
1
+ JSDOC.PluginManager.registerPlugin(
2
+ "JSDOC.frameworkPrototype",
3
+ {
4
+ onPrototypeClassCreate: function(classCreator) {
5
+ var desc = "";
6
+ if (classCreator.comment) {
7
+ desc = classCreator.comment;
8
+ }
9
+ var insert = desc+"/** @name "+classCreator.name+"\n@constructor\n@scope "+classCreator.name+".prototype */"
10
+
11
+ insert = insert.replace(/\*\/\/\*\*/g, "\n");
12
+ /*DEBUG*///print("insert is "+insert);
13
+ classCreator.addComment.data = insert;
14
+ }
15
+ }
16
+ );
@@ -0,0 +1,10 @@
1
+ JSDOC.PluginManager.registerPlugin(
2
+ "JSDOC.functionCall",
3
+ {
4
+ onFunctionCall: function(functionCall) {
5
+ if (functionCall.name == "dojo.define" && functionCall.arg1) {
6
+ functionCall.doc = "/** @lends "+eval(functionCall.arg1)+".prototype */";
7
+ }
8
+ }
9
+ }
10
+ );
@@ -0,0 +1,62 @@
1
+ JSDOC.PluginManager.registerPlugin(
2
+ "JSDOC.publishSrcHilite",
3
+ {
4
+ onPublishSrc: function(src) {
5
+ if (src.path in JsHilite.cache) {
6
+ return; // already generated src code
7
+ }
8
+ else JsHilite.cache[src.path] = true;
9
+
10
+ try {
11
+ var sourceCode = IO.readFile(src.path);
12
+ }
13
+ catch(e) {
14
+ print(e.message);
15
+ quit();
16
+ }
17
+
18
+ var hiliter = new JsHilite(sourceCode, src.charset);
19
+ src.hilited = hiliter.hilite();
20
+ }
21
+ }
22
+ );
23
+
24
+ function JsHilite(src, charset) {
25
+
26
+ var tr = new JSDOC.TokenReader();
27
+
28
+ tr.keepComments = true;
29
+ tr.keepDocs = true;
30
+ tr.keepWhite = true;
31
+
32
+ this.tokens = tr.tokenize(new JSDOC.TextStream(src));
33
+
34
+ // TODO is redefining toString() the best way?
35
+ JSDOC.Token.prototype.toString = function() {
36
+ return "<span class=\""+this.type+"\">"+this.data.replace(/</g, "&lt;")+"</span>";
37
+ }
38
+
39
+ if (!charset) charset = "utf-8";
40
+
41
+ this.header = '<html><head><meta http-equiv="content-type" content="text/html; charset='+charset+'"> '+
42
+ "<style>\n\
43
+ .KEYW {color: #933;}\n\
44
+ .COMM {color: #bbb; font-style: italic;}\n\
45
+ .NUMB {color: #393;}\n\
46
+ .STRN {color: #393;}\n\
47
+ .REGX {color: #339;}\n\
48
+ .line {border-right: 1px dotted #666; color: #666; font-style: normal;}\n\
49
+ </style></head><body><pre>";
50
+ this.footer = "</pre></body></html>";
51
+ this.showLinenumbers = true;
52
+ }
53
+
54
+ JsHilite.cache = {};
55
+
56
+ JsHilite.prototype.hilite = function() {
57
+ var hilited = this.tokens.join("");
58
+ var line = 1;
59
+ if (this.showLinenumbers) hilited = hilited.replace(/(^|\n)/g, function(m){return m+"<span class='line'>"+((line<10)? " ":"")+((line<100)? " ":"")+(line++)+"</span> "});
60
+
61
+ return this.header+hilited+this.footer;
62
+ }
@@ -0,0 +1,10 @@
1
+ JSDOC.PluginManager.registerPlugin(
2
+ "JSDOC.symbolLink",
3
+ {
4
+ onSymbolLink: function(link) {
5
+ // modify link.linkPath (the href part of the link)
6
+ // or link.linkText (the text displayed)
7
+ // or link.linkInner (the #name part of the link)
8
+ }
9
+ }
10
+ );
@@ -0,0 +1,31 @@
1
+ JSDOC.PluginManager.registerPlugin(
2
+ "JSDOC.tagParamConfig",
3
+ {
4
+ onDocCommentTags: function(comment) {
5
+ var currentParam = null;
6
+ var tags = comment.tags;
7
+ for (var i = 0, l = tags.length; i < l; i++) {
8
+
9
+ if (tags[i].title == "param") {
10
+ if (tags[i].name.indexOf(".") == -1) {
11
+ currentParam = i;
12
+ }
13
+ }
14
+ else if (tags[i].title == "config") {
15
+ tags[i].title = "param";
16
+ if (currentParam == null) {
17
+ tags[i].name = "arguments"+"."+tags[i].name;
18
+ }
19
+ else if (tags[i].name.indexOf(tags[currentParam].name+".") != 0) {
20
+ tags[i].name = tags[currentParam].name+"."+tags[i].name;
21
+ }
22
+ currentParam != null
23
+ //tags[currentParam].properties.push(tags[i]);
24
+ }
25
+ else {
26
+ currentParam = null;
27
+ }
28
+ }
29
+ }
30
+ }
31
+ );
@@ -0,0 +1,43 @@
1
+ JSDOC.PluginManager.registerPlugin(
2
+ "JSDOC.tagSynonyms",
3
+ {
4
+ onDocCommentSrc: function(comment) {
5
+ comment.src = comment.src.replace(/@methodOf\b/i, "@function\n@memberOf");
6
+ comment.src = comment.src.replace(/@fieldOf\b/i, "@field\n@memberOf");
7
+ },
8
+
9
+ onDocCommentTags: function(comment) {
10
+ for (var i = 0, l = comment.tags.length; i < l; i++) {
11
+ var title = comment.tags[i].title.toLowerCase();
12
+ var syn;
13
+ if ((syn = JSDOC.tagSynonyms.synonyms["="+title])) {
14
+ comment.tags[i].title = syn;
15
+ }
16
+ }
17
+ }
18
+ }
19
+ );
20
+
21
+ new Namespace(
22
+ "JSDOC.tagSynonyms",
23
+ function() {
24
+ JSDOC.tagSynonyms.synonyms = {
25
+ "=member": "memberOf",
26
+ "=memberof": "memberOf",
27
+ "=description": "desc",
28
+ "=exception": "throws",
29
+ "=argument": "param",
30
+ "=returns": "return",
31
+ "=classdescription": "class",
32
+ "=fileoverview": "overview",
33
+ "=extends": "augments",
34
+ "=base": "augments",
35
+ "=projectdescription": "overview",
36
+ "=classdescription": "class",
37
+ "=link": "see",
38
+ "=borrows": "inherits",
39
+ "=scope": "lends",
40
+ "=construct": "constructor"
41
+ }
42
+ }
43
+ );
@@ -0,0 +1,348 @@
1
+ /**
2
+ * @fileOverview
3
+ * A bootstrap script that creates some basic required objects
4
+ * for loading other scripts.
5
+ * @author Michael Mathews, micmath@gmail.com
6
+ * @version $Id: run.js 756 2009-01-07 21:32:58Z micmath $
7
+ */
8
+
9
+ /**
10
+ * @namespace Keep track of any messages from the running script.
11
+ */
12
+ LOG = {
13
+ warn: function(msg, e) {
14
+ if (JSDOC.opt.q) return;
15
+ if (e) msg = e.fileName+", line "+e.lineNumber+": "+msg;
16
+
17
+ msg = ">> WARNING: "+msg;
18
+ LOG.warnings.push(msg);
19
+ if (LOG.out) LOG.out.write(msg+"\n");
20
+ else print(msg);
21
+ },
22
+
23
+ inform: function(msg) {
24
+ if (JSDOC.opt.q) return;
25
+ msg = " > "+msg;
26
+ if (LOG.out) LOG.out.write(msg+"\n");
27
+ else if (typeof LOG.verbose != "undefined" && LOG.verbose) print(msg);
28
+ }
29
+ };
30
+ LOG.warnings = [];
31
+ LOG.verbose = false
32
+ LOG.out = undefined;
33
+
34
+ /**
35
+ * @class Manipulate a filepath.
36
+ */
37
+ function FilePath(absPath, separator) {
38
+ this.slash = separator || "/";
39
+ this.root = this.slash;
40
+ this.path = [];
41
+ this.file = "";
42
+
43
+ var parts = absPath.split(/[\\\/]/);
44
+ if (parts) {
45
+ if (parts.length) this.root = parts.shift() + this.slash;
46
+ if (parts.length) this.file = parts.pop()
47
+ if (parts.length) this.path = parts;
48
+ }
49
+
50
+ this.path = this.resolvePath();
51
+ }
52
+
53
+ /** Collapse any dot-dot or dot items in a filepath. */
54
+ FilePath.prototype.resolvePath = function() {
55
+ var resolvedPath = [];
56
+ for (var i = 0; i < this.path.length; i++) {
57
+ if (this.path[i] == "..") resolvedPath.pop();
58
+ else if (this.path[i] != ".") resolvedPath.push(this.path[i]);
59
+ }
60
+ return resolvedPath;
61
+ }
62
+
63
+ /** Trim off the filename. */
64
+ FilePath.prototype.toDir = function() {
65
+ if (this.file) this.file = "";
66
+ return this;
67
+ }
68
+
69
+ /** Go up a directory. */
70
+ FilePath.prototype.upDir = function() {
71
+ this.toDir();
72
+ if (this.path.length) this.path.pop();
73
+ return this;
74
+ }
75
+
76
+ FilePath.prototype.toString = function() {
77
+ return this.root
78
+ + this.path.join(this.slash)
79
+ + ((this.path.length > 0)? this.slash : "")
80
+ + this.file;
81
+ }
82
+
83
+ /**
84
+ * Turn a path into just the name of the file.
85
+ */
86
+ FilePath.fileName = function(path) {
87
+ var nameStart = Math.max(path.lastIndexOf("/")+1, path.lastIndexOf("\\")+1, 0);
88
+ return path.substring(nameStart);
89
+ }
90
+
91
+ /**
92
+ * Get the extension of a filename
93
+ */
94
+ FilePath.fileExtension = function(filename) {
95
+ return filename.split(".").pop().toLowerCase();
96
+ };
97
+
98
+ /**
99
+ * Turn a path into just the directory part.
100
+ */
101
+ FilePath.dir = function(path) {
102
+ var nameStart = Math.max(path.lastIndexOf("/")+1, path.lastIndexOf("\\")+1, 0);
103
+ return path.substring(0, nameStart-1);
104
+ }
105
+
106
+
107
+ importClass(java.lang.System);
108
+
109
+ /**
110
+ * @namespace A collection of information about your system.
111
+ */
112
+ SYS = {
113
+ /**
114
+ * Information about your operating system: arch, name, version.
115
+ * @type string
116
+ */
117
+ os: [
118
+ new String(System.getProperty("os.arch")),
119
+ new String(System.getProperty("os.name")),
120
+ new String(System.getProperty("os.version"))
121
+ ].join(", "),
122
+
123
+ /**
124
+ * Which way does your slash lean.
125
+ * @type string
126
+ */
127
+ slash: System.getProperty("file.separator")||"/",
128
+
129
+ /**
130
+ * The path to the working directory where you ran java.
131
+ * @type string
132
+ */
133
+ userDir: new String(System.getProperty("user.dir")),
134
+
135
+ /**
136
+ * Where is Java's home folder.
137
+ * @type string
138
+ */
139
+ javaHome: new String(System.getProperty("java.home")),
140
+
141
+ /**
142
+ * The absolute path to the directory containing this script.
143
+ * @type string
144
+ */
145
+ pwd: undefined
146
+ };
147
+
148
+ // jsrun appends an argument, with the path to here.
149
+ if (arguments[arguments.length-1].match(/^-j=(.+)/)) {
150
+ if (RegExp.$1.charAt(0) == SYS.slash || RegExp.$1.charAt(1) == ":") { // absolute path to here
151
+ SYS.pwd = new FilePath(RegExp.$1).toDir().toString();
152
+ }
153
+ else { // relative path to here
154
+ SYS.pwd = new FilePath(SYS.userDir + SYS.slash + RegExp.$1).toDir().toString();
155
+ }
156
+ arguments.pop();
157
+ }
158
+ else {
159
+ print("The run.js script requires you use jsrun.jar.");
160
+ quit();
161
+ }
162
+
163
+ // shortcut
164
+ var File = Packages.java.io.File;
165
+
166
+ /**
167
+ * @namespace A collection of functions that deal with reading a writing to disk.
168
+ */
169
+ IO = {
170
+
171
+ /**
172
+ * Create a new file in the given directory, with the given name and contents.
173
+ */
174
+ saveFile: function(/**string*/ outDir, /**string*/ fileName, /**string*/ content) {
175
+ var out = new Packages.java.io.PrintWriter(
176
+ new Packages.java.io.OutputStreamWriter(
177
+ new Packages.java.io.FileOutputStream(outDir+SYS.slash+fileName),
178
+ IO.encoding
179
+ )
180
+ );
181
+ out.write(content);
182
+ out.flush();
183
+ out.close();
184
+ },
185
+
186
+ /**
187
+ * @type string
188
+ */
189
+ readFile: function(/**string*/ path) {
190
+ if (!IO.exists(path)) {
191
+ throw "File doesn't exist there: "+path;
192
+ }
193
+ return readFile(path, IO.encoding);
194
+ },
195
+
196
+ /**
197
+ * @param inFile
198
+ * @param outDir
199
+ * @param [fileName=The original filename]
200
+ */
201
+ copyFile: function(/**string*/ inFile, /**string*/ outDir, /**string*/ fileName) {
202
+ if (fileName == null) fileName = FilePath.fileName(inFile);
203
+
204
+ var inFile = new File(inFile);
205
+ var outFile = new File(outDir+SYS.slash+fileName);
206
+
207
+ var bis = new Packages.java.io.BufferedInputStream(new Packages.java.io.FileInputStream(inFile), 4096);
208
+ var bos = new Packages.java.io.BufferedOutputStream(new Packages.java.io.FileOutputStream(outFile), 4096);
209
+ var theChar;
210
+ while ((theChar = bis.read()) != -1) {
211
+ bos.write(theChar);
212
+ }
213
+ bos.close();
214
+ bis.close();
215
+ },
216
+
217
+ /**
218
+ * Creates a series of nested directories.
219
+ */
220
+ mkPath: function(/**Array*/ path) {
221
+ if (path.constructor != Array) path = path.split(/[\\\/]/);
222
+ var make = "";
223
+ for (var i = 0, l = path.length; i < l; i++) {
224
+ make += path[i] + SYS.slash;
225
+ if (! IO.exists(make)) {
226
+ IO.makeDir(make);
227
+ }
228
+ }
229
+ },
230
+
231
+ /**
232
+ * Creates a directory at the given path.
233
+ */
234
+ makeDir: function(/**string*/ path) {
235
+ (new File(path)).mkdir();
236
+ },
237
+
238
+ /**
239
+ * @type string[]
240
+ * @param dir The starting directory to look in.
241
+ * @param [recurse=1] How many levels deep to scan.
242
+ * @returns An array of all the paths to files in the given dir.
243
+ */
244
+ ls: function(/**string*/ dir, /**number*/ recurse, _allFiles, _path) {
245
+ if (_path === undefined) { // initially
246
+ var _allFiles = [];
247
+ var _path = [dir];
248
+ }
249
+ if (_path.length == 0) return _allFiles;
250
+ if (recurse === undefined) recurse = 1;
251
+
252
+ dir = new File(dir);
253
+ if (!dir.directory) return [String(dir)];
254
+ var files = dir.list();
255
+
256
+ for (var f = 0; f < files.length; f++) {
257
+ var file = String(files[f]);
258
+ if (file.match(/^\.[^\.\/\\]/)) continue; // skip dot files
259
+
260
+ if ((new File(_path.join(SYS.slash)+SYS.slash+file)).list()) { // it's a directory
261
+ _path.push(file);
262
+ if (_path.length-1 < recurse) IO.ls(_path.join(SYS.slash), recurse, _allFiles, _path);
263
+ _path.pop();
264
+ }
265
+ else {
266
+ _allFiles.push((_path.join(SYS.slash)+SYS.slash+file).replace(SYS.slash+SYS.slash, SYS.slash));
267
+ }
268
+ }
269
+
270
+ return _allFiles;
271
+ },
272
+
273
+ /**
274
+ * @type boolean
275
+ */
276
+ exists: function(/**string*/ path) {
277
+ file = new File(path);
278
+
279
+ if (file.isDirectory()){
280
+ return true;
281
+ }
282
+ if (!file.exists()){
283
+ return false;
284
+ }
285
+ if (!file.canRead()){
286
+ return false;
287
+ }
288
+ return true;
289
+ },
290
+
291
+ /**
292
+ *
293
+ */
294
+ open: function(/**string*/ path, /**string*/ append) {
295
+ var append = true;
296
+ var outFile = new File(path);
297
+ var out = new Packages.java.io.PrintWriter(
298
+ new Packages.java.io.OutputStreamWriter(
299
+ new Packages.java.io.FileOutputStream(outFile, append),
300
+ IO.encoding
301
+ )
302
+ );
303
+ return out;
304
+ },
305
+
306
+ /**
307
+ * Sets {@link IO.encoding}.
308
+ * Encoding is used when reading and writing text to files,
309
+ * and in the meta tags of HTML output.
310
+ */
311
+ setEncoding: function(/**string*/ encoding) {
312
+ if (/ISO-8859-([0-9]+)/i.test(encoding)) {
313
+ IO.encoding = "ISO8859_"+RegExp.$1;
314
+ }
315
+ else {
316
+ IO.encoding = encoding;
317
+ }
318
+ },
319
+
320
+ /**
321
+ * @default "utf-8"
322
+ * @private
323
+ */
324
+ encoding: "utf-8",
325
+
326
+ /**
327
+ * Load the given script.
328
+ */
329
+ include: function(relativePath) {
330
+ load(SYS.pwd+relativePath);
331
+ },
332
+
333
+ /**
334
+ * Loads all scripts from the given directory path.
335
+ */
336
+ includeDir: function(path) {
337
+ if (!path) return;
338
+
339
+ for (var lib = IO.ls(SYS.pwd+path), i = 0; i < lib.length; i++)
340
+ if (/\.js$/i.test(lib[i])) load(lib[i]);
341
+ }
342
+ }
343
+
344
+ // now run the application
345
+ IO.include("frame.js");
346
+ IO.include("main.js");
347
+
348
+ main();