sproutcore 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +269 -0
- data/README.txt +67 -0
- data/Rakefile +4 -0
- data/app_generators/sproutcore/USAGE +5 -0
- data/app_generators/sproutcore/sproutcore_generator.rb +66 -0
- data/app_generators/sproutcore/templates/README +77 -0
- data/app_generators/sproutcore/templates/environment.yml +4 -0
- data/bin/sc-build +145 -0
- data/bin/sc-gen +24 -0
- data/bin/sc-server +63 -0
- data/bin/sproutcore +21 -0
- data/clients/sc_docs/controllers/docs.js +118 -0
- data/clients/sc_docs/core.js +19 -0
- data/clients/sc_docs/english.lproj/body.css +159 -0
- data/clients/sc_docs/english.lproj/body.rhtml +33 -0
- data/clients/sc_docs/english.lproj/controls.css +0 -0
- data/clients/sc_docs/english.lproj/icons/small/next.png +0 -0
- data/clients/sc_docs/english.lproj/icons/small/reset.png +0 -0
- data/clients/sc_docs/english.lproj/images/gradients.png +0 -0
- data/clients/sc_docs/english.lproj/images/indicator.gif +0 -0
- data/clients/sc_docs/english.lproj/images/toolbar.png +0 -0
- data/clients/sc_docs/english.lproj/no_docs.rhtml +7 -0
- data/clients/sc_docs/english.lproj/strings.js +14 -0
- data/clients/sc_docs/english.lproj/warning.rhtml +6 -0
- data/clients/sc_docs/fixtures/doc.js +11 -0
- data/clients/sc_docs/main.js +21 -0
- data/clients/sc_docs/models/doc.js +9 -0
- data/clients/sc_docs/tests/controllers/docs.rhtml +21 -0
- data/clients/sc_docs/tests/models/doc.rhtml +21 -0
- data/clients/sc_docs/tests/views/doc_frame.rhtml +21 -0
- data/clients/sc_docs/tests/views/doc_label_view.rhtml +21 -0
- data/clients/sc_docs/views/doc_frame.js +33 -0
- data/clients/sc_docs/views/doc_label.js +20 -0
- data/clients/sc_test_runner/controllers/runner.js +175 -0
- data/clients/sc_test_runner/core.js +19 -0
- data/clients/sc_test_runner/english.lproj/body.css +151 -0
- data/clients/sc_test_runner/english.lproj/body.rhtml +35 -0
- data/clients/sc_test_runner/english.lproj/controls.css +0 -0
- data/clients/sc_test_runner/english.lproj/icons/small/next.png +0 -0
- data/clients/sc_test_runner/english.lproj/icons/small/reset.png +0 -0
- data/clients/sc_test_runner/english.lproj/images/gradients.png +0 -0
- data/clients/sc_test_runner/english.lproj/images/indicator.gif +0 -0
- data/clients/sc_test_runner/english.lproj/images/toolbar.png +0 -0
- data/clients/sc_test_runner/english.lproj/no_tests.rhtml +6 -0
- data/clients/sc_test_runner/english.lproj/strings.js +14 -0
- data/clients/sc_test_runner/english.lproj/warning.rhtml +6 -0
- data/clients/sc_test_runner/fixtures/test.js +12 -0
- data/clients/sc_test_runner/main.js +26 -0
- data/clients/sc_test_runner/models/test.js +11 -0
- data/clients/sc_test_runner/views/runner_frame.js +72 -0
- data/clients/sc_test_runner/views/test_label.js +20 -0
- data/config/hoe.rb +70 -0
- data/config/requirements.rb +17 -0
- data/environment.yml +9 -0
- data/frameworks/prototype/prototype.js +4186 -0
- data/frameworks/sproutcore/Core.js +378 -0
- data/frameworks/sproutcore/README +3 -0
- data/frameworks/sproutcore/controllers/array.js +236 -0
- data/frameworks/sproutcore/controllers/collection.js +305 -0
- data/frameworks/sproutcore/controllers/controller.js +323 -0
- data/frameworks/sproutcore/controllers/object.js +372 -0
- data/frameworks/sproutcore/drag/drag.js +549 -0
- data/frameworks/sproutcore/drag/drag_data_source.js +32 -0
- data/frameworks/sproutcore/drag/drag_source.js +64 -0
- data/frameworks/sproutcore/drag/drop_target.js +153 -0
- data/frameworks/sproutcore/english.lproj/blank.gif +0 -0
- data/frameworks/sproutcore/english.lproj/buttons.css +589 -0
- data/frameworks/sproutcore/english.lproj/buttons.png +0 -0
- data/frameworks/sproutcore/english.lproj/inline_text_editor.css +21 -0
- data/frameworks/sproutcore/english.lproj/menu.css +121 -0
- data/frameworks/sproutcore/english.lproj/panels/background-fat.jpg +0 -0
- data/frameworks/sproutcore/english.lproj/panels/background-thin.jpg +0 -0
- data/frameworks/sproutcore/english.lproj/panels/bottom-edge.png +0 -0
- data/frameworks/sproutcore/english.lproj/panels/bottom-left-corner.png +0 -0
- data/frameworks/sproutcore/english.lproj/panels/bottom-right-corner.png +0 -0
- data/frameworks/sproutcore/english.lproj/panels/left-edge.png +0 -0
- data/frameworks/sproutcore/english.lproj/panels/overlay.png +0 -0
- data/frameworks/sproutcore/english.lproj/panels/right-edge.png +0 -0
- data/frameworks/sproutcore/english.lproj/panels/top-edge.png +0 -0
- data/frameworks/sproutcore/english.lproj/panels/top-left-corner.png +0 -0
- data/frameworks/sproutcore/english.lproj/panels/top-right-corner.png +0 -0
- data/frameworks/sproutcore/english.lproj/panes.css +155 -0
- data/frameworks/sproutcore/english.lproj/picker.css +22 -0
- data/frameworks/sproutcore/english.lproj/strings.js +15 -0
- data/frameworks/sproutcore/english.lproj/tab.css +23 -0
- data/frameworks/sproutcore/english.lproj/tests.css +67 -0
- data/frameworks/sproutcore/english.lproj/theme.css +77 -0
- data/frameworks/sproutcore/foundation/animator.js +670 -0
- data/frameworks/sproutcore/foundation/application.js +199 -0
- data/frameworks/sproutcore/foundation/array.js +348 -0
- data/frameworks/sproutcore/foundation/benchmark.js +211 -0
- data/frameworks/sproutcore/foundation/binding.js +384 -0
- data/frameworks/sproutcore/foundation/date.js +357 -0
- data/frameworks/sproutcore/foundation/error.js +39 -0
- data/frameworks/sproutcore/foundation/input_manager.js +153 -0
- data/frameworks/sproutcore/foundation/json.js +296 -0
- data/frameworks/sproutcore/foundation/mock.js +42 -0
- data/frameworks/sproutcore/foundation/node_descriptor.js +56 -0
- data/frameworks/sproutcore/foundation/object.js +777 -0
- data/frameworks/sproutcore/foundation/observable.js +451 -0
- data/frameworks/sproutcore/foundation/page.js +63 -0
- data/frameworks/sproutcore/foundation/path_module.js +413 -0
- data/frameworks/sproutcore/foundation/responder.js +310 -0
- data/frameworks/sproutcore/foundation/routes.js +371 -0
- data/frameworks/sproutcore/foundation/run_loop.js +21 -0
- data/frameworks/sproutcore/foundation/server.js +491 -0
- data/frameworks/sproutcore/foundation/set.js +96 -0
- data/frameworks/sproutcore/foundation/string.js +149 -0
- data/frameworks/sproutcore/foundation/undo_manager.js +186 -0
- data/frameworks/sproutcore/foundation/unittest.js +622 -0
- data/frameworks/sproutcore/foundation/utils.js +61 -0
- data/frameworks/sproutcore/globals/panels.js +182 -0
- data/frameworks/sproutcore/globals/popups.js +60 -0
- data/frameworks/sproutcore/globals/window.js +381 -0
- data/frameworks/sproutcore/lib/index.rhtml +66 -0
- data/frameworks/sproutcore/models/collection.js +395 -0
- data/frameworks/sproutcore/models/record.js +622 -0
- data/frameworks/sproutcore/models/store.js +295 -0
- data/frameworks/sproutcore/panes/dialog.js +16 -0
- data/frameworks/sproutcore/panes/manager.js +164 -0
- data/frameworks/sproutcore/panes/menu.js +45 -0
- data/frameworks/sproutcore/panes/overlay.js +231 -0
- data/frameworks/sproutcore/panes/pane.js +90 -0
- data/frameworks/sproutcore/panes/panel.js +19 -0
- data/frameworks/sproutcore/panes/picker.js +45 -0
- data/frameworks/sproutcore/tests/controllers/array.rhtml +86 -0
- data/frameworks/sproutcore/tests/controllers/controller.rhtml +273 -0
- data/frameworks/sproutcore/tests/controllers/object.rhtml +327 -0
- data/frameworks/sproutcore/tests/foundation/application.rhtml +125 -0
- data/frameworks/sproutcore/tests/foundation/array.rhtml +221 -0
- data/frameworks/sproutcore/tests/foundation/object.rhtml +69 -0
- data/frameworks/sproutcore/tests/globals/window.rhtml +45 -0
- data/frameworks/sproutcore/tests/panes/pane.rhtml +88 -0
- data/frameworks/sproutcore/tests/views/collection.rhtml +137 -0
- data/frameworks/sproutcore/tests/views/popup_button.rhtml +115 -0
- data/frameworks/sproutcore/tests/views/text_field.rhtml +37 -0
- data/frameworks/sproutcore/validators/credit_card.js +92 -0
- data/frameworks/sproutcore/validators/date.js +36 -0
- data/frameworks/sproutcore/validators/email.js +29 -0
- data/frameworks/sproutcore/validators/not_empty.js +24 -0
- data/frameworks/sproutcore/validators/number.js +55 -0
- data/frameworks/sproutcore/validators/password.js +78 -0
- data/frameworks/sproutcore/validators/validator.js +304 -0
- data/frameworks/sproutcore/views/button.js +425 -0
- data/frameworks/sproutcore/views/checkbox_field.js +30 -0
- data/frameworks/sproutcore/views/collection.js +1521 -0
- data/frameworks/sproutcore/views/container.js +62 -0
- data/frameworks/sproutcore/views/error_explanation.js +45 -0
- data/frameworks/sproutcore/views/field.js +214 -0
- data/frameworks/sproutcore/views/filter_button.js +29 -0
- data/frameworks/sproutcore/views/form.js +591 -0
- data/frameworks/sproutcore/views/image.js +141 -0
- data/frameworks/sproutcore/views/inline_text_editor.js +96 -0
- data/frameworks/sproutcore/views/label.js +176 -0
- data/frameworks/sproutcore/views/menu_item.js +90 -0
- data/frameworks/sproutcore/views/pagination.js +54 -0
- data/frameworks/sproutcore/views/popup_button.js +86 -0
- data/frameworks/sproutcore/views/popup_menu.js +137 -0
- data/frameworks/sproutcore/views/progress.js +100 -0
- data/frameworks/sproutcore/views/radio_field.js +107 -0
- data/frameworks/sproutcore/views/radio_group.js +48 -0
- data/frameworks/sproutcore/views/segmented.js +80 -0
- data/frameworks/sproutcore/views/select_field.js +272 -0
- data/frameworks/sproutcore/views/spinner.js +11 -0
- data/frameworks/sproutcore/views/tab.js +126 -0
- data/frameworks/sproutcore/views/text_field.js +179 -0
- data/frameworks/sproutcore/views/textarea_field.js +14 -0
- data/frameworks/sproutcore/views/toolbar.js +29 -0
- data/frameworks/sproutcore/views/view.js +1389 -0
- data/frameworks/sproutcore/views/workspace.js +170 -0
- data/generators/client/README +3 -0
- data/generators/client/USAGE +12 -0
- data/generators/client/client_generator.rb +53 -0
- data/generators/client/templates/core.js +19 -0
- data/generators/client/templates/english.lproj/body.css +0 -0
- data/generators/client/templates/english.lproj/body.rhtml +3 -0
- data/generators/client/templates/english.lproj/controls.css +0 -0
- data/generators/client/templates/english.lproj/strings.js +14 -0
- data/generators/client/templates/main.js +37 -0
- data/generators/controller/USAGE +16 -0
- data/generators/controller/controller_generator.rb +51 -0
- data/generators/controller/templates/controller.js +21 -0
- data/generators/controller/templates/test.rhtml +21 -0
- data/generators/framework/README +7 -0
- data/generators/framework/USAGE +12 -0
- data/generators/framework/framework_generator.rb +53 -0
- data/generators/framework/templates/core.js +20 -0
- data/generators/framework/templates/english.lproj/body.css +0 -0
- data/generators/framework/templates/english.lproj/body.rhtml +3 -0
- data/generators/framework/templates/english.lproj/controls.css +0 -0
- data/generators/framework/templates/english.lproj/strings.js +14 -0
- data/generators/language/USAGE +16 -0
- data/generators/language/language_generator.rb +47 -0
- data/generators/language/templates/strings.js +10 -0
- data/generators/model/USAGE +24 -0
- data/generators/model/model_generator.rb +55 -0
- data/generators/model/templates/fixture.js +11 -0
- data/generators/model/templates/model.js +20 -0
- data/generators/model/templates/test.rhtml +21 -0
- data/generators/test/USAGE +16 -0
- data/generators/test/templates/test.rhtml +21 -0
- data/generators/test/test_generator.rb +47 -0
- data/generators/view/USAGE +16 -0
- data/generators/view/templates/test.rhtml +21 -0
- data/generators/view/templates/view.js +20 -0
- data/generators/view/view_generator.rb +51 -0
- data/jsdoc/README.txt +119 -0
- data/jsdoc/app/DocFile.js +137 -0
- data/jsdoc/app/DocTag.js +110 -0
- data/jsdoc/app/Doclet.js +63 -0
- data/jsdoc/app/Dumper.js +143 -0
- data/jsdoc/app/JsDoc.js +103 -0
- data/jsdoc/app/JsHilite.js +45 -0
- data/jsdoc/app/JsIO.js +163 -0
- data/jsdoc/app/JsParse.js +385 -0
- data/jsdoc/app/JsPlate.js +130 -0
- data/jsdoc/app/JsTestrun.js +129 -0
- data/jsdoc/app/JsToke.js +564 -0
- data/jsdoc/app/Symbol.js +298 -0
- data/jsdoc/app/Transformer.js +14 -0
- data/jsdoc/app/Util.js +97 -0
- data/jsdoc/app/js.jar +0 -0
- data/jsdoc/app/run.js +144 -0
- data/jsdoc/plugins/min.js +316 -0
- data/jsdoc/plugins/strip.js +20 -0
- data/jsdoc/templates/sproutcore/class.tmpl +438 -0
- data/jsdoc/templates/sproutcore/default.css +241 -0
- data/jsdoc/templates/sproutcore/index.html +13 -0
- data/jsdoc/templates/sproutcore/index.tmpl +21 -0
- data/jsdoc/templates/sproutcore/prototype.js +4186 -0
- data/jsdoc/templates/sproutcore/publish.js +236 -0
- data/jsdoc/templates/sproutcore/splash.html +7 -0
- data/lib/sproutcore/build_tools/html_builder.rb +88 -0
- data/lib/sproutcore/build_tools/resource_builder.rb +194 -0
- data/lib/sproutcore/build_tools.rb +44 -0
- data/lib/sproutcore/bundle.rb +517 -0
- data/lib/sproutcore/bundle_manifest.rb +397 -0
- data/lib/sproutcore/generator_helper.rb +170 -0
- data/lib/sproutcore/helpers/capture_helper.rb +42 -0
- data/lib/sproutcore/helpers/static_helper.rb +80 -0
- data/lib/sproutcore/helpers/tag_helper.rb +110 -0
- data/lib/sproutcore/helpers/text_helper.rb +336 -0
- data/lib/sproutcore/helpers.rb +3 -0
- data/lib/sproutcore/jsdoc.rb +40 -0
- data/lib/sproutcore/jsmin.rb +247 -0
- data/lib/sproutcore/library.rb +258 -0
- data/lib/sproutcore/merb/bundle_controller.rb +179 -0
- data/lib/sproutcore/merb/router.rb +43 -0
- data/lib/sproutcore/merb.rb +27 -0
- data/lib/sproutcore/version.rb +9 -0
- data/lib/sproutcore/view_helpers/button_views.rb +302 -0
- data/lib/sproutcore/view_helpers/core_views.rb +284 -0
- data/lib/sproutcore/view_helpers/form_views.rb +258 -0
- data/lib/sproutcore/view_helpers/menu_views.rb +94 -0
- data/lib/sproutcore/view_helpers.rb +628 -0
- data/lib/sproutcore.rb +30 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/sproutcore_spec.rb +11 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/rspec.rake +21 -0
- data/tasks/website.rake +17 -0
- metadata +365 -0
@@ -0,0 +1,385 @@
|
|
1
|
+
/**
|
2
|
+
* @fileOverview
|
3
|
+
* @name JsParse
|
4
|
+
* @author Michael Mathews micmath@gmail.com
|
5
|
+
* @url $HeadURL: https://jsdoc-toolkit.googlecode.com/svn/tags/jsdoc_toolkit-1.4.0b/app/JsParse.js $
|
6
|
+
* @revision $Id: JsParse.js 329 2007-11-13 00:48:15Z 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
|
+
* @class Find objects in tokenized JavaScript source code.
|
13
|
+
* @constructor
|
14
|
+
* @author Michael Mathews <a href="mailto:micmath@gmail.com">micmath@gmail.com</a>
|
15
|
+
*/
|
16
|
+
function JsParse() {};
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Populate the symbols array with symbols found in the
|
20
|
+
* given token stream.
|
21
|
+
* @param {TokenStream} tokenStream
|
22
|
+
*/
|
23
|
+
JsParse.prototype.parse = function(tokenStream) {
|
24
|
+
/**
|
25
|
+
* All symbols found in the tokenStream.
|
26
|
+
* @type Symbol[]
|
27
|
+
*/
|
28
|
+
this.symbols = [];
|
29
|
+
|
30
|
+
/**
|
31
|
+
* Overview found in the tokenStream.
|
32
|
+
* @type Symbol
|
33
|
+
*/
|
34
|
+
this.overview = null;
|
35
|
+
|
36
|
+
while(tokenStream.next()) {
|
37
|
+
if (this._findDocComment(tokenStream)) continue;
|
38
|
+
if (this._findFunction(tokenStream)) continue;
|
39
|
+
if (this._findVariable(tokenStream)) continue;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Try to find a JsDoc comment in the tokenStream.
|
45
|
+
* @param {TokenStream} ts
|
46
|
+
* @return {boolean} Was a JsDoc comment found?
|
47
|
+
*/
|
48
|
+
JsParse.prototype._findDocComment = function(ts) {
|
49
|
+
if (ts.look().is("JSDOC")) {
|
50
|
+
|
51
|
+
ts.look().data = ts.look().data.replace(/@namespace\b/, "@static\n@class");
|
52
|
+
|
53
|
+
var doc = ts.look().data;
|
54
|
+
|
55
|
+
|
56
|
+
if (doc.indexOf("/**#") == 0) {
|
57
|
+
new Symbol("", [], "META", doc);
|
58
|
+
delete ts.tokens[ts.cursor];
|
59
|
+
return true;
|
60
|
+
}
|
61
|
+
else if (/@(projectdescription|(file)?overview)\b/i.test(doc)) {
|
62
|
+
this.overview = new Symbol("", [], "FILE", doc);
|
63
|
+
delete ts.tokens[ts.cursor];
|
64
|
+
return true;
|
65
|
+
}
|
66
|
+
else if (/@name\s+([a-z0-9_$.]+)\s*/i.test(doc)) {
|
67
|
+
this.symbols.push(new Symbol(RegExp.$1, [], SYM.VIRTUAL, doc));
|
68
|
+
delete ts.tokens[ts.cursor];
|
69
|
+
return true;
|
70
|
+
}
|
71
|
+
else if (/@scope\s+([a-z0-9_$.]+)\s*/i.test(doc)) {
|
72
|
+
var scope = RegExp.$1;
|
73
|
+
if (scope) {
|
74
|
+
scope = scope.replace(/\.prototype\b/, "/");
|
75
|
+
this._onObLiteral(scope, new TokenStream(ts.balance("LEFT_CURLY")));
|
76
|
+
return true;
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
return false;
|
81
|
+
}
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Try to find a function definition in the tokenStream
|
85
|
+
* @param {TokenStream} ts
|
86
|
+
* @return {boolean} Was a function definition found?
|
87
|
+
*/
|
88
|
+
JsParse.prototype._findFunction = function(ts) {
|
89
|
+
if (ts.look().is("NAME")) {
|
90
|
+
var name = ts.look().data;
|
91
|
+
var doc = "";
|
92
|
+
var isa = null;
|
93
|
+
var body = "";
|
94
|
+
var paramTokens = [];
|
95
|
+
var params = [];
|
96
|
+
|
97
|
+
// like function foo()
|
98
|
+
if (ts.look(-1).is("FUNCTION")) {
|
99
|
+
isa = SYM.FUNCTION;
|
100
|
+
|
101
|
+
if (ts.look(-2).is("JSDOC")) {
|
102
|
+
doc = ts.look(-2).data;
|
103
|
+
}
|
104
|
+
paramTokens = ts.balance("LEFT_PAREN");
|
105
|
+
body = ts.balance("LEFT_CURLY");
|
106
|
+
}
|
107
|
+
|
108
|
+
// like var foo = function()
|
109
|
+
else if (ts.look(1).is("ASSIGN") && ts.look(2).is("FUNCTION")) {
|
110
|
+
isa = SYM.FUNCTION;
|
111
|
+
|
112
|
+
if (ts.look(-1).is("VAR") && ts.look(-2).is("JSDOC")) {
|
113
|
+
doc = ts.look(-2).data;
|
114
|
+
}
|
115
|
+
else if (ts.look(-1).is("JSDOC")) {
|
116
|
+
doc = ts.look(-1).data;
|
117
|
+
}
|
118
|
+
paramTokens = ts.balance("LEFT_PAREN");
|
119
|
+
body = ts.balance("LEFT_CURLY");
|
120
|
+
|
121
|
+
// like foo = function(n) {return n}(42)
|
122
|
+
if (ts.look(1).is("LEFT_PAREN")) {
|
123
|
+
isa = SYM.OBJECT;
|
124
|
+
|
125
|
+
ts.balance("LEFT_PAREN");
|
126
|
+
if (doc) { // we only keep these if they're documented
|
127
|
+
name = name.replace(/\.prototype\.?/, "/");
|
128
|
+
|
129
|
+
if (!/\/$/.test(name)) { // assigning to prototype of already existing symbol
|
130
|
+
this.symbols.push(new Symbol(name, [], isa, doc));
|
131
|
+
}
|
132
|
+
}
|
133
|
+
this._onFnBody(name, new TokenStream(body));
|
134
|
+
return true;
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
// like var foo = new function()
|
139
|
+
else if (ts.look(1).is("ASSIGN") && ts.look(2).is("NEW") && ts.look(3).is("FUNCTION")) {
|
140
|
+
isa = SYM.OBJECT;
|
141
|
+
|
142
|
+
if (ts.look(-1).is("VAR") && ts.look(-2).is("JSDOC")) {
|
143
|
+
doc = ts.look(-2).data;
|
144
|
+
}
|
145
|
+
else if (ts.look(-1).is("JSDOC")) {
|
146
|
+
doc = ts.look(-1).data;
|
147
|
+
}
|
148
|
+
|
149
|
+
paramTokens = ts.balance("LEFT_PAREN");
|
150
|
+
body = ts.balance("LEFT_CURLY");
|
151
|
+
if (doc) { // we only keep these if they're documented
|
152
|
+
name = name.replace(/\.prototype\.?/, "/");
|
153
|
+
|
154
|
+
if (!/\/$/.test(name)) { // assigning to prototype of already existing symbol
|
155
|
+
this.symbols.push(new Symbol(name, [], isa, doc));
|
156
|
+
}
|
157
|
+
}
|
158
|
+
this._onFnBody(name, new TokenStream(body));
|
159
|
+
return true;
|
160
|
+
}
|
161
|
+
|
162
|
+
if (isa && name) {
|
163
|
+
if (isa == SYM.FUNCTION) {
|
164
|
+
for (var i = 0; i < paramTokens.length; i++) {
|
165
|
+
if (paramTokens[i].is("NAME"))
|
166
|
+
params.push(paramTokens[i].data);
|
167
|
+
}
|
168
|
+
}
|
169
|
+
|
170
|
+
// like Foo.bar.prototype.baz = function() {}
|
171
|
+
var ns = name;
|
172
|
+
if (name.indexOf(".prototype") > 0) {
|
173
|
+
isa = SYM.FUNCTION;
|
174
|
+
name = name.replace(/\.prototype\.?/, "/");
|
175
|
+
}
|
176
|
+
|
177
|
+
this.symbols.push(new Symbol(name, params, isa, doc));
|
178
|
+
|
179
|
+
if (body) {
|
180
|
+
if (ns.indexOf(".prototype") > 0) {
|
181
|
+
if (/@constructor\b/.test(doc)) {
|
182
|
+
ns = ns.replace(/\.prototype\.?/, "/");
|
183
|
+
}
|
184
|
+
else {
|
185
|
+
ns = ns.replace(/\.prototype\.[^.]+$/, "/");
|
186
|
+
}
|
187
|
+
}
|
188
|
+
this._onFnBody(ns, new TokenStream(body));
|
189
|
+
}
|
190
|
+
return true;
|
191
|
+
}
|
192
|
+
}
|
193
|
+
return false;
|
194
|
+
}
|
195
|
+
|
196
|
+
/**
|
197
|
+
* Try to find a variable definition in the tokenStream
|
198
|
+
* @param {TokenStream} ts
|
199
|
+
* @return {boolean} Was a variable definition found?
|
200
|
+
*/
|
201
|
+
JsParse.prototype._findVariable = function(ts) {
|
202
|
+
if (ts.look().is("NAME") && ts.look(1).is("ASSIGN")) {
|
203
|
+
// like var foo = 1
|
204
|
+
var name = ts.look().data;
|
205
|
+
isa = SYM.OBJECT;
|
206
|
+
|
207
|
+
var doc;
|
208
|
+
if (ts.look(-1).is("JSDOC")) doc = ts.look(-1).data;
|
209
|
+
else if (ts.look(-1).is("VAR") && ts.look(-2).is("JSDOC")) doc = ts.look(-2).data;
|
210
|
+
name = name.replace(/\.prototype\.?/, "/");
|
211
|
+
|
212
|
+
if (doc) { // we only keep these if they're documented
|
213
|
+
if (!/\/$/.test(name)) { // assigning to prototype of already existing symbol
|
214
|
+
this.symbols.push(new Symbol(name, [], isa, doc));
|
215
|
+
}
|
216
|
+
if (/@class\b/i.test(doc)) {
|
217
|
+
name = name +"/";
|
218
|
+
}
|
219
|
+
}
|
220
|
+
|
221
|
+
// like foo = {
|
222
|
+
if (ts.look(2).is("LEFT_CURLY")) {
|
223
|
+
this._onObLiteral(name, new TokenStream(ts.balance("LEFT_CURLY")));
|
224
|
+
}
|
225
|
+
return true;
|
226
|
+
}
|
227
|
+
return false;
|
228
|
+
}
|
229
|
+
|
230
|
+
/**
|
231
|
+
* Handle sub-parsing of the content within an object literal.
|
232
|
+
* @private
|
233
|
+
* @param {String} nspace The name attached to this object.
|
234
|
+
* @param {TokenStream} ts The content of the object literal.
|
235
|
+
*/
|
236
|
+
JsParse.prototype._onObLiteral = function(nspace, ts) {
|
237
|
+
while (ts.next()) {
|
238
|
+
if (this._findDocComment(ts)) {
|
239
|
+
|
240
|
+
}
|
241
|
+
else if (ts.look().is("NAME") && ts.look(1).is("COLON")) {
|
242
|
+
var name = nspace+((nspace.charAt(nspace.length-1)=="/")?"":".")+ts.look().data;
|
243
|
+
|
244
|
+
// like foo: function
|
245
|
+
if (ts.look(2).is("FUNCTION")) {
|
246
|
+
var isa = SYM.FUNCTION;
|
247
|
+
var doc = "";
|
248
|
+
|
249
|
+
if (ts.look(-1).is("JSDOC")) doc = ts.look(-1).data;
|
250
|
+
|
251
|
+
var paramTokens = ts.balance("LEFT_PAREN");
|
252
|
+
var params = [];
|
253
|
+
for (var i = 0; i < paramTokens.length; i++) {
|
254
|
+
if (paramTokens[i].is("NAME"))
|
255
|
+
params.push(paramTokens[i].data);
|
256
|
+
}
|
257
|
+
|
258
|
+
var body = ts.balance("LEFT_CURLY");
|
259
|
+
|
260
|
+
// like foo: function(n) {return n}(42)
|
261
|
+
if (ts.look(1).is("LEFT_PAREN")) {
|
262
|
+
isa = SYM.OBJECT;
|
263
|
+
|
264
|
+
ts.balance("LEFT_PAREN");
|
265
|
+
//if (doc) { // we only keep these if they're documented
|
266
|
+
//name = name.replace(/\.prototype\.?/, "/");
|
267
|
+
|
268
|
+
//if (!/\/$/.test(name)) { // assigning to prototype of already existing symbol
|
269
|
+
// this.symbols.push(new Symbol(name, [], isa, doc));
|
270
|
+
//}
|
271
|
+
//}
|
272
|
+
//this._onFnBody(name, new TokenStream(body));
|
273
|
+
//return true;
|
274
|
+
}
|
275
|
+
|
276
|
+
this.symbols.push(new Symbol(name, params, isa, doc));
|
277
|
+
|
278
|
+
// find methods in the body of this function
|
279
|
+
this._onFnBody(name, new TokenStream(body));
|
280
|
+
}
|
281
|
+
// like foo: {...}
|
282
|
+
else if (ts.look(2).is("LEFT_CURLY")) { // another nested object literal
|
283
|
+
if (ts.look(-1).is("JSDOC")) {
|
284
|
+
var isa = SYM.OBJECT;
|
285
|
+
var doc = ts.look(-1).data;
|
286
|
+
|
287
|
+
this.symbols.push(new Symbol(name, [], isa, doc));
|
288
|
+
}
|
289
|
+
|
290
|
+
this._onObLiteral(name, new TokenStream(ts.balance("LEFT_CURLY"))); // recursive
|
291
|
+
}
|
292
|
+
else { // like foo: 1, or foo: "one"
|
293
|
+
if (ts.look(-1).is("JSDOC")) { // we only grab these if they are documented
|
294
|
+
var isa = SYM.OBJECT;
|
295
|
+
var doc = ts.look(-1).data;
|
296
|
+
|
297
|
+
this.symbols.push(new Symbol(name, [], isa, doc));
|
298
|
+
}
|
299
|
+
|
300
|
+
while (!ts.look().is("COMMA")) { // skip to end of RH value ignoring things like bar({blah, blah})
|
301
|
+
if (ts.look().is("LEFT_PAREN")) ts.balance("LEFT_PAREN");
|
302
|
+
else if (ts.look().is("LEFT_CURLY")) ts.balance("LEFT_CURLY");
|
303
|
+
else if (!ts.next()) break;
|
304
|
+
}
|
305
|
+
}
|
306
|
+
}
|
307
|
+
}
|
308
|
+
}
|
309
|
+
|
310
|
+
/**
|
311
|
+
* Handle sub-parsing of the content within a function body.
|
312
|
+
* @private
|
313
|
+
* @param {String} nspace The name attached to this function.
|
314
|
+
* @param {TokenStream} fs The content of the function body.
|
315
|
+
*/
|
316
|
+
JsParse.prototype._onFnBody = function(nspace, fs) {
|
317
|
+
while (fs.look()) {
|
318
|
+
if (this._findDocComment(fs)) {
|
319
|
+
|
320
|
+
}
|
321
|
+
else if (fs.look().is("NAME") && fs.look(1).is("ASSIGN")) {
|
322
|
+
var name = fs.look().data;
|
323
|
+
|
324
|
+
// like this.foo =
|
325
|
+
if (name.indexOf("this.") == 0) {
|
326
|
+
// like this.foo = function
|
327
|
+
if (fs.look(2).is("FUNCTION")) {
|
328
|
+
var isa = SYM.FUNCTION;
|
329
|
+
var doc = (fs.look(-1).is("JSDOC"))? fs.look(-1).data : "";
|
330
|
+
name = name.replace(/^this\./, (nspace+"/").replace("//", "/"))
|
331
|
+
|
332
|
+
var paramTokens = fs.balance("LEFT_PAREN");
|
333
|
+
var params = [];
|
334
|
+
for (var i = 0; i < paramTokens.length; i++) {
|
335
|
+
if (paramTokens[i].is("NAME")) params.push(paramTokens[i].data);
|
336
|
+
}
|
337
|
+
|
338
|
+
body = fs.balance("LEFT_CURLY");
|
339
|
+
|
340
|
+
// like this.foo = function(n) {return n}(42)
|
341
|
+
if (fs.look(1).is("LEFT_PAREN")) { // false alarm, it's not really a named function definition
|
342
|
+
isa = SYM.OBJECT;
|
343
|
+
fs.balance("LEFT_PAREN");
|
344
|
+
if (doc) { // we only grab these if they are documented
|
345
|
+
this.symbols.push(
|
346
|
+
new Symbol(name, [], isa, doc)
|
347
|
+
);
|
348
|
+
}
|
349
|
+
break;
|
350
|
+
}
|
351
|
+
|
352
|
+
this.symbols.push(
|
353
|
+
new Symbol(name, params, isa, doc)
|
354
|
+
);
|
355
|
+
|
356
|
+
if (body) {
|
357
|
+
this._onFnBody(name, new TokenStream(body)); // recursive
|
358
|
+
}
|
359
|
+
}
|
360
|
+
else {
|
361
|
+
var isa = SYM.OBJECT;
|
362
|
+
var doc = (fs.look(-1).is("JSDOC"))? fs.look(-1).data : "";
|
363
|
+
name = name.replace(/^this\./, (nspace+"/").replace("//", "/"))
|
364
|
+
|
365
|
+
if (doc) {
|
366
|
+
this.symbols.push(
|
367
|
+
new Symbol(name, [], isa, doc)
|
368
|
+
);
|
369
|
+
}
|
370
|
+
|
371
|
+
// like this.foo = { ... }
|
372
|
+
if (fs.look(2).is("LEFT_CURLY")) {
|
373
|
+
var literal = fs.balance("LEFT_CURLY");
|
374
|
+
this._onObLiteral(name, new TokenStream(literal));
|
375
|
+
}
|
376
|
+
}
|
377
|
+
}
|
378
|
+
// like <thisfunction>.prototype.foo =
|
379
|
+
else if (name.indexOf(nspace+".prototype.") == 0) {
|
380
|
+
this._findFunction(fs);
|
381
|
+
}
|
382
|
+
}
|
383
|
+
if (!fs.next()) break;
|
384
|
+
}
|
385
|
+
}
|
@@ -0,0 +1,130 @@
|
|
1
|
+
/**
|
2
|
+
* @fileOverview
|
3
|
+
* @name JsPlate
|
4
|
+
* @author Michael Mathews micmath@gmail.com
|
5
|
+
* @url $HeadURL: https://jsdoc-toolkit.googlecode.com/svn/tags/jsdoc_toolkit-1.4.0b/app/JsPlate.js $
|
6
|
+
* @revision $Id: JsPlate.js 213 2007-08-22 10:21:50Z 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
|
+
/**
|
13
|
+
* @class A lightweight template engine for JavaScript.
|
14
|
+
* @constructor
|
15
|
+
* @author Michael Mathews <a href="mailto:micmath@gmail.com">micmath@gmail.com</a>
|
16
|
+
* @param {string} template
|
17
|
+
*/
|
18
|
+
JsPlate = function(template) {
|
19
|
+
this.template = IO.readFile(template);
|
20
|
+
|
21
|
+
this.code = "";
|
22
|
+
this.parse();
|
23
|
+
}
|
24
|
+
|
25
|
+
/** Converts a template into evalable code. */
|
26
|
+
JsPlate.prototype.parse = function() {
|
27
|
+
this.template = this.template.replace(/\{#[\s\S]+?#\}/gi, "");
|
28
|
+
this.code = "var output=``"+this.template;
|
29
|
+
|
30
|
+
this.code = this.code.replace(
|
31
|
+
/<for each="(.+?)" in="(.+?)"(?: sortby="(.+?)")?>/g,
|
32
|
+
function (match, eachName, inName, sortby) {
|
33
|
+
if (!sortby) sortby = "asis";
|
34
|
+
|
35
|
+
return "``; var $"+eachName+"_keys = "+sortby+"("+inName+"); for(var $"+eachName+"_i = 0; $"+eachName+"_i < $"+eachName+"_keys.length; $"+eachName+"_i++) { var $"+eachName+"_last = ($"+eachName+"_i == $"+eachName+"_keys.length-1); var $"+eachName+"_key = $"+eachName+"_keys[$"+eachName+"_i]; var "+eachName+" = "+inName+"[$"+eachName+"_key]; output+=``";
|
36
|
+
}
|
37
|
+
);
|
38
|
+
this.code = this.code.replace(/<if test="(.+?)">/g, "``; if ($1) { output+=``");
|
39
|
+
this.code = this.code.replace(/<\/(if|for)>/g, "``; }; output+=``");
|
40
|
+
this.code = this.code.replace(
|
41
|
+
/\{\+\s*([\s\S]+?)\s*\+\}/gi,
|
42
|
+
function (match, code) {
|
43
|
+
code = code.replace(/"/g, "``"); // prevent qoute-escaping of inline code
|
44
|
+
code = code.replace(/(\r?\n)/g, " ");
|
45
|
+
return "``+"+code+"+``";
|
46
|
+
}
|
47
|
+
);
|
48
|
+
this.code = this.code.replace(
|
49
|
+
/\{!\s*([\s\S]+?)\s*!\}/gi,
|
50
|
+
function (match, code) {
|
51
|
+
code = code.replace(/"/g, "``"); // prevent qoute-escaping of inline code
|
52
|
+
code = code.replace(/(\r?\n)/g, " ");
|
53
|
+
return "``; "+code+"; output+=``";
|
54
|
+
}
|
55
|
+
);
|
56
|
+
this.code = this.code+"``;";
|
57
|
+
|
58
|
+
this.code = this.code.replace(/(\r?\n)/g, "\\n");
|
59
|
+
this.code = this.code.replace(/"/g, "\\\"");
|
60
|
+
this.code = this.code.replace(/``/g, "\"");
|
61
|
+
}
|
62
|
+
|
63
|
+
/**
|
64
|
+
* @private
|
65
|
+
*/
|
66
|
+
JsPlate.prototype.toCode = function() {
|
67
|
+
return this.code;
|
68
|
+
}
|
69
|
+
|
70
|
+
/**
|
71
|
+
* @private
|
72
|
+
* @static
|
73
|
+
* @memberOf JsPlate
|
74
|
+
*/
|
75
|
+
JsPlate.keys = function(obj) {
|
76
|
+
var keys = [];
|
77
|
+
if (obj.constructor.toString().indexOf("Array") > -1) {
|
78
|
+
for (var i = 0; i < obj.length; i++) keys.push(i);
|
79
|
+
}
|
80
|
+
else {
|
81
|
+
for (var i in obj) { keys.push(i); }
|
82
|
+
}
|
83
|
+
return keys.sort();
|
84
|
+
};
|
85
|
+
|
86
|
+
/**
|
87
|
+
* @private
|
88
|
+
* @static
|
89
|
+
* @memberOf JsPlate
|
90
|
+
*/
|
91
|
+
JsPlate.values = function(obj) {
|
92
|
+
var values = [];
|
93
|
+
if (obj.constructor.toString().indexOf("Array") > -1) {
|
94
|
+
for (var i = 0; i < obj.length; i++) values.push(obj[i]);
|
95
|
+
}
|
96
|
+
else {
|
97
|
+
for (var i in obj) { values.push(obj[i]); }
|
98
|
+
}
|
99
|
+
return values.sort();
|
100
|
+
};
|
101
|
+
|
102
|
+
/**
|
103
|
+
* @private
|
104
|
+
* @static
|
105
|
+
* @memberOf JsPlate
|
106
|
+
*/
|
107
|
+
JsPlate.asis = function(obj) {
|
108
|
+
var keys = [];
|
109
|
+
if (obj.constructor.toString().indexOf("Array") > -1) {
|
110
|
+
for (var i = 0; i < obj.length; i++) keys.push(i);
|
111
|
+
}
|
112
|
+
else {
|
113
|
+
for (var i in obj) { keys.push(i); }
|
114
|
+
}
|
115
|
+
return keys;
|
116
|
+
};
|
117
|
+
|
118
|
+
/**
|
119
|
+
* Return the output. This must be called after parse()
|
120
|
+
* @param {object} data What shall represent the "data" in your template.
|
121
|
+
* @return {string}
|
122
|
+
*/
|
123
|
+
JsPlate.prototype.process = function(data) {
|
124
|
+
var keys = JsPlate.keys;
|
125
|
+
var values = JsPlate.values;
|
126
|
+
var asis = JsPlate.asis;
|
127
|
+
eval(this.code);
|
128
|
+
return output;
|
129
|
+
//print(this.code)
|
130
|
+
}
|
@@ -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-1.4.0b/app/JsTestrun.js $
|
6
|
+
* @revision $Id: JsTestrun.js 292 2007-10-25 22:17:25Z 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
|
+
}
|