sc-docs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. data/.gitignore +4 -0
  2. data/.gitmodules +3 -0
  3. data/Gemfile +5 -0
  4. data/Gemfile.lock +48 -0
  5. data/LICENSE +21 -0
  6. data/README.md +59 -0
  7. data/bin/sc-docs +5 -0
  8. data/lib/sc_docs.rb +3 -0
  9. data/lib/sc_docs/cli.rb +54 -0
  10. data/lib/sc_docs/docs/Buildfile +8 -0
  11. data/lib/sc_docs/docs/README +8 -0
  12. data/lib/sc_docs/docs/apps/docs/Buildfile +15 -0
  13. data/lib/sc_docs/docs/apps/docs/controllers/classes.js +27 -0
  14. data/lib/sc_docs/docs/apps/docs/controllers/search_controller.js +62 -0
  15. data/lib/sc_docs/docs/apps/docs/controllers/selected_class.js +143 -0
  16. data/lib/sc_docs/docs/apps/docs/core.js +148 -0
  17. data/lib/sc_docs/docs/apps/docs/main.js +41 -0
  18. data/lib/sc_docs/docs/apps/docs/models/class.js +63 -0
  19. data/lib/sc_docs/docs/apps/docs/models/entity.js +29 -0
  20. data/lib/sc_docs/docs/apps/docs/models/method.js +79 -0
  21. data/lib/sc_docs/docs/apps/docs/models/property.js +48 -0
  22. data/lib/sc_docs/docs/apps/docs/resources/images/method_icon.png +0 -0
  23. data/lib/sc_docs/docs/apps/docs/resources/images/property_icon.png +0 -0
  24. data/lib/sc_docs/docs/apps/docs/resources/loading.rhtml +9 -0
  25. data/lib/sc_docs/docs/apps/docs/resources/main_page.css +156 -0
  26. data/lib/sc_docs/docs/apps/docs/resources/main_page.js +91 -0
  27. data/lib/sc_docs/docs/apps/docs/resources/templates/details.handlebars +81 -0
  28. data/lib/sc_docs/docs/apps/docs/resources/templates/extensions/signature.js +0 -0
  29. data/lib/sc_docs/docs/apps/docs/system/jquery_ui.js +62 -0
  30. data/lib/sc_docs/docs/apps/docs/system/showdown.js +1297 -0
  31. data/lib/sc_docs/docs/apps/docs/theme.js +29 -0
  32. data/lib/sc_docs/docs/apps/docs/views/detail_list.js +24 -0
  33. data/lib/sc_docs/docs/apps/docs/views/master_list.js +35 -0
  34. data/lib/sc_docs/docs/apps/docs/views/methods_collection.js +80 -0
  35. data/lib/sc_docs/docs/apps/docs/views/properties_collection.js +9 -0
  36. data/lib/sc_docs/generator.rb +145 -0
  37. data/lib/sc_docs/server.rb +21 -0
  38. data/lib/sc_docs/templates/docs.sproutcore.com/allclasses.tmpl +31 -0
  39. data/lib/sc_docs/templates/docs.sproutcore.com/allfiles.tmpl +66 -0
  40. data/lib/sc_docs/templates/docs.sproutcore.com/class.tmpl +437 -0
  41. data/lib/sc_docs/templates/docs.sproutcore.com/index.tmpl +52 -0
  42. data/lib/sc_docs/templates/docs.sproutcore.com/output/css/api.css +619 -0
  43. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/apidocs.jpg +0 -0
  44. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/apidocs.png +0 -0
  45. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/clearinput.png +0 -0
  46. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/cross.png +0 -0
  47. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/ddiagonal.png +0 -0
  48. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/diagonal.png +0 -0
  49. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/docbullet.jpg +0 -0
  50. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/docbullet.png +0 -0
  51. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/glow.png +0 -0
  52. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/logo.png +0 -0
  53. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/pixels.png +0 -0
  54. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/search.png +0 -0
  55. data/lib/sc_docs/templates/docs.sproutcore.com/output/js/api.js +134 -0
  56. data/lib/sc_docs/templates/docs.sproutcore.com/output/js/jquery-bbq.js +18 -0
  57. data/lib/sc_docs/templates/docs.sproutcore.com/output/js/lib/jquery-1.5.1.min.js +16 -0
  58. data/lib/sc_docs/templates/docs.sproutcore.com/output/js/lib/modernizr-1.7.min.js +2 -0
  59. data/lib/sc_docs/templates/docs.sproutcore.com/output/js/plugin.js +1 -0
  60. data/lib/sc_docs/templates/docs.sproutcore.com/output/js/script.js +5 -0
  61. data/lib/sc_docs/templates/docs.sproutcore.com/publish.js +200 -0
  62. data/lib/sc_docs/templates/docs.sproutcore.com/static/default.css +300 -0
  63. data/lib/sc_docs/templates/docs.sproutcore.com/static/header.html +19 -0
  64. data/lib/sc_docs/templates/docs.sproutcore.com/static/index.html +19 -0
  65. data/lib/sc_docs/templates/docs.sproutcore.com/symbol.tmpl +35 -0
  66. data/lib/sc_docs/templates/sc_fixture/publish.js +632 -0
  67. data/lib/sc_docs/version.rb +4 -0
  68. data/sc_docs.gemspec +27 -0
  69. data/vendor/jsdoc/README.txt +109 -0
  70. data/vendor/jsdoc/app/frame.js +33 -0
  71. data/vendor/jsdoc/app/frame/Chain.js +102 -0
  72. data/vendor/jsdoc/app/frame/Dumper.js +144 -0
  73. data/vendor/jsdoc/app/frame/Hash.js +84 -0
  74. data/vendor/jsdoc/app/frame/Link.js +173 -0
  75. data/vendor/jsdoc/app/frame/Namespace.js +10 -0
  76. data/vendor/jsdoc/app/frame/Opt.js +134 -0
  77. data/vendor/jsdoc/app/frame/Reflection.js +26 -0
  78. data/vendor/jsdoc/app/frame/String.js +93 -0
  79. data/vendor/jsdoc/app/frame/Testrun.js +129 -0
  80. data/vendor/jsdoc/app/handlers/FOODOC.js +26 -0
  81. data/vendor/jsdoc/app/handlers/XMLDOC.js +26 -0
  82. data/vendor/jsdoc/app/handlers/XMLDOC/DomReader.js +159 -0
  83. data/vendor/jsdoc/app/handlers/XMLDOC/XMLDoc.js +16 -0
  84. data/vendor/jsdoc/app/handlers/XMLDOC/XMLParse.js +292 -0
  85. data/vendor/jsdoc/app/lib/JSDOC.js +106 -0
  86. data/vendor/jsdoc/app/lib/JSDOC/DocComment.js +204 -0
  87. data/vendor/jsdoc/app/lib/JSDOC/DocTag.js +294 -0
  88. data/vendor/jsdoc/app/lib/JSDOC/JsDoc.js +140 -0
  89. data/vendor/jsdoc/app/lib/JSDOC/JsPlate.js +109 -0
  90. data/vendor/jsdoc/app/lib/JSDOC/Lang.js +144 -0
  91. data/vendor/jsdoc/app/lib/JSDOC/Parser.js +146 -0
  92. data/vendor/jsdoc/app/lib/JSDOC/PluginManager.js +33 -0
  93. data/vendor/jsdoc/app/lib/JSDOC/Symbol.js +644 -0
  94. data/vendor/jsdoc/app/lib/JSDOC/SymbolSet.js +243 -0
  95. data/vendor/jsdoc/app/lib/JSDOC/TextStream.js +41 -0
  96. data/vendor/jsdoc/app/lib/JSDOC/Token.js +18 -0
  97. data/vendor/jsdoc/app/lib/JSDOC/TokenReader.js +332 -0
  98. data/vendor/jsdoc/app/lib/JSDOC/TokenStream.js +133 -0
  99. data/vendor/jsdoc/app/lib/JSDOC/Util.js +32 -0
  100. data/vendor/jsdoc/app/lib/JSDOC/Walker.js +507 -0
  101. data/vendor/jsdoc/app/main.js +111 -0
  102. data/vendor/jsdoc/app/plugins/commentSrcJson.js +20 -0
  103. data/vendor/jsdoc/app/plugins/frameworkPrototype.js +16 -0
  104. data/vendor/jsdoc/app/plugins/functionCall.js +10 -0
  105. data/vendor/jsdoc/app/plugins/publishSrcHilite.js +62 -0
  106. data/vendor/jsdoc/app/plugins/symbolLink.js +10 -0
  107. data/vendor/jsdoc/app/plugins/tagParamConfig.js +31 -0
  108. data/vendor/jsdoc/app/plugins/tagSynonyms.js +43 -0
  109. data/vendor/jsdoc/app/run.js +297 -0
  110. data/vendor/jsdoc/app/t/TestDoc.js +144 -0
  111. data/vendor/jsdoc/app/t/runner.js +13 -0
  112. data/vendor/jsdoc/app/test.js +342 -0
  113. data/vendor/jsdoc/app/test/addon.js +24 -0
  114. data/vendor/jsdoc/app/test/anon_inner.js +14 -0
  115. data/vendor/jsdoc/app/test/augments.js +31 -0
  116. data/vendor/jsdoc/app/test/augments2.js +26 -0
  117. data/vendor/jsdoc/app/test/borrows.js +46 -0
  118. data/vendor/jsdoc/app/test/borrows2.js +23 -0
  119. data/vendor/jsdoc/app/test/config.js +22 -0
  120. data/vendor/jsdoc/app/test/constructs.js +18 -0
  121. data/vendor/jsdoc/app/test/encoding.js +10 -0
  122. data/vendor/jsdoc/app/test/encoding_other.js +12 -0
  123. data/vendor/jsdoc/app/test/event.js +54 -0
  124. data/vendor/jsdoc/app/test/exports.js +14 -0
  125. data/vendor/jsdoc/app/test/functions_anon.js +39 -0
  126. data/vendor/jsdoc/app/test/functions_nested.js +33 -0
  127. data/vendor/jsdoc/app/test/global.js +13 -0
  128. data/vendor/jsdoc/app/test/globals.js +25 -0
  129. data/vendor/jsdoc/app/test/ignore.js +10 -0
  130. data/vendor/jsdoc/app/test/inner.js +16 -0
  131. data/vendor/jsdoc/app/test/jsdoc_test.js +477 -0
  132. data/vendor/jsdoc/app/test/lend.js +33 -0
  133. data/vendor/jsdoc/app/test/memberof.js +19 -0
  134. data/vendor/jsdoc/app/test/memberof2.js +38 -0
  135. data/vendor/jsdoc/app/test/memberof3.js +33 -0
  136. data/vendor/jsdoc/app/test/memberof_constructor.js +17 -0
  137. data/vendor/jsdoc/app/test/module.js +17 -0
  138. data/vendor/jsdoc/app/test/multi_methods.js +25 -0
  139. data/vendor/jsdoc/app/test/name.js +19 -0
  140. data/vendor/jsdoc/app/test/namespace_nested.js +23 -0
  141. data/vendor/jsdoc/app/test/nocode.js +13 -0
  142. data/vendor/jsdoc/app/test/oblit_anon.js +20 -0
  143. data/vendor/jsdoc/app/test/overview.js +20 -0
  144. data/vendor/jsdoc/app/test/param_inline.js +37 -0
  145. data/vendor/jsdoc/app/test/params_optional.js +8 -0
  146. data/vendor/jsdoc/app/test/prototype.js +17 -0
  147. data/vendor/jsdoc/app/test/prototype_nested.js +9 -0
  148. data/vendor/jsdoc/app/test/prototype_oblit.js +13 -0
  149. data/vendor/jsdoc/app/test/prototype_oblit_constructor.js +24 -0
  150. data/vendor/jsdoc/app/test/public.js +10 -0
  151. data/vendor/jsdoc/app/test/scripts/code.js +5 -0
  152. data/vendor/jsdoc/app/test/scripts/notcode.txt +5 -0
  153. data/vendor/jsdoc/app/test/shared.js +42 -0
  154. data/vendor/jsdoc/app/test/shared2.js +2 -0
  155. data/vendor/jsdoc/app/test/shortcuts.js +22 -0
  156. data/vendor/jsdoc/app/test/static_this.js +13 -0
  157. data/vendor/jsdoc/app/test/synonyms.js +31 -0
  158. data/vendor/jsdoc/app/test/tosource.js +23 -0
  159. data/vendor/jsdoc/app/test/variable_redefine.js +14 -0
  160. data/vendor/jsdoc/changes.txt +127 -0
  161. data/vendor/jsdoc/conf/sample.conf +31 -0
  162. metadata +240 -0
@@ -0,0 +1,173 @@
1
+ /** Handle the creation of HTML links to documented symbols.
2
+ @constructor
3
+ */
4
+ function Link() {
5
+ this.alias = "";
6
+ this.src = "";
7
+ this.file = "";
8
+ this.text = "";
9
+ this.innerName = "";
10
+ this.classLink = false;
11
+ this.targetName = "";
12
+
13
+ this.target = function(targetName) {
14
+ if (defined(targetName)) this.targetName = targetName;
15
+ return this;
16
+ }
17
+ this.inner = function(inner) {
18
+ if (defined(inner)) this.innerName = inner;
19
+ return this;
20
+ }
21
+ this.withText = function(text) {
22
+ if (defined(text)) this.text = text;
23
+ return this;
24
+ }
25
+ this.toSrc = function(filename) {
26
+ if (defined(filename)) this.src = filename;
27
+ return this;
28
+ }
29
+ this.toSymbol = function(alias) {
30
+ if (defined(alias)) this.alias = new String(alias);
31
+ return this;
32
+ }
33
+ this.toClass = function(alias) {
34
+ this.classLink = true;
35
+ return this.toSymbol(alias);
36
+ }
37
+ this.toFile = function(file) {
38
+ if (defined(file)) this.file = file;
39
+ return this;
40
+ }
41
+
42
+ this.toString = function() {
43
+ var linkString;
44
+ var thisLink = this;
45
+
46
+ if (this.alias) {
47
+ linkString = this.alias.replace(/(^|[^a-z$0-9_#.:^-])([|a-z$0-9_#.:^-]+)($|[^a-z$0-9_#.:^-])/i,
48
+ function(match, prematch, symbolName, postmatch) {
49
+ var symbolNames = symbolName.split("|");
50
+ var links = [];
51
+ for (var i = 0, l = symbolNames.length; i < l; i++) {
52
+ thisLink.alias = symbolNames[i];
53
+ links.push(thisLink._makeSymbolLink(symbolNames[i]));
54
+ }
55
+ return prematch+links.join("|")+postmatch;
56
+ }
57
+ );
58
+ }
59
+ else if (this.src) {
60
+ linkString = thisLink._makeSrcLink(this.src);
61
+ }
62
+ else if (this.file) {
63
+ linkString = thisLink._makeFileLink(this.file);
64
+ }
65
+
66
+ return linkString;
67
+ }
68
+ }
69
+
70
+ /** prefixed for hashes */
71
+ Link.hashPrefix = "";
72
+
73
+ /** Appended to the front of relative link paths. */
74
+ Link.base = "";
75
+
76
+ Link.symbolNameToLinkName = function(symbol) {
77
+ var linker = "",
78
+ ns = "";
79
+
80
+ if (symbol.isStatic) linker = ".";
81
+ else if (symbol.isInner) linker = "-";
82
+
83
+ if (symbol.isEvent && !/^event:/.test(symbol.name)) {
84
+ ns = "event:";
85
+ }
86
+ return Link.hashPrefix+linker+ns+symbol.name;
87
+ }
88
+
89
+ Link.getSymbol= function(alias) {
90
+ var symbol= Link.symbolSet.getSymbol(alias);
91
+
92
+ if (symbol)
93
+ return symbol;
94
+
95
+ if ('#'!==alias.charAt(0) || !Link.currentSymbol)
96
+ return null;
97
+
98
+ // resolve relative name
99
+ var container= Link.currentSymbol;
100
+
101
+ while (container)
102
+ {
103
+ symbol= Link.symbolSet.getSymbol(container.alias + alias);
104
+ if (symbol)
105
+ return symbol;
106
+
107
+ // No superclass
108
+ if (!container.augments.length)
109
+ return null;
110
+
111
+ container= Link.symbolSet.getSymbol(container.augments[0].desc);
112
+ }
113
+
114
+ return null;
115
+ }
116
+
117
+ /** Create a link to another symbol. */
118
+ Link.prototype._makeSymbolLink = function(alias) {
119
+ var linkBase = Link.base+publish.conf.symbolsDir;
120
+ var linkTo = Link.getSymbol(alias);
121
+ var linkPath;
122
+ var target = (this.targetName)? " target=\""+this.targetName+"\"" : "";
123
+
124
+ // if there is no symbol by that name just return the name unaltered
125
+ if (!linkTo)
126
+ return this.text || alias;
127
+
128
+ // it's a symbol in another file
129
+ else {
130
+ if (!linkTo.is("CONSTRUCTOR") && !linkTo.isNamespace) { // it's a method or property
131
+ linkPath= (Link.filemap) ? Link.filemap[linkTo.memberOf] :
132
+ escape(linkTo.memberOf) || "_global_";
133
+ linkPath += publish.conf.ext + "#" + Link.symbolNameToLinkName(linkTo);
134
+ }
135
+ else {
136
+ linkPath = (Link.filemap)? Link.filemap[linkTo.alias] : escape(linkTo.alias);
137
+ linkPath += publish.conf.ext;// + (this.classLink? "":"#" + Link.hashPrefix + "constructor");
138
+ }
139
+ linkPath = linkBase + linkPath
140
+ }
141
+
142
+ var linkText= this.text || alias;
143
+
144
+ var link = {linkPath: linkPath, linkText: linkText, linkInner: (this.innerName? "#"+this.innerName : "")};
145
+
146
+ if (typeof JSDOC.PluginManager != "undefined") {
147
+ JSDOC.PluginManager.run("onSymbolLink", link);
148
+ }
149
+
150
+ return "<a href=\""+link.linkPath+link.linkInner+"\""+target+">"+link.linkText+"</a>";
151
+ }
152
+
153
+ /** Create a link to a source file. */
154
+ Link.prototype._makeSrcLink = function(srcFilePath) {
155
+ var target = (this.targetName)? " target=\""+this.targetName+"\"" : "";
156
+
157
+ // transform filepath into a filename
158
+ var srcFile = srcFilePath.replace(/\.\.?[\\\/]/g, "").replace(/[:\\\/]/g, "_");
159
+ var outFilePath = Link.base + publish.conf.srcDir + srcFile + publish.conf.ext;
160
+
161
+ if (!this.text) this.text = FilePath.fileName(srcFilePath);
162
+ return "<a href=\""+outFilePath+"\""+target+">"+this.text+"</a>";
163
+ }
164
+
165
+ /** Create a link to a source file. */
166
+ Link.prototype._makeFileLink = function(filePath) {
167
+ var target = (this.targetName)? " target=\""+this.targetName+"\"" : "";
168
+
169
+ var outFilePath = Link.base + filePath;
170
+
171
+ if (!this.text) this.text = filePath;
172
+ return "<a href=\""+outFilePath+"\""+target+">"+this.text+"</a>";
173
+ }
@@ -0,0 +1,10 @@
1
+ _global_ = this;
2
+
3
+ function Namespace(name, f) {
4
+ var n = name.split(".");
5
+ for (var o = _global_, i = 0, l = n.length; i < l; i++) {
6
+ o = o[n[i]] = o[n[i]] || {};
7
+ }
8
+
9
+ if (f) f();
10
+ }
@@ -0,0 +1,134 @@
1
+ /** @namespace */
2
+ Opt = {
3
+ /**
4
+ * Get commandline option values.
5
+ * @param {Array} args Commandline arguments. Like ["-a=xml", "-b", "--class=new", "--debug"]
6
+ * @param {object} optNames Map short names to long names. Like {a:"accept", b:"backtrace", c:"class", d:"debug"}.
7
+ * @return {object} Short names and values. Like {a:"xml", b:true, c:"new", d:true}
8
+ */
9
+ get: function(args, optNames) {
10
+ var opt = {"_": []}; // the unnamed option allows multiple values
11
+ for (var i = 0; i < args.length; i++) {
12
+ var arg = new String(args[i]);
13
+ var name;
14
+ var value;
15
+ if (arg.charAt(0) == "-") {
16
+ if (arg.charAt(1) == "-") { // it's a longname like --foo
17
+ arg = arg.substring(2);
18
+ var m = arg.split("=");
19
+ name = m.shift();
20
+ value = m.shift();
21
+ if (typeof value == "undefined") value = true;
22
+
23
+ for (var n in optNames) { // convert it to a shortname
24
+ if (name == optNames[n]) {
25
+ name = n;
26
+ }
27
+ }
28
+ }
29
+ else { // it's a shortname like -f
30
+ arg = arg.substring(1);
31
+ var m = arg.split("=");
32
+ name = m.shift();
33
+ value = m.shift();
34
+ if (typeof value == "undefined") value = true;
35
+
36
+ for (var n in optNames) { // find the matching key
37
+ if (name == n || name+'[]' == n) {
38
+ name = n;
39
+ break;
40
+ }
41
+ }
42
+ }
43
+ if (name.match(/(.+)\[\]$/)) { // it's an array type like n[]
44
+ name = RegExp.$1;
45
+ if (!opt[name]) opt[name] = [];
46
+ }
47
+
48
+ if (opt[name] && opt[name].push) {
49
+ opt[name].push(value);
50
+ }
51
+ else {
52
+ opt[name] = value;
53
+ }
54
+ }
55
+ else { // not associated with any optname
56
+ opt._.push(args[i]);
57
+ }
58
+ }
59
+ return opt;
60
+ }
61
+ }
62
+
63
+ /*t:
64
+ plan(11, "Testing Opt.");
65
+
66
+ is(
67
+ typeof Opt,
68
+ "object",
69
+ "Opt is an object."
70
+ );
71
+
72
+ is(
73
+ typeof Opt.get,
74
+ "function",
75
+ "Opt.get is a function."
76
+ );
77
+
78
+ var optNames = {a:"accept", b:"backtrace", c:"class", d:"debug", "e[]":"exceptions"};
79
+ var t_options = Opt.get(["-a=xml", "-b", "--class=new", "--debug", "-e=one", "-e=two", "foo", "bar"], optNames);
80
+
81
+ is(
82
+ t_options.a,
83
+ "xml",
84
+ "an option defined with a short name can be accessed by its short name."
85
+ );
86
+
87
+ is(
88
+ t_options.b,
89
+ true,
90
+ "an option defined with a short name and no value are true."
91
+ );
92
+
93
+ is(
94
+ t_options.c,
95
+ "new",
96
+ "an option defined with a long name can be accessed by its short name."
97
+ );
98
+
99
+ is(
100
+ t_options.d,
101
+ true,
102
+ "an option defined with a long name and no value are true."
103
+ );
104
+
105
+ is(
106
+ typeof t_options.e,
107
+ "object",
108
+ "an option that can accept multiple values is defined."
109
+ );
110
+
111
+ is(
112
+ t_options.e.length,
113
+ 2,
114
+ "an option that can accept multiple values can have more than one value."
115
+ );
116
+
117
+ is(
118
+ t_options.e[1],
119
+ "two",
120
+ "an option that can accept multiple values can be accessed as an array."
121
+ );
122
+
123
+ is(
124
+ typeof t_options._,
125
+ "object",
126
+ "the property '_' is defined for unnamed options."
127
+ );
128
+
129
+ is(
130
+ t_options._[0],
131
+ "foo",
132
+ "the property '_' can be accessed as an array."
133
+ );
134
+ */
@@ -0,0 +1,26 @@
1
+ /**@constructor*/
2
+ function Reflection(obj) {
3
+ this.obj = obj;
4
+ }
5
+
6
+ Reflection.prototype.getConstructorName = function() {
7
+ if (this.obj.constructor.name) return this.obj.constructor.name;
8
+ var src = this.obj.constructor.toSource();
9
+ var name = src.substring(name.indexOf("function")+8, src.indexOf('(')).replace(/ /g,'');
10
+ return name;
11
+ }
12
+
13
+ Reflection.prototype.getMethod = function(name) {
14
+ for (var p in this.obj) {
15
+ if (p == name && typeof(this.obj[p]) == "function") return this.obj[p];
16
+ }
17
+ return null;
18
+ }
19
+
20
+ Reflection.prototype.getParameterNames = function() {
21
+ var src = this.obj.toSource();
22
+ src = src.substring(
23
+ src.indexOf("(", 8)+1, src.indexOf(")")
24
+ );
25
+ return src.split(/, ?/);
26
+ }
@@ -0,0 +1,93 @@
1
+ /**
2
+ @name String
3
+ @class Additions to the core string object.
4
+ */
5
+
6
+ /** @author Steven Levithan, released as public domain. */
7
+ String.prototype.trim = function() {
8
+ var str = this.replace(/^\s+/, '');
9
+ for (var i = str.length - 1; i >= 0; i--) {
10
+ if (/\S/.test(str.charAt(i))) {
11
+ str = str.substring(0, i + 1);
12
+ break;
13
+ }
14
+ }
15
+ return str;
16
+ }
17
+ /*t:
18
+ plan(6, "Testing String.prototype.trim.");
19
+
20
+ var s = " a bc ".trim();
21
+ is(s, "a bc", "multiple spaces front and back are trimmed.");
22
+
23
+ s = "a bc\n\n".trim();
24
+ is(s, "a bc", "newlines only in back are trimmed.");
25
+
26
+ s = "\ta bc".trim();
27
+ is(s, "a bc", "tabs only in front are trimmed.");
28
+
29
+ s = "\n \t".trim();
30
+ is(s, "", "an all-space string is trimmed to empty.");
31
+
32
+ s = "a b\nc".trim();
33
+ is(s, "a b\nc", "a string with no spaces in front or back is trimmed to itself.");
34
+
35
+ s = "".trim();
36
+ is(s, "", "an empty string is trimmed to empty.");
37
+
38
+ */
39
+
40
+ String.prototype.balance = function(open, close) {
41
+ var i = 0;
42
+ while (this.charAt(i) != open) {
43
+ if (i == this.length) return [-1, -1];
44
+ i++;
45
+ }
46
+
47
+ var j = i+1;
48
+ var balance = 1;
49
+ while (j < this.length) {
50
+ if (this.charAt(j) == open) balance++;
51
+ if (this.charAt(j) == close) balance--;
52
+ if (balance == 0) break;
53
+ j++;
54
+ if (j == this.length) return [-1, -1];
55
+ }
56
+
57
+ return [i, j];
58
+ }
59
+ /*t:
60
+ plan(16, "Testing String.prototype.balance.");
61
+
62
+ var s = "{abc}".balance("{","}");
63
+ is(s[0], 0, "opener in first is found.");
64
+ is(s[1], 4, "closer in last is found.");
65
+
66
+ s = "ab{c}de".balance("{","}");
67
+ is(s[0], 2, "opener in middle is found.");
68
+ is(s[1], 4, "closer in middle is found.");
69
+
70
+ s = "a{b{c}de}f".balance("{","}");
71
+ is(s[0], 1, "nested opener is found.");
72
+ is(s[1], 8, "nested closer is found.");
73
+
74
+ s = "{}".balance("{","}");
75
+ is(s[0], 0, "opener with no content is found.");
76
+ is(s[1], 1, "closer with no content is found.");
77
+
78
+ s = "".balance("{","}");
79
+ is(s[0], -1, "empty string opener is -1.");
80
+ is(s[1], -1, "empty string closer is -1.");
81
+
82
+ s = "{abc".balance("{","}");
83
+ is(s[0], -1, "opener with no closer returns -1.");
84
+ is(s[1], -1, "no closer returns -1.");
85
+
86
+ s = "abc".balance("{","}");
87
+ is(s[0], -1, "no opener or closer returns -1 for opener.");
88
+ is(s[1], -1, "no opener or closer returns -1 for closer.");
89
+
90
+ s = "a<bc}de".balance("<","}");
91
+ is(s[0], 1, "unmatching opener is found.");
92
+ is(s[1], 4, "unmatching closer is found.");
93
+ */
@@ -0,0 +1,129 @@
1
+ /**
2
+ * @fileOverview
3
+ * @name JsTestrun
4
+ * @author Michael Mathews micmath@gmail.com
5
+ * @url $HeadURL: https://jsdoc-toolkit.googlecode.com/svn/tags/jsdoc_toolkit-2.4.0/jsdoc-toolkit/app/frame/Testrun.js $
6
+ * @revision $Id: Testrun.js 418 2008-01-15 21:40:33Z 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
+
11
+ /**
12
+ Yet another unit testing tool for JavaScript.
13
+ @author Michael Mathews <a href="mailto:micmath@gmail.com">micmath@gmail.com</a>
14
+ @param {object} testCases Properties are testcase names, values are functions to execute as tests.
15
+ */
16
+ function testrun(testCases) {
17
+ var ran = 0;
18
+ for (t in testCases) {
19
+ var result = testCases[t]();
20
+ ran++;
21
+ }
22
+
23
+ return testrun.reportOut+"-------------------------------\n"+((testrun.fails>0)? ":( Failed "+testrun.fails+"/" : ":) Passed all ")+testrun.count+" test"+((testrun.count == 1)? "":"s")+".\n";
24
+ }
25
+
26
+
27
+ testrun.count = 0;
28
+ testrun.current = null;
29
+ testrun.passes = 0;
30
+ testrun.fails = 0;
31
+ testrun.reportOut = "";
32
+
33
+ /** @private */
34
+ testrun.report = function(text) {
35
+ testrun.reportOut += text+"\n";
36
+ }
37
+
38
+ /**
39
+ Check if test evaluates to true.
40
+ @param {string} test To be evaluated.
41
+ @param {string} message Optional. To be displayed in the report.
42
+ @return {boolean} True if the string test evaluates to true.
43
+ */
44
+ ok = function(test, message) {
45
+ testrun.count++;
46
+
47
+ var result;
48
+ try {
49
+ result = eval(test);
50
+
51
+ if (result) {
52
+ testrun.passes++;
53
+ testrun.report(" OK "+testrun.count+" - "+((message != null)? message : ""));
54
+ }
55
+ else {
56
+ testrun.fails++;
57
+ testrun.report("NOT OK "+testrun.count+" - "+((message != null)? message : ""));
58
+ }
59
+ }
60
+ catch(e) {
61
+ testrun.fails++
62
+ testrun.report("NOT OK "+testrun.count+" - "+((message != null)? message : ""));
63
+
64
+ }
65
+ }
66
+
67
+ /**
68
+ Check if test is same as expected.
69
+ @param {string} test To be evaluated.
70
+ @param {string} expected
71
+ @param {string} message Optional. To be displayed in the report.
72
+ @return {boolean} True if (test == expected). Note that the comparison is not a strict equality check.
73
+ */
74
+ is = function(test, expected, message) {
75
+ testrun.count++;
76
+
77
+ var result;
78
+ try {
79
+ result = eval(test);
80
+
81
+ if (result == expected) {
82
+ testrun.passes++
83
+ testrun.report(" OK "+testrun.count+" - "+((message != null)? message : ""));
84
+ }
85
+ else {
86
+ testrun.fails++
87
+ testrun.report("NOT OK "+testrun.count+" - "+((message != null)? message : ""));
88
+ testrun.report("expected: "+expected);
89
+ testrun.report(" got: "+result);
90
+ }
91
+ }
92
+ catch(e) {
93
+ testrun.fails++
94
+ testrun.report("NOT OK "+testrun.count+" - "+((message != null)? message : ""));
95
+ testrun.report("expected: "+expected);
96
+ testrun.report(" got: "+result);}
97
+ }
98
+
99
+ /**
100
+ Check if test matches pattern.
101
+ @param {string} test To be evaluated.
102
+ @param {string} pattern Used to create a RegExp.
103
+ @param {string} message Optional. To be displayed in the report.
104
+ @return {boolean} True if test matches pattern.
105
+ */
106
+ like = function(test, pattern, message) {
107
+ testrun.count++;
108
+
109
+ var result;
110
+ try {
111
+ result = eval(test);
112
+ var rgx = new RegExp(pattern);
113
+
114
+ if (rgx.test(result)) {
115
+ testrun.passes++
116
+ testrun.report(" OK "+testrun.count+" - "+((message != null)? message : ""));
117
+ }
118
+ else {
119
+ testrun.fails++
120
+ testrun.report("NOT OK "+testrun.count+" - "+((message != null)? message : ""));
121
+ testrun.report(" this: "+result);
122
+ testrun.report("is not like: "+pattern);
123
+ }
124
+ }
125
+ catch(e) {
126
+ testrun.fails++
127
+ testrun.report("NOT OK "+testrun.count+" - "+((message != null)? message : ""));
128
+ }
129
+ }