ninjs 0.13.8 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/bin/ninjs +2 -1
- data/lib/ninjs/command.rb +1 -1
- data/lib/ninjs/generator.rb +14 -10
- data/lib/ninjs/project.rb +7 -4
- data/ninjs.gemspec +20 -7
- data/repository/ninjs/core/application.js +24 -43
- data/repository/ninjs/core/dom.js +139 -0
- data/repository/ninjs/core/existence.js +121 -277
- data/repository/ninjs/core/extend.js +35 -77
- data/repository/ninjs/core/module.js +101 -116
- data/repository/ninjs/core/nin.js +7 -4
- data/repository/ninjs/tests/application.test.js +24 -0
- data/repository/ninjs/tests/array.utilities.test.js +55 -0
- data/repository/ninjs/tests/existence.test.js +64 -0
- data/repository/ninjs/tests/extension.test.js +38 -0
- data/repository/ninjs/tests/index.html +11 -5
- data/repository/ninjs/tests/module.test.js +75 -0
- data/repository/ninjs/tests/qspec.js +26 -0
- data/repository/ninjs/tests/{ninjs.utilities.test.js → string.utilities.test.js} +14 -66
- data/spec/cli_spec.rb +159 -0
- data/spec/command_spec.rb +226 -2
- data/spec/fixtures/compressed.myapp.js +40 -20
- data/spec/fixtures/myapp.initial.js +383 -488
- data/spec/fixtures/myapp.js +379 -484
- data/spec/fixtures/mymodule.alias.module.js +10 -0
- data/spec/fixtures/mymodule.dependencies.module.js +13 -0
- data/spec/fixtures/mymodule.elements.js +5 -0
- data/spec/fixtures/mymodule.model.js +3 -0
- data/spec/fixtures/mymodule.module.js +10 -0
- data/spec/fixtures/nin.js +428 -0
- data/spec/generator_spec.rb +58 -10
- data/spec/project_spec.rb +11 -7
- metadata +59 -9
- data/repository/ninjs/tests/ninjs.test.js +0 -188
- data/repository/ninjs/tests/qunit/qunit.css +0 -197
- data/repository/ninjs/tests/qunit/qunit.js +0 -1415
@@ -0,0 +1,428 @@
|
|
1
|
+
(function() {
|
2
|
+
if (window.is_defined === undefined) {
|
3
|
+
window.is_defined = function(suspect) {
|
4
|
+
return ((suspect === undefined) || (suspect === null)) ? false : true;
|
5
|
+
};
|
6
|
+
}
|
7
|
+
|
8
|
+
if (!is_defined(window.is_undefined)) {
|
9
|
+
window.is_undefined = function(suspect) {
|
10
|
+
return (suspect === undefined) ? true : false;
|
11
|
+
};
|
12
|
+
}
|
13
|
+
|
14
|
+
if (is_undefined(window.is_typeof)) {
|
15
|
+
window.is_typeof = function(type, suspect) {
|
16
|
+
if (is_undefined(type)) {
|
17
|
+
throw new SyntaxError("is_typeof(Type, suspect): type is undefined");
|
18
|
+
}
|
19
|
+
if (is_undefined(suspect)) {
|
20
|
+
throw new SyntaxError("is_typeof(Type, suspect): suspect is undefined");
|
21
|
+
}
|
22
|
+
|
23
|
+
return (suspect.constructor == type) ? true : false;
|
24
|
+
};
|
25
|
+
}
|
26
|
+
|
27
|
+
if (is_undefined(window.is_numeric)) {
|
28
|
+
window.is_numeric = function(suspect) {
|
29
|
+
if(is_typeof(Number, suspect)) {
|
30
|
+
return true;
|
31
|
+
}
|
32
|
+
else {
|
33
|
+
var pattern = /^-?\d+(?:\.\d*)?(?:e[+\-]?\d+)?$/i;
|
34
|
+
return pattern.test(suspect);
|
35
|
+
}
|
36
|
+
};
|
37
|
+
}
|
38
|
+
|
39
|
+
if (is_undefined(window.is_string)) {
|
40
|
+
window.is_string = function(suspect) {
|
41
|
+
return is_typeof(String, suspect);
|
42
|
+
};
|
43
|
+
}
|
44
|
+
|
45
|
+
if (is_undefined(window.is_array)) {
|
46
|
+
window.is_array = function(suspect) {
|
47
|
+
return is_typeof(Array, suspect);
|
48
|
+
};
|
49
|
+
}
|
50
|
+
|
51
|
+
if (is_undefined(window.is_number)) {
|
52
|
+
window.is_number = function(suspect) {
|
53
|
+
return is_typeof(Number, suspect);
|
54
|
+
};
|
55
|
+
}
|
56
|
+
|
57
|
+
if (is_undefined(window.is_date)) {
|
58
|
+
window.is_date = function(suspect) {
|
59
|
+
return is_typeof(Date, suspect);
|
60
|
+
};
|
61
|
+
}
|
62
|
+
|
63
|
+
if (is_undefined(window.is_bool)) {
|
64
|
+
window.is_bool = function(suspect) {
|
65
|
+
return is_typeof(Boolean, suspect);
|
66
|
+
};
|
67
|
+
}
|
68
|
+
|
69
|
+
if (is_undefined(window.is_regex)) {
|
70
|
+
window.is_regex = function(suspect) {
|
71
|
+
return is_typeof(RegExp, suspect);
|
72
|
+
};
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
if (is_undefined(window.is_empty)) {
|
77
|
+
window.is_empty = function(suspect) {
|
78
|
+
return suspect.length === 0;
|
79
|
+
};
|
80
|
+
}
|
81
|
+
|
82
|
+
if (is_undefined(window.is_not_empty)) {
|
83
|
+
window.is_not_empty = function(suspect) {
|
84
|
+
return suspect.length >= 1;
|
85
|
+
};
|
86
|
+
}
|
87
|
+
|
88
|
+
if (is_undefined(Function.prototype['method'])) {
|
89
|
+
Function.prototype.method = function(name, func) {
|
90
|
+
if (is_undefined(name)) {
|
91
|
+
throw new SyntaxError("Object.method(name, func): name is undefined");
|
92
|
+
}
|
93
|
+
|
94
|
+
if (is_undefined(func)) {
|
95
|
+
throw new SyntaxError("Object.method(name, func): func is undefined");
|
96
|
+
}
|
97
|
+
|
98
|
+
if (is_undefined(this.prototype[name])) {
|
99
|
+
this.prototype[name] = func;
|
100
|
+
return this;
|
101
|
+
}
|
102
|
+
};
|
103
|
+
}
|
104
|
+
|
105
|
+
if (is_undefined(window.unless)) {
|
106
|
+
window.unless = function(expression, callback, fallback) {
|
107
|
+
if (is_undefined(expression)) {
|
108
|
+
throw new SyntaxError("unless(expression, callback[, fallback]): expression is undefined");
|
109
|
+
}
|
110
|
+
|
111
|
+
if (is_undefined(callback)) {
|
112
|
+
throw new SyntaxError("unless(expression, callback[, fallback]): callback is undefined");
|
113
|
+
}
|
114
|
+
|
115
|
+
if (!expression) {
|
116
|
+
callback.call(this);
|
117
|
+
}
|
118
|
+
else if (is_defined(fallback)) {
|
119
|
+
fallback.call(this);
|
120
|
+
}
|
121
|
+
};
|
122
|
+
}
|
123
|
+
if (is_undefined(Function.prototype['method'])) {
|
124
|
+
Function.prototype.method = function(name, func) {
|
125
|
+
if (is_undefined(name)) {
|
126
|
+
throw new SyntaxError("Object.method(name, func): name is undefined");
|
127
|
+
}
|
128
|
+
|
129
|
+
if (is_undefined(func)) {
|
130
|
+
throw new SyntaxError("Object.method(name, func): func is undefined");
|
131
|
+
}
|
132
|
+
|
133
|
+
if (is_undefined(this.prototype[name])) {
|
134
|
+
this.prototype[name] = func;
|
135
|
+
return this;
|
136
|
+
}
|
137
|
+
};
|
138
|
+
}
|
139
|
+
|
140
|
+
if (is_undefined(window.unless)) {
|
141
|
+
window.unless = function(expression, callback, fallback) {
|
142
|
+
if (is_undefined(expression)) {
|
143
|
+
throw new SyntaxError("unless(expression, callback[, fallback]): expression is undefined");
|
144
|
+
}
|
145
|
+
|
146
|
+
if (is_undefined(callback)) {
|
147
|
+
throw new SyntaxError("unless(expression, callback[, fallback]): callback is undefined");
|
148
|
+
}
|
149
|
+
|
150
|
+
if (!expression) {
|
151
|
+
callback.call(this);
|
152
|
+
}
|
153
|
+
else if (is_defined(fallback)) {
|
154
|
+
fallback.call(this);
|
155
|
+
}
|
156
|
+
};
|
157
|
+
}
|
158
|
+
var userAgent = navigator.userAgent;
|
159
|
+
var browser = {
|
160
|
+
agent: userAgent,
|
161
|
+
mozilla: (/mozilla/.test(userAgent.toLowerCase())) && (!/(compatible|webkit)/.test(userAgent.toLowerCase())),
|
162
|
+
webkit: /webkit/.test(userAgent.toLowerCase()),
|
163
|
+
firefox: /firefox/.test(userAgent.toLowerCase()),
|
164
|
+
chrome: /webkit/.test(userAgent.toLowerCase()),
|
165
|
+
safari: /safari/.test(userAgent.toLowerCase()),
|
166
|
+
opera: /opera/.test(userAgent.toLowerCase()),
|
167
|
+
msie: (/msie/.test(userAgent.toLowerCase())) && (!/opera/.test( userAgent.toLowerCase() ))
|
168
|
+
};
|
169
|
+
|
170
|
+
var readyBound = false;
|
171
|
+
var isReady = false;
|
172
|
+
var readyList = [];
|
173
|
+
|
174
|
+
function domReady() {
|
175
|
+
if (!isReady) {
|
176
|
+
isReady = true;
|
177
|
+
if (readyList) {
|
178
|
+
for(var fn = 0; fn < readyList.length; fn++) {
|
179
|
+
readyList[fn].call(window, []);
|
180
|
+
}
|
181
|
+
readyList = [];
|
182
|
+
}
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
function addLoadEvent(func) {
|
187
|
+
var oldonload = window.onload;
|
188
|
+
if (typeof window.onload != 'function') {
|
189
|
+
window.onload = func;
|
190
|
+
} else {
|
191
|
+
window.onload = function() {
|
192
|
+
if (oldonload) {
|
193
|
+
oldonload();
|
194
|
+
}
|
195
|
+
func();
|
196
|
+
}
|
197
|
+
}
|
198
|
+
};
|
199
|
+
|
200
|
+
function bindReady() {
|
201
|
+
if (readyBound) {
|
202
|
+
return;
|
203
|
+
}
|
204
|
+
|
205
|
+
readyBound = true;
|
206
|
+
|
207
|
+
if (document.addEventListener && !browser.opera) {
|
208
|
+
document.addEventListener("DOMContentLoaded", domReady, false);
|
209
|
+
}
|
210
|
+
|
211
|
+
if (browser.msie && window == top) (function(){
|
212
|
+
if (isReady) return;
|
213
|
+
try {
|
214
|
+
document.documentElement.doScroll("left");
|
215
|
+
} catch(error) {
|
216
|
+
setTimeout(arguments.callee, 0);
|
217
|
+
return;
|
218
|
+
}
|
219
|
+
domReady();
|
220
|
+
})();
|
221
|
+
|
222
|
+
if (browser.opera) {
|
223
|
+
document.addEventListener( "DOMContentLoaded", function () {
|
224
|
+
if (isReady) return;
|
225
|
+
for (var i = 0; i < document.styleSheets.length; i++)
|
226
|
+
if (document.styleSheets[i].disabled) {
|
227
|
+
setTimeout( arguments.callee, 0 );
|
228
|
+
return;
|
229
|
+
}
|
230
|
+
domReady();
|
231
|
+
}, false);
|
232
|
+
}
|
233
|
+
|
234
|
+
if (browser.safari) {
|
235
|
+
var numStyles;
|
236
|
+
(function(){
|
237
|
+
if (isReady) return;
|
238
|
+
if (document.readyState != "loaded" && document.readyState != "complete") {
|
239
|
+
setTimeout( arguments.callee, 0 );
|
240
|
+
return;
|
241
|
+
}
|
242
|
+
if (numStyles === undefined) {
|
243
|
+
var links = document.getElementsByTagName("link");
|
244
|
+
for (var i=0; i < links.length; i++) {
|
245
|
+
if (links[i].getAttribute('rel') == 'stylesheet') {
|
246
|
+
numStyles++;
|
247
|
+
}
|
248
|
+
}
|
249
|
+
var styles = document.getElementsByTagName("style");
|
250
|
+
numStyles += styles.length;
|
251
|
+
}
|
252
|
+
if (document.styleSheets.length != numStyles) {
|
253
|
+
setTimeout( arguments.callee, 0 );
|
254
|
+
return;
|
255
|
+
}
|
256
|
+
|
257
|
+
domReady();
|
258
|
+
})();
|
259
|
+
}
|
260
|
+
|
261
|
+
addLoadEvent(domReady);
|
262
|
+
};
|
263
|
+
|
264
|
+
window.NinjsDOM = function() {
|
265
|
+
this.cached_selectors = {};
|
266
|
+
};
|
267
|
+
|
268
|
+
NinjsDOM.method('ready', function(fn, args) {
|
269
|
+
bindReady();
|
270
|
+
|
271
|
+
if (isReady) {
|
272
|
+
fn.call(window, []);
|
273
|
+
}
|
274
|
+
else {
|
275
|
+
readyList.push( function() { return fn.call(window, []); } );
|
276
|
+
}
|
277
|
+
});
|
278
|
+
|
279
|
+
bindReady();
|
280
|
+
window.NinjsModule = function(name) {
|
281
|
+
this.dom = new NinjsDOM(this);
|
282
|
+
this.browser = browser;
|
283
|
+
this.data = {};
|
284
|
+
this.name = name;
|
285
|
+
this.run_tests = false;
|
286
|
+
this.tests = [];
|
287
|
+
};
|
288
|
+
|
289
|
+
NinjsModule.method('actions', function() {});
|
290
|
+
|
291
|
+
NinjsModule.method('run', function() {
|
292
|
+
var mod = this;
|
293
|
+
this.dom.ready(function() {
|
294
|
+
mod.execute();
|
295
|
+
});
|
296
|
+
});
|
297
|
+
|
298
|
+
NinjsModule.method('execute', function() {
|
299
|
+
if (this.run_tests) {
|
300
|
+
this._run_tests();
|
301
|
+
}
|
302
|
+
|
303
|
+
this.actions();
|
304
|
+
});
|
305
|
+
|
306
|
+
NinjsModule.method('elements', function(elements) {
|
307
|
+
if (is_undefined(elements)) {
|
308
|
+
if (is_typeof(Object, elements)) {
|
309
|
+
throw new SyntaxError("NinjsModule.elements(elements): elements is undefined");
|
310
|
+
}
|
311
|
+
else if (is_string(elements)) {
|
312
|
+
throw new SyntaxError("NinjsModule.elements(name): name is undefined");
|
313
|
+
}
|
314
|
+
}
|
315
|
+
|
316
|
+
if (is_string(elements)) {
|
317
|
+
var name = elements;
|
318
|
+
return this.dom.cached_selectors[name];
|
319
|
+
}
|
320
|
+
else {
|
321
|
+
var dom = this.dom;
|
322
|
+
dom.ready(function() {
|
323
|
+
for(var key in elements) {
|
324
|
+
if (elements.hasOwnProperty(key)) {
|
325
|
+
dom.cached_selectors[key] = elements[key];
|
326
|
+
}
|
327
|
+
}
|
328
|
+
});
|
329
|
+
}
|
330
|
+
});
|
331
|
+
|
332
|
+
NinjsModule.method('set_data', function(key, value) {
|
333
|
+
if (is_undefined(key)) {
|
334
|
+
throw new SyntaxError('NinjsModule.set_data(key, value): key is undefined');
|
335
|
+
}
|
336
|
+
|
337
|
+
if (is_typeof(String, key) && is_undefined(value)) {
|
338
|
+
throw new SyntaxError('NinjsModule.set_data(key, value): value is undefined');
|
339
|
+
}
|
340
|
+
|
341
|
+
if (is_typeof(String, key)) {
|
342
|
+
this.data[key] = value;
|
343
|
+
}
|
344
|
+
else if (is_typeof(Object, key)) {
|
345
|
+
var data = key;
|
346
|
+
for(var property in data) {
|
347
|
+
this.data[property] = data[property];
|
348
|
+
}
|
349
|
+
}
|
350
|
+
|
351
|
+
return this;
|
352
|
+
});
|
353
|
+
|
354
|
+
NinjsModule.method('add_test', function(test_file) {
|
355
|
+
this.tests.push(test_file);
|
356
|
+
});
|
357
|
+
|
358
|
+
NinjsModule.method('_run_tests', function() {
|
359
|
+
var test_template = [];
|
360
|
+
test_template.push('<div class="test-results" title="Test Results">');
|
361
|
+
test_template.push('<h1 id="qunit-header">' + this.name + ' module tests</h1>');
|
362
|
+
test_template.push('<h2 id="qunit-banner"></h2>');
|
363
|
+
test_template.push('<h2 id="qunit-userAgent"></h2>');
|
364
|
+
test_template.push('<ol id="qunit-tests"></ol>');
|
365
|
+
test_template.push('</div>');
|
366
|
+
|
367
|
+
var qunit_dependencies = '<script src="' + _.tests_path +'qunit/qunit.js"></script>';
|
368
|
+
$.getScript(_.tests_path + 'qunit/qunit.js');
|
369
|
+
var qunit_styles = '<link rel="stylesheet" href="' + _.tests_path + 'qunit/qunit.css">';
|
370
|
+
$('body').append(qunit_styles);
|
371
|
+
$('body').append(test_template.join("\n"));
|
372
|
+
|
373
|
+
this.tests.each(function(test) {
|
374
|
+
$.getScript(_.tests_path + test + '.test.js', function() {
|
375
|
+
var test_results_dialog = $('.test-results');
|
376
|
+
var height = $(window).height() - 200;
|
377
|
+
var width = $(window).width() - 300;
|
378
|
+
try {
|
379
|
+
test_results_dialog.dialog({
|
380
|
+
width: width,
|
381
|
+
height: height,
|
382
|
+
autoOpen: false,
|
383
|
+
buttons: {
|
384
|
+
"Thanks buddy": function() {
|
385
|
+
test_results_dialog.dialog('close');
|
386
|
+
}
|
387
|
+
}
|
388
|
+
});
|
389
|
+
var failed = $('.failed');
|
390
|
+
console.log(failed.html());
|
391
|
+
test_results_dialog.dialog('open');
|
392
|
+
}
|
393
|
+
catch(error) {
|
394
|
+
alert("Test harness requires jQueryUI");
|
395
|
+
}
|
396
|
+
});
|
397
|
+
});
|
398
|
+
});
|
399
|
+
|
400
|
+
window.NinjsApplication = function(base_url, tests_path) {
|
401
|
+
if(is_defined(tests_path)) {
|
402
|
+
this.tests_path = tests_path;
|
403
|
+
}
|
404
|
+
|
405
|
+
if(is_defined(base_url)) {
|
406
|
+
this.site_url = function(path) {
|
407
|
+
var path = path || '';
|
408
|
+
return base_url + path;
|
409
|
+
};
|
410
|
+
}
|
411
|
+
};
|
412
|
+
|
413
|
+
NinjsApplication.method('add_module', function(name) {
|
414
|
+
if (is_undefined(name)) {
|
415
|
+
throw new SyntaxError("NinjsApplication.add_module(name): name is undefined");
|
416
|
+
}
|
417
|
+
|
418
|
+
if (is_defined(this[name])) {
|
419
|
+
throw new SyntaxError("NinjsApplication.add_module(name): '" + name + "' already declared");
|
420
|
+
}
|
421
|
+
|
422
|
+
if (this.name === name) {
|
423
|
+
throw new SyntaxError("NinjsApplication.add_module(name): a module cannot have the same name as the application");
|
424
|
+
}
|
425
|
+
|
426
|
+
return this[name] = new NinjsModule(name);
|
427
|
+
});
|
428
|
+
})();
|