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
@@ -1,77 +1,35 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
}
|
36
|
-
}
|
37
|
-
|
38
|
-
if (is_undefined(unless)) {
|
39
|
-
/*
|
40
|
-
Function: unless
|
41
|
-
Function to better express negative conditions (ie. if (!something))
|
42
|
-
|
43
|
-
Parameters:
|
44
|
-
expression - expression to be tested
|
45
|
-
callback - function to be executed unless expression is true (see how that works)
|
46
|
-
fallback - function to be executed if the expression is false (optional)
|
47
|
-
|
48
|
-
Returns:
|
49
|
-
undefined
|
50
|
-
|
51
|
-
> unless(test_expression === 'some condition',
|
52
|
-
> function() {
|
53
|
-
> alert('we do something');
|
54
|
-
> },
|
55
|
-
> function() {
|
56
|
-
> alert('we can do something if it meets the condition too');
|
57
|
-
> }
|
58
|
-
> );
|
59
|
-
*/
|
60
|
-
var unless = function(expression, callback, fallback) {
|
61
|
-
if (is_undefined(expression)) {
|
62
|
-
throw new SyntaxError("unless(expression, callback[, fallback]): expression is undefined");
|
63
|
-
}
|
64
|
-
|
65
|
-
if (is_undefined(callback)) {
|
66
|
-
throw new SyntaxError("unless(expression, callback[, fallback]): callback is undefined");
|
67
|
-
}
|
68
|
-
|
69
|
-
// This kind of expression is exactly why we NEED unless
|
70
|
-
if (!expression) {
|
71
|
-
callback.call(this);
|
72
|
-
}
|
73
|
-
else if (is_defined(fallback)) {
|
74
|
-
fallback.call(this);
|
75
|
-
}
|
76
|
-
};
|
77
|
-
}
|
1
|
+
if (is_undefined(Function.prototype['method'])) {
|
2
|
+
Function.prototype.method = function(name, func) {
|
3
|
+
if (is_undefined(name)) {
|
4
|
+
throw new SyntaxError("Object.method(name, func): name is undefined");
|
5
|
+
}
|
6
|
+
|
7
|
+
if (is_undefined(func)) {
|
8
|
+
throw new SyntaxError("Object.method(name, func): func is undefined");
|
9
|
+
}
|
10
|
+
|
11
|
+
if (is_undefined(this.prototype[name])) {
|
12
|
+
this.prototype[name] = func;
|
13
|
+
return this;
|
14
|
+
}
|
15
|
+
};
|
16
|
+
}
|
17
|
+
|
18
|
+
if (is_undefined(window.unless)) {
|
19
|
+
window.unless = function(expression, callback, fallback) {
|
20
|
+
if (is_undefined(expression)) {
|
21
|
+
throw new SyntaxError("unless(expression, callback[, fallback]): expression is undefined");
|
22
|
+
}
|
23
|
+
|
24
|
+
if (is_undefined(callback)) {
|
25
|
+
throw new SyntaxError("unless(expression, callback[, fallback]): callback is undefined");
|
26
|
+
}
|
27
|
+
|
28
|
+
if (!expression) {
|
29
|
+
callback.call(this);
|
30
|
+
}
|
31
|
+
else if (is_defined(fallback)) {
|
32
|
+
fallback.call(this);
|
33
|
+
}
|
34
|
+
};
|
35
|
+
}
|
@@ -1,135 +1,120 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
window.NinjsModule = function(name) {
|
2
|
+
this.dom = new NinjsDOM(this);
|
3
|
+
this.browser = browser;
|
4
|
+
this.data = {};
|
5
|
+
this.name = name;
|
6
|
+
this.run_tests = false;
|
7
|
+
this.tests = [];
|
8
|
+
};
|
8
9
|
|
9
|
-
NinjsModule.method('actions', function() {});
|
10
|
+
NinjsModule.method('actions', function() {});
|
10
11
|
|
11
|
-
NinjsModule.method('run', function() {
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
var module = this;
|
18
|
-
|
19
|
-
function check_ready() {
|
20
|
-
timer = setInterval(is_ready, 13);
|
21
|
-
}
|
12
|
+
NinjsModule.method('run', function() {
|
13
|
+
var mod = this;
|
14
|
+
this.dom.ready(function() {
|
15
|
+
mod.execute();
|
16
|
+
});
|
17
|
+
});
|
22
18
|
|
23
|
-
function
|
24
|
-
if (
|
25
|
-
|
26
|
-
timer = null;
|
27
|
-
callback.call(module);
|
19
|
+
NinjsModule.method('execute', function() {
|
20
|
+
if (this.run_tests) {
|
21
|
+
this._run_tests();
|
28
22
|
}
|
29
|
-
}
|
30
23
|
|
31
|
-
|
32
|
-
});
|
24
|
+
this.actions();
|
25
|
+
});
|
33
26
|
|
34
|
-
NinjsModule.method('
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
27
|
+
NinjsModule.method('elements', function(elements) {
|
28
|
+
if (is_undefined(elements)) {
|
29
|
+
if (is_typeof(Object, elements)) {
|
30
|
+
throw new SyntaxError("NinjsModule.elements(elements): elements is undefined");
|
31
|
+
}
|
32
|
+
else if (is_string(elements)) {
|
33
|
+
throw new SyntaxError("NinjsModule.elements(name): name is undefined");
|
34
|
+
}
|
35
|
+
}
|
41
36
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
if (is_string(elements)) {
|
54
|
-
var name = elements;
|
55
|
-
return is_defined(this.dom[name]) ? this.dom[name] : undefined;
|
56
|
-
}
|
57
|
-
// Set elements
|
58
|
-
else {
|
59
|
-
this.call_on_ready(function() {
|
60
|
-
for(var key in elements) {
|
61
|
-
if (elements.hasOwnProperty(key)) {
|
62
|
-
this.dom[key] = elements[key];
|
37
|
+
if (is_string(elements)) {
|
38
|
+
var name = elements;
|
39
|
+
return this.dom.cached_selectors[name];
|
40
|
+
}
|
41
|
+
else {
|
42
|
+
var dom = this.dom;
|
43
|
+
dom.ready(function() {
|
44
|
+
for(var key in elements) {
|
45
|
+
if (elements.hasOwnProperty(key)) {
|
46
|
+
dom.cached_selectors[key] = elements[key];
|
47
|
+
}
|
63
48
|
}
|
64
|
-
}
|
65
|
-
}
|
66
|
-
}
|
67
|
-
});
|
49
|
+
});
|
50
|
+
}
|
51
|
+
});
|
68
52
|
|
69
|
-
NinjsModule.method('set_data', function(key, value) {
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
53
|
+
NinjsModule.method('set_data', function(key, value) {
|
54
|
+
if (is_undefined(key)) {
|
55
|
+
throw new SyntaxError('NinjsModule.set_data(key, value): key is undefined');
|
56
|
+
}
|
57
|
+
|
58
|
+
if (is_typeof(String, key) && is_undefined(value)) {
|
59
|
+
throw new SyntaxError('NinjsModule.set_data(key, value): value is undefined');
|
60
|
+
}
|
77
61
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
62
|
+
if (is_typeof(String, key)) {
|
63
|
+
this.data[key] = value;
|
64
|
+
}
|
65
|
+
else if (is_typeof(Object, key)) {
|
66
|
+
var data = key;
|
67
|
+
for(var property in data) {
|
68
|
+
this.data[property] = data[property];
|
69
|
+
}
|
85
70
|
}
|
86
|
-
}
|
87
71
|
|
88
|
-
|
89
|
-
});
|
72
|
+
return this;
|
73
|
+
});
|
90
74
|
|
91
|
-
NinjsModule.method('add_test', function(test_file) {
|
92
|
-
|
93
|
-
});
|
75
|
+
NinjsModule.method('add_test', function(test_file) {
|
76
|
+
this.tests.push(test_file);
|
77
|
+
});
|
94
78
|
|
95
|
-
NinjsModule.method('_run_tests', function() {
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
79
|
+
NinjsModule.method('_run_tests', function() {
|
80
|
+
var test_template = [];
|
81
|
+
test_template.push('<div class="test-results" title="Test Results">');
|
82
|
+
test_template.push('<h1 id="qunit-header">' + this.name + ' module tests</h1>');
|
83
|
+
test_template.push('<h2 id="qunit-banner"></h2>');
|
84
|
+
test_template.push('<h2 id="qunit-userAgent"></h2>');
|
85
|
+
test_template.push('<ol id="qunit-tests"></ol>');
|
86
|
+
test_template.push('</div>');
|
103
87
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
88
|
+
var qunit_dependencies = '<script src="' + _.tests_path +'qunit/qunit.js"></script>';
|
89
|
+
$.getScript(_.tests_path + 'qunit/qunit.js');
|
90
|
+
var qunit_styles = '<link rel="stylesheet" href="' + _.tests_path + 'qunit/qunit.css">';
|
91
|
+
$('body').append(qunit_styles);
|
92
|
+
$('body').append(test_template.join("\n"));
|
109
93
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
94
|
+
this.tests.each(function(test) {
|
95
|
+
$.getScript(_.tests_path + test + '.test.js', function() {
|
96
|
+
var test_results_dialog = $('.test-results');
|
97
|
+
var height = $(window).height() - 200;
|
98
|
+
var width = $(window).width() - 300;
|
99
|
+
try {
|
100
|
+
test_results_dialog.dialog({
|
101
|
+
width: width,
|
102
|
+
height: height,
|
103
|
+
autoOpen: false,
|
104
|
+
buttons: {
|
105
|
+
"Thanks buddy": function() {
|
106
|
+
test_results_dialog.dialog('close');
|
107
|
+
}
|
123
108
|
}
|
124
|
-
}
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
}
|
109
|
+
});
|
110
|
+
var failed = $('.failed');
|
111
|
+
console.log(failed.html());
|
112
|
+
test_results_dialog.dialog('open');
|
113
|
+
}
|
114
|
+
catch(error) {
|
115
|
+
alert("Test harness requires jQueryUI");
|
116
|
+
}
|
117
|
+
});
|
133
118
|
});
|
134
119
|
});
|
135
|
-
|
120
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
var spec = new QSpec("NinjsApplication");
|
2
|
+
|
3
|
+
spec.before = function() {
|
4
|
+
this.app = new NinjsApplication('myapp');
|
5
|
+
};
|
6
|
+
|
7
|
+
spec.after = function() {
|
8
|
+
delete this.app;
|
9
|
+
};
|
10
|
+
|
11
|
+
spec.should("create a ninjs application object", function() {
|
12
|
+
this.app = new NinjsApplication('myapp');
|
13
|
+
ok(is_defined(this.app), 'app is defined');
|
14
|
+
ok(is_typeof(NinjsApplication, this.app), 'app is a valid NinjsApplication');
|
15
|
+
});
|
16
|
+
|
17
|
+
spec.should("create a NinjsModule", function() {
|
18
|
+
this.app = new NinjsApplication('myapp');
|
19
|
+
this.app.add_module('mymod');
|
20
|
+
|
21
|
+
ok(is_typeof(NinjsModule, this.app.mymod), 'app.mymod is a valid NinjsModule');
|
22
|
+
});
|
23
|
+
|
24
|
+
spec.run_all();
|
@@ -0,0 +1,55 @@
|
|
1
|
+
var spec = new QSpec("Array Extensions");
|
2
|
+
|
3
|
+
spec.should("test for emptiness with is_empty and not_empty", function() {
|
4
|
+
expect(4);
|
5
|
+
|
6
|
+
ok([].is_empty(), "[].is_empty() is true");
|
7
|
+
equals(['one', 'two', 'three'].is_empty(), false, "['one', 'two', 'three'].is_empty()");
|
8
|
+
ok(['one', 'two', 'three'].not_empty(), "['one', 'two', 'three'].not_empty() is false");
|
9
|
+
equals([].not_empty(), false, "[].not_empty() is false");
|
10
|
+
});
|
11
|
+
|
12
|
+
spec.should("iterate over each element with each", function() {
|
13
|
+
expect(7);
|
14
|
+
|
15
|
+
var iteration_count = 0;
|
16
|
+
var test_array_values = [];
|
17
|
+
var test_array_indices = [];
|
18
|
+
|
19
|
+
['one', 'two', 'three'].each(function(value, index) {
|
20
|
+
iteration_count++;
|
21
|
+
test_array_values.push(value);
|
22
|
+
test_array_indices.push(index);
|
23
|
+
});
|
24
|
+
|
25
|
+
equals(test_array_values[0], 'one', 'value at index 0 is correct');
|
26
|
+
equals(test_array_values[1], 'two', 'value at index 1 is correct');
|
27
|
+
equals(test_array_values[2], 'three', 'value at index 2 is correct');
|
28
|
+
|
29
|
+
equals(test_array_indices[0], 0, 'first index is correct');
|
30
|
+
equals(test_array_indices[1], 1, 'second index is correct');
|
31
|
+
equals(test_array_indices[2], 2, 'third index is correct');
|
32
|
+
|
33
|
+
equals(iteration_count, 3, 'made only three iterations');
|
34
|
+
});
|
35
|
+
|
36
|
+
spec.should("test if array contains an element", function() {
|
37
|
+
var array = ['one', 'two', 'three'];
|
38
|
+
var string = 'hello';
|
39
|
+
var object = {
|
40
|
+
name: 'some object'
|
41
|
+
};
|
42
|
+
var number = 45;
|
43
|
+
var date = new Date();
|
44
|
+
|
45
|
+
var test_array = [array, string, object, number, date];
|
46
|
+
|
47
|
+
ok(test_array.contains(array), 'array.contains(array)');
|
48
|
+
ok(test_array.contains(string), 'array.contains(string)');
|
49
|
+
ok(test_array.contains(object), 'array.contains(object)');
|
50
|
+
ok(test_array.contains(number), 'array.contains(number)');
|
51
|
+
ok(test_array.contains(date), 'array.contains(date)');
|
52
|
+
equals(test_array.contains('not in there'), false, 'non-existent value is false');
|
53
|
+
});
|
54
|
+
|
55
|
+
spec.run_all();
|
@@ -0,0 +1,64 @@
|
|
1
|
+
var spec = new QSpec("Existence");
|
2
|
+
|
3
|
+
spec.should("test for existence with is_defined", function() {
|
4
|
+
var nonexistent;
|
5
|
+
var existent = 'I think';
|
6
|
+
equals(is_defined(existent), true, 'existent variable is_defined');
|
7
|
+
equals(is_defined(nonexistent), false, 'non-existent variable does not exist');
|
8
|
+
});
|
9
|
+
|
10
|
+
spec.should("test for non-existence with is_undefined", function() {
|
11
|
+
var existent = 'I think';
|
12
|
+
var nonexistent;
|
13
|
+
equals(is_undefined(nonexistent), true, 'non-existent variable does not exist');
|
14
|
+
equals(is_undefined(existent), false, 'existent variable does exist');
|
15
|
+
});
|
16
|
+
|
17
|
+
spec.should("check the type strictly with is_typeof", function() {
|
18
|
+
var foo = function(){};
|
19
|
+
var bar = {
|
20
|
+
name: 'SomeObject',
|
21
|
+
method: function() {}
|
22
|
+
};
|
23
|
+
var SomeClass = function(){};
|
24
|
+
var some_instance = new SomeClass();
|
25
|
+
|
26
|
+
equals(is_typeof(Number, 4), true, 'can check against Number');
|
27
|
+
equals(is_typeof(String, 'Hello World'), true, 'can check against String');
|
28
|
+
equals(is_typeof(Array, ['one', 'two', 'three']), true, 'can check against Array');
|
29
|
+
equals(is_typeof(Function, foo), true, 'can check against Function');
|
30
|
+
equals(is_typeof(Object, bar), true, 'can check against Object');
|
31
|
+
equals(is_typeof(RegExp, /pattern/), true, 'can check against Regexp');
|
32
|
+
equals(is_typeof(SomeClass, some_instance), true, 'can check against custom object');
|
33
|
+
});
|
34
|
+
|
35
|
+
spec.should("check for default types", function() {
|
36
|
+
var today = new Date();
|
37
|
+
var easy_as = [1,2,3];
|
38
|
+
var pattern = new RegExp(/pattern/);
|
39
|
+
|
40
|
+
ok(is_string('hello'), 'hello is_string');
|
41
|
+
ok(is_number(42), '42 is_number');
|
42
|
+
ok(is_array(easy_as), 'easy_as is_array');
|
43
|
+
ok(is_bool(false), 'false is_bool');
|
44
|
+
ok(is_date(today), 'today is_date');
|
45
|
+
ok(is_regex(pattern), 'pattern is_regex');
|
46
|
+
|
47
|
+
equals(is_regex('hello'), false, 'hello fails is_regex');
|
48
|
+
equals(is_date(42), false, '42 fails is_date');
|
49
|
+
equals(is_bool(easy_as), false, 'easy_as fails is_bool');
|
50
|
+
equals(is_array(today), false, 'today fails is_array');
|
51
|
+
equals(is_number(true), false, 'true fails is_number');
|
52
|
+
equals(is_string(pattern), false, 'pattern fails is_string');
|
53
|
+
});
|
54
|
+
|
55
|
+
spec.should("determine if a string is a number", function() {
|
56
|
+
ok(is_numeric(2), '2 is a number');
|
57
|
+
ok(is_numeric(-2), '-2 is a number');
|
58
|
+
ok(is_numeric(45.6), '45.6 is a number');
|
59
|
+
ok(is_numeric(-45.6), '-45.6 is a number');
|
60
|
+
equals(is_numeric('45.6'), true, "'45.6 is a number'");
|
61
|
+
equals(is_numeric('Hello'), false, 'Hello is not a number');
|
62
|
+
});
|
63
|
+
|
64
|
+
spec.run_all();
|