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