ninjs 0.10.2 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/Gemfile +1 -0
  2. data/Gemfile.lock +64 -0
  3. data/Rakefile +4 -1
  4. data/VERSION +1 -1
  5. data/bin/ninjs +14 -5
  6. data/lib/ninjs.rb +0 -3
  7. data/lib/ninjs/command.rb +67 -110
  8. data/lib/ninjs/configuration.rb +33 -39
  9. data/lib/ninjs/project.rb +14 -31
  10. data/ninjs.conf +7 -0
  11. data/ninjs.gemspec +63 -5
  12. data/repository/jquery/1.5.js +16 -0
  13. data/repository/jquery/latest.js +1 -1
  14. data/repository/jquery/mobile/1.0a3.js +123 -0
  15. data/repository/jquery/mobile/1.0a3/assets/css/jquery.mobile.css +1652 -0
  16. data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/ajax-loader.png +0 -0
  17. data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/form-check-off.png +0 -0
  18. data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/form-check-on.png +0 -0
  19. data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/form-radio-off.png +0 -0
  20. data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/form-radio-on.png +0 -0
  21. data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/icon-search-black.png +0 -0
  22. data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/icons-18-black.png +0 -0
  23. data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/icons-18-white.png +0 -0
  24. data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/icons-36-black.png +0 -0
  25. data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/icons-36-white.png +0 -0
  26. data/repository/jquery/mobile/latest.js +1 -0
  27. data/spec/fixtures/global.js +7 -0
  28. data/spec/fixtures/global.module.js +7 -0
  29. data/spec/fixtures/myapplication.js +576 -0
  30. data/spec/fixtures/nin.js +573 -0
  31. data/spec/fixtures/ninjs.conf +6 -0
  32. data/spec/fixtures/test.elements.js +4 -0
  33. data/spec/fixtures/test.js +15 -0
  34. data/spec/fixtures/test.model.js +3 -0
  35. data/spec/fixtures/test.module.js +10 -0
  36. data/spec/fixtures/updated.myapplication.js +27 -0
  37. data/spec/fixtures/utilities.js +162 -0
  38. data/spec/ninjs_spec.rb +257 -0
  39. data/spec/spec_helper.rb +2 -1
  40. data/tmp/ff9e83aa019b712b90200b8d1b8fa0c7e14576af.json +1 -0
  41. data/tmp/metric_fu/_data/20110305.yml +1548 -0
  42. data/tmp/metric_fu/output/bluff-min.js +1 -0
  43. data/tmp/metric_fu/output/churn.html +692 -0
  44. data/tmp/metric_fu/output/excanvas.js +35 -0
  45. data/tmp/metric_fu/output/flay.html +566 -0
  46. data/tmp/metric_fu/output/flay.js +11 -0
  47. data/tmp/metric_fu/output/flog.html +2392 -0
  48. data/tmp/metric_fu/output/flog.js +12 -0
  49. data/tmp/metric_fu/output/hotspots.html +3607 -0
  50. data/tmp/metric_fu/output/index.html +572 -0
  51. data/tmp/metric_fu/output/js-class.js +1 -0
  52. data/tmp/metric_fu/output/lib_ninjs.rb.html +49 -0
  53. data/tmp/metric_fu/output/lib_ninjs_command.rb.html +137 -0
  54. data/tmp/metric_fu/output/lib_ninjs_configuration.rb.html +107 -0
  55. data/tmp/metric_fu/output/lib_ninjs_dependencies.rb.html +34 -0
  56. data/tmp/metric_fu/output/lib_ninjs_helpers.rb.html +34 -0
  57. data/tmp/metric_fu/output/lib_ninjs_manifest.rb.html +27 -0
  58. data/tmp/metric_fu/output/lib_ninjs_project.rb.html +236 -0
  59. data/tmp/metric_fu/output/rails_best_practices.js +11 -0
  60. data/tmp/metric_fu/output/rcov.html +566 -0
  61. data/tmp/metric_fu/output/rcov.js +11 -0
  62. data/tmp/metric_fu/output/reek.html +1294 -0
  63. data/tmp/metric_fu/output/reek.js +20 -0
  64. data/tmp/metric_fu/output/roodi.html +599 -0
  65. data/tmp/metric_fu/output/roodi.js +11 -0
  66. data/tmp/metric_fu/report.yml +1548 -0
  67. data/tmp/metric_fu/scratch/rcov/rcov.txt +1 -0
  68. metadata +94 -27
  69. data/spec/test_spec.rb +0 -5
@@ -0,0 +1,573 @@
1
+ /* File: nin.js */
2
+ /* File: extend.js */
3
+ /* File: existence.js */
4
+ if (is_defined === undefined) {
5
+ /*
6
+ Function: is_defined
7
+ Checks if a variable is undefined.
8
+
9
+ Parameters:
10
+ suspect - suspect variable to test
11
+
12
+ Returns:
13
+ bool
14
+
15
+ See Also:
16
+
17
+ <is_undefined>
18
+ */
19
+ var is_defined = function(suspect) {
20
+ return (suspect === undefined) ? false : true;
21
+ };
22
+ }
23
+
24
+ if (!is_defined(is_undefined)) {
25
+ /*
26
+ Function: is_undefined
27
+ Checks if a variable is defined.
28
+
29
+ Parameters:
30
+ suspect - suspect variable to test
31
+
32
+ Returns:
33
+ bool
34
+
35
+ See Also:
36
+
37
+ <is_defined>
38
+ */
39
+ var is_undefined = function(suspect) {
40
+ return (suspect === undefined) ? true : false;
41
+ };
42
+ }
43
+
44
+ if (is_undefined(is_typeof)) {
45
+ /*
46
+ Function: is_typeof
47
+ Determine an object's type strictly by comparing constructors.
48
+
49
+ Parameters:
50
+ type - The type you expect (ie. String, Number, Array without quotes: is_typeof(String, 'hello'): // true)
51
+ suspect - The variable to check against type
52
+
53
+ Returns:
54
+ bool
55
+
56
+ See Also:
57
+ <is_numeric>,
58
+ <is_string>,
59
+ <is_array>,
60
+ <is_number>,
61
+ <is_date>,
62
+ <is_bool>,
63
+ <is_regex>
64
+ */
65
+ var is_typeof = function(type, suspect) {
66
+ try {
67
+ if (is_undefined(type)) {
68
+ throw new SyntaxError("is_typeof(Type, suspect): type is undefined");
69
+ }
70
+ if (is_undefined(suspect)) {
71
+ throw new SyntaxError("is_typeof(Type, suspect): suspect is undefined");
72
+ }
73
+
74
+ return (suspect.constructor == type) ? true : false;
75
+ }
76
+ catch(error) {
77
+ alert(error.message);
78
+ }
79
+ };
80
+ }
81
+
82
+ if (is_undefined(is_numeric)) {
83
+ /*
84
+ Function: is_numeric
85
+ Determine if the suspect string represents a numeric value.
86
+
87
+ Parameters:
88
+ suspect - variable to check for numeric value
89
+
90
+ Returns:
91
+ bool
92
+
93
+ See Also:
94
+ <is_number>
95
+ */
96
+ var is_numeric = function(suspect) {
97
+ if(is_typeof(Number, suspect)) {
98
+ return true;
99
+ }
100
+ else {
101
+ var pattern = /^-?\d+(?:\.\d*)?(?:e[+\-]?\d+)?$/i;
102
+ return pattern.test(suspect);
103
+ }
104
+ };
105
+ }
106
+
107
+ if (is_undefined(is_string)) {
108
+ /*
109
+ Function: is_string
110
+ Determine the suspect is a String. This is a proxy method for is_typeof(String, suspect).
111
+
112
+ Parameters:
113
+ suspect - supect variable to test
114
+
115
+ Returns:
116
+ bool
117
+
118
+ See Also:
119
+ <is_typeof>,
120
+ <is_numeric>,
121
+ <is_array>,
122
+ <is_number>,
123
+ <is_date>,
124
+ <is_bool>,
125
+ <is_regex>
126
+ */
127
+ var is_string = function(suspect) {
128
+ return is_typeof(String, suspect);
129
+ };
130
+ }
131
+
132
+ if (is_undefined(is_array)) {
133
+ /*
134
+ Function: is_array
135
+ Determine if the suspect is an Array. This is a proxy method for is_typeof(Array, suspect).
136
+
137
+ Parameters:
138
+ suspect - suspect variable to test
139
+
140
+ Returns:
141
+ bool
142
+
143
+ See Also:
144
+ <is_typeof>,
145
+ <is_numeric>,
146
+ <is_string>,
147
+ <is_number>,
148
+ <is_date>,
149
+ <is_bool>,
150
+ <is_regex>
151
+ */
152
+ var is_array = function(suspect) {
153
+ return is_typeof(Array, suspect);
154
+ };
155
+ }
156
+
157
+ if (is_undefined(is_number)) {
158
+ /*
159
+ Function: is_number
160
+ Determines if the suspect is a Number. This is a proxy method for is_typeof(Number, suspect).
161
+
162
+ Parameters:
163
+ suspect - suspect variable to test
164
+
165
+ Returns:
166
+ bool
167
+
168
+ See Also:
169
+ <is_typeof>,
170
+ <is_numeric>,
171
+ <is_string>,
172
+ <is_array>,
173
+ <is_date>,
174
+ <is_bool>,
175
+ <is_regex>
176
+ */
177
+ var is_number = function(suspect) {
178
+ return is_typeof(Number, suspect);
179
+ };
180
+ }
181
+
182
+ if (is_undefined(is_date)) {
183
+ /*
184
+ Function: is_date
185
+ Determines if the suspect is a Date. This is a proxy method for is_typeof(Date, suspect).
186
+
187
+ Parameters:
188
+ suspect - suspect variable to test
189
+
190
+ Returns:
191
+ bool
192
+
193
+ See Also:
194
+ <is_typeof>,
195
+ <is_numeric>,
196
+ <is_string>,
197
+ <is_array>,
198
+ <is_number>,
199
+ <is_bool>,
200
+ <is_regex>
201
+ */
202
+ var is_date = function(suspect) {
203
+ return is_typeof(Date, suspect);
204
+ };
205
+ }
206
+
207
+ if (is_undefined(is_bool)) {
208
+ /*
209
+ Function: is_bool
210
+ Determines if the suspect is a Boolean. This is a proxy method for is_typeof(Boolean, suspect).
211
+
212
+ Parameters:
213
+ suspect - suspect variable to test
214
+
215
+ Returns:
216
+ bool
217
+
218
+ See Also:
219
+ <is_typeof>,
220
+ <is_numeric>,
221
+ <is_string>,
222
+ <is_array>,
223
+ <is_number>,
224
+ <is_regex>
225
+ */
226
+ var is_bool = function(suspect) {
227
+ return is_typeof(Boolean, suspect);
228
+ };
229
+ }
230
+
231
+ if (is_undefined(is_regex)) {
232
+ /*
233
+ Function: is_regex
234
+ Determines if the suspect is a RegExp. This is a proxy method for is_typeof(RegExp, suspect).
235
+
236
+ Parameters:
237
+ suspect - suspect variable to test
238
+
239
+ Returns:
240
+ bool
241
+
242
+ See Also:
243
+ <is_typeof>,
244
+ <is_numeric>,
245
+ <is_string>,
246
+ <is_array>,
247
+ <is_number>,
248
+ <is_bool>
249
+ */
250
+ var is_regex = function(suspect) {
251
+ return is_typeof(RegExp, suspect);
252
+ };
253
+ }
254
+
255
+ if (is_undefined(Function.prototype['method'])) {
256
+ /*
257
+ Function: method
258
+ Method to add a method to an object (ie. String.method('my_method', my_func); //-> 'hello'.my_func())
259
+
260
+ Parameters:
261
+ name - name of the method
262
+ func - function definition
263
+
264
+ Returns:
265
+ this === Function
266
+
267
+ > String.method('custom_method', function() {
268
+ > // define custom_method
269
+ > });
270
+ >
271
+ > "hello".custom_method();
272
+ */
273
+ Function.prototype.method = function(name, func) {
274
+ try {
275
+ if (is_undefined(name)) {
276
+ throw new SyntaxError("Object.method(name, func): name is undefined");
277
+ }
278
+ if (is_undefined(func)) {
279
+ throw new SyntaxError("Object.method(name, func): func is undefined");
280
+ }
281
+
282
+ if (is_undefined(this.prototype[name])) {
283
+ this.prototype[name] = func;
284
+ return this;
285
+ }
286
+ }
287
+ catch(error) {
288
+ alert(error.message);
289
+ }
290
+ };
291
+ }
292
+ /*
293
+ File: module.js
294
+
295
+ Class: NinjsModule
296
+ A NinjsModule is an object which encapsulates a certain behavior or functionality.
297
+
298
+ Parameters:
299
+ name - the name of the module
300
+
301
+ See Also:
302
+ <NinjsApplication>
303
+ */
304
+ var NinjsModule = function(name) {
305
+ /*
306
+ Variable: data
307
+ The module's data object
308
+ */
309
+ this.data = {};
310
+ /*
311
+ Variable: name
312
+ The module's name (string)
313
+ */
314
+ this.name = name;
315
+ /*
316
+ Variable: run_tests (beta)
317
+ Boolean to turn tests on/off
318
+ */
319
+ this.run_tests = false;
320
+ /*
321
+ Variable: tests (beta)
322
+ Array of test files to run
323
+ */
324
+ this.tests = [];
325
+ };
326
+
327
+ /*
328
+ Method: actions
329
+ The actions method contains code to be executed when run is called. This method is a placeholder to be overwritten.
330
+
331
+ > MyModule.actions = function() {
332
+ > // define actions here
333
+ >};
334
+ */
335
+ NinjsModule.method('actions', function() {});
336
+
337
+
338
+ /*
339
+ Method: run
340
+ Waits for the DOM to load then calls execute.
341
+
342
+ > MyModule.run();
343
+ */
344
+ NinjsModule.method('run', function() {
345
+ this.call_on_ready(this.execute);
346
+ });
347
+
348
+ /*
349
+ Method: call_on_ready
350
+ Waits for the DOM to be ready and then executes a callback.
351
+
352
+ Parameters:
353
+ callback - function to be called when the DOM is ready
354
+
355
+ > MyModule.call_on_ready(function() {
356
+ > // some code to execute when the DOM is ready
357
+ > });
358
+ */
359
+ NinjsModule.method('call_on_ready', function(callback) {
360
+ var timer;
361
+ var module = this;
362
+
363
+ function check_ready() {
364
+ timer = setInterval(is_ready, 13);
365
+ }
366
+
367
+ function is_ready() {
368
+ if (document && document.getElementsByTagName && document.getElementById && document.body) {
369
+ clearInterval(timer);
370
+ timer = null;
371
+ callback.call(module);
372
+ }
373
+ }
374
+
375
+ check_ready();
376
+ });
377
+
378
+ /*
379
+ Method: execute
380
+ Wrapper method that set's up the environment and then calls actions.
381
+
382
+ > MyModule.execute();
383
+ */
384
+ NinjsModule.method('execute', function() {
385
+ this.old__ = is_defined(window.__) ? window.__ : undefined;
386
+ window.__ = this;
387
+
388
+ if (this.run_tests) {
389
+ this._run_tests();
390
+ }
391
+ this.actions();
392
+
393
+ if(is_defined(this.old__)) {
394
+ window.__ = this.old__;
395
+ }
396
+ });
397
+
398
+ /*
399
+ Method: elements
400
+ Method to define module elements.
401
+
402
+ Parameters:
403
+ callback - function to define a module's elements
404
+
405
+ > MyModule.elements(function() {
406
+ > // element definitions go here
407
+ > });
408
+ */
409
+ NinjsModule.method('elements', function(callback) {
410
+ this.old__ = is_defined(window.__) ? window.__ : undefined;
411
+ window.__ = this;
412
+
413
+ this.call_on_ready(callback);
414
+
415
+ if(is_defined(this.old__)) {
416
+ window.__ = this.old__;
417
+ }
418
+ });
419
+
420
+
421
+ /*
422
+ Method: set_data
423
+ Adds properties to the module's data object.
424
+
425
+ Parameters:
426
+ key - string or object (if string = key, if object sets multiple properties)
427
+ value - value of key if key is string
428
+
429
+ > MyModule.set_data('some_key', 'some_value');
430
+ > MyModule.data.some_key === 'some_value'
431
+
432
+ > MyModule.set_data({
433
+ > 'property_one': 'value_one',
434
+ > 'property_two': 'value_two'
435
+ > });
436
+ > MyModule.data.property_one === 'value_one'
437
+ > MyModule.data.property_two === 'value_two'
438
+ */
439
+ NinjsModule.method('set_data', function(key, value) {
440
+ try {
441
+ if (is_undefined(key)) {
442
+ throw new SyntaxError('NinjsModule.set_data(key, value): key is undefined');
443
+ }
444
+
445
+ if (is_typeof(String, key) && is_undefined(value)) {
446
+ throw new SyntaxError('NinjsModule.set_data(key, value): value is undefined');
447
+ }
448
+
449
+ if (is_typeof(String, key)) {
450
+ this.data[key] = value;
451
+ }
452
+ else if (is_typeof(Object, key)) {
453
+ var data = key;
454
+ for(var property in data) {
455
+ this.data[property] = data[property];
456
+ }
457
+ }
458
+
459
+ return this;
460
+ }
461
+ catch(error) {
462
+ alert(error.message);
463
+ }
464
+ });
465
+
466
+ /*
467
+ Method: add_test
468
+ Adds a test file to the tests array (beta).
469
+
470
+ Parameters:
471
+ test_file - File to add to the tests array
472
+
473
+ > MyModule.add_test('mytest.test.js');
474
+ */
475
+ NinjsModule.method('add_test', function(test_file) {
476
+ this.tests.push(test_file);
477
+ });
478
+
479
+ /*
480
+ Method: _run_tests
481
+ Runs the test files in the test array. This method is automatically called by the execute method if run_tests === true
482
+ */
483
+ NinjsModule.method('_run_tests', function() {
484
+ var test_template = [];
485
+ test_template.push('<div class="test-results" title="Test Results">');
486
+ test_template.push('<h1 id="qunit-header">' + this.name + ' module tests</h1>');
487
+ test_template.push('<h2 id="qunit-banner"></h2>');
488
+ test_template.push('<h2 id="qunit-userAgent"></h2>');
489
+ test_template.push('<ol id="qunit-tests"></ol>');
490
+ test_template.push('</div>');
491
+
492
+ var qunit_dependencies = '<script src="' + _.tests_path +'qunit/qunit.js"></script>';
493
+ $.getScript(_.tests_path + 'qunit/qunit.js');
494
+ var qunit_styles = '<link rel="stylesheet" href="' + _.tests_path + 'qunit/qunit.css">';
495
+ $('body').append(qunit_styles);
496
+ $('body').append(test_template.join("\n"));
497
+
498
+ this.tests.each(function(test) {
499
+ $.getScript(_.tests_path + test + '.test.js', function() {
500
+ var test_results_dialog = $('.test-results');
501
+ var height = $(window).height() - 200;
502
+ var width = $(window).width() - 300;
503
+ try {
504
+ test_results_dialog.dialog({
505
+ width: width,
506
+ height: height,
507
+ autoOpen: false,
508
+ buttons: {
509
+ "Thanks buddy": function() {
510
+ test_results_dialog.dialog('close');
511
+ }
512
+ }
513
+ });
514
+ var failed = $('.failed');
515
+ console.log(failed.html());
516
+ test_results_dialog.dialog('open');
517
+ }
518
+ catch(error) {
519
+ alert("Test harness requires jQueryUI");
520
+ }
521
+ });
522
+ });
523
+ });
524
+ /*
525
+ File: application.js
526
+
527
+ Class: NinjsApplication
528
+ An NinjsApplication object serves as your application's namespace and includes a utility to add modules to the application object.
529
+
530
+ See Also:
531
+ <NinjsModule>
532
+ */
533
+ var NinjsApplication = function(base_url, tests_path) {
534
+ if (is_undefined(window._)) {
535
+ window._ = this;
536
+ }
537
+
538
+ if(is_defined(tests_path)) {
539
+ this.tests_path = tests_path;
540
+ }
541
+
542
+ if(is_defined(base_url)) {
543
+ this.site_url = function(path) {
544
+ var path = path || '';
545
+ return base_url + path;
546
+ }
547
+ }
548
+ };
549
+
550
+ /*
551
+ Method: add_module
552
+ Adds a NinjsModule to the application.
553
+
554
+ Parameters:
555
+ name - the name of the module
556
+
557
+ > myapp.add_module('my_module');
558
+ */
559
+ NinjsApplication.method('add_module', function(name) {
560
+ try {
561
+ if (is_undefined(name)) {
562
+ throw new SyntaxError("NinjsApplication.add_module(name): name is undefined");
563
+ }
564
+
565
+ if (is_defined(this[name])) {
566
+ throw new SyntaxError("NinjsApplication.add_module(name): '" + name + "' already declared");
567
+ }
568
+ this[name] = new NinjsModule(name);
569
+ }
570
+ catch(error) {
571
+ alert(error.message);
572
+ }
573
+ });