ninjs-framework 0.1.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/.DS_Store +0 -0
- data/.bundle/config +2 -0
- data/.travis.yml +2 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +47 -0
- data/LICENSE.txt +20 -0
- data/README.md +4 -0
- data/Rakefile +76 -0
- data/VERSION +1 -0
- data/lib/.DS_Store +0 -0
- data/lib/ninjs-framework.rb +164 -0
- data/lib/ninjs-framework/assets/jasmine/jasmine-html.js +190 -0
- data/lib/ninjs-framework/assets/jasmine/jasmine.css +166 -0
- data/lib/ninjs-framework/assets/jasmine/jasmine.js +2476 -0
- data/lib/ninjs-framework/assets/jasmine/jasmine_favicon.png +0 -0
- data/lib/ninjs-framework/core/.core.pdoc.yaml +0 -0
- data/lib/ninjs-framework/core/.existence.pdoc.yaml +12 -0
- data/lib/ninjs-framework/core/.extend.pdoc.yaml +0 -0
- data/lib/ninjs-framework/core/.nin.pdoc.yaml +0 -0
- data/lib/ninjs-framework/core/application.js +17 -0
- data/lib/ninjs-framework/core/dom.js +164 -0
- data/lib/ninjs-framework/core/existence.js +60 -0
- data/lib/ninjs-framework/core/extend.js +14 -0
- data/lib/ninjs-framework/core/module.js +66 -0
- data/lib/ninjs-framework/core/nin.js +5 -0
- data/lib/ninjs-framework/extensions/jquery.elements.js +60 -0
- data/lib/ninjs-framework/templates/application.js.erb +3 -0
- data/lib/ninjs-framework/templates/autoload.js.erb +3 -0
- data/lib/ninjs-framework/templates/core.js.erb +3 -0
- data/lib/ninjs-framework/templates/dependency.js.erb +3 -0
- data/lib/ninjs-framework/templates/jasmine.yml.erb +75 -0
- data/lib/ninjs-framework/templates/test-index.html.erb +51 -0
- data/lib/ninjs-framework/utilities/all.js +5 -0
- data/lib/ninjs-framework/utilities/array.js +29 -0
- data/lib/ninjs-framework/utilities/cookie.js +59 -0
- data/lib/ninjs-framework/utilities/css.js +51 -0
- data/lib/ninjs-framework/utilities/number.js +11 -0
- data/lib/ninjs-framework/utilities/string.js +61 -0
- data/spec/fixtures/myapp.js +530 -0
- data/spec/fixtures/nin.js +297 -0
- data/spec/fixtures/ninjs.conf +9 -0
- data/spec/fixtures/test.elements.js +3 -0
- data/spec/fixtures/test.js +14 -0
- data/spec/fixtures/test.model.js +3 -0
- data/spec/fixtures/test.module.js +10 -0
- data/spec/fixtures/utilities.js +211 -0
- data/spec/javascripts/application_spec.js +22 -0
- data/spec/javascripts/array_utility_spec.js +49 -0
- data/spec/javascripts/existence_spec.js +71 -0
- data/spec/javascripts/extension_spec.js +22 -0
- data/spec/javascripts/helpers/SpecHelper.js +3 -0
- data/spec/javascripts/module_spec.js +30 -0
- data/spec/javascripts/string_utility_spec.js +85 -0
- data/spec/javascripts/support/jasmine.yml +75 -0
- data/spec/javascripts/support/jasmine_config.rb +23 -0
- data/spec/javascripts/support/jasmine_runner.rb +32 -0
- data/spec/ninjs_framework_spec.rb +121 -0
- data/spec/spec_helper.rb +41 -0
- data/spec/tmp/Rakefile +76 -0
- data/spec/tmp/application/myapp.js +530 -0
- data/spec/tmp/application/test.js +14 -0
- data/spec/tmp/elements/test.elements.js +3 -0
- data/spec/tmp/lib/nin.js +297 -0
- data/spec/tmp/lib/utilities.js +211 -0
- data/spec/tmp/models/test.model.js +3 -0
- data/spec/tmp/modules/test.module.js +10 -0
- data/spec/tmp/ninjs.conf +9 -0
- data/spec/tmp/spec/index.html +51 -0
- data/spec/tmp/spec/javascripts/application_spec.js +22 -0
- data/spec/tmp/spec/javascripts/array_utility_spec.js +49 -0
- data/spec/tmp/spec/javascripts/existence_spec.js +71 -0
- data/spec/tmp/spec/javascripts/extension_spec.js +22 -0
- data/spec/tmp/spec/javascripts/module_spec.js +30 -0
- data/spec/tmp/spec/javascripts/string_utility_spec.js +85 -0
- data/spec/tmp/spec/javascripts/support/jasmine-html.js +190 -0
- data/spec/tmp/spec/javascripts/support/jasmine.css +166 -0
- data/spec/tmp/spec/javascripts/support/jasmine.js +2476 -0
- data/spec/tmp/spec/javascripts/support/jasmine.yml.erb +75 -0
- data/spec/tmp/spec/javascripts/support/jasmine_config.rb +23 -0
- data/spec/tmp/spec/javascripts/support/jasmine_favicon.png +0 -0
- data/spec/tmp/spec/javascripts/support/jasmine_runner.rb +32 -0
- metadata +285 -0
Binary file
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
NinjsApplication = function() {};
|
2
|
+
|
3
|
+
NinjsApplication.prototype.add_module = function(name) {
|
4
|
+
if (is_undefined(name)) {
|
5
|
+
throw new SyntaxError("NinjsApplication.add_module(name): name is undefined");
|
6
|
+
}
|
7
|
+
|
8
|
+
if (is_defined(this[name])) {
|
9
|
+
throw new SyntaxError("NinjsApplication.add_module(name): '" + name + "' already declared");
|
10
|
+
}
|
11
|
+
|
12
|
+
if (this.name === name) {
|
13
|
+
throw new SyntaxError("NinjsApplication.add_module(name): a module cannot have the same name as the application");
|
14
|
+
}
|
15
|
+
|
16
|
+
return this[name] = new NinjsModule(name);
|
17
|
+
};
|
@@ -0,0 +1,164 @@
|
|
1
|
+
var DomReady = window.DomReady = {},
|
2
|
+
userAgent = navigator.userAgent.toLowerCase(),
|
3
|
+
browser = {
|
4
|
+
version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
|
5
|
+
safari: /webkit/.test(userAgent),
|
6
|
+
opera: /opera/.test(userAgent),
|
7
|
+
msie: (/msie/.test(userAgent)) && (!/opera/.test( userAgent )),
|
8
|
+
mozilla: (/mozilla/.test(userAgent)) && (!/(compatible|webkit)/.test(userAgent))
|
9
|
+
},
|
10
|
+
readyBound = false,
|
11
|
+
isReady = false,
|
12
|
+
readyList = [];
|
13
|
+
|
14
|
+
|
15
|
+
function domReady() {
|
16
|
+
// Make sure that the DOM is not already loaded
|
17
|
+
if(!isReady) {
|
18
|
+
// Remember that the DOM is ready
|
19
|
+
isReady = true;
|
20
|
+
|
21
|
+
if(readyList) {
|
22
|
+
var length = readyList.length;
|
23
|
+
for(var fn = 0; fn < length; fn++) {
|
24
|
+
readyList[fn].call(window, []);
|
25
|
+
}
|
26
|
+
|
27
|
+
readyList = [];
|
28
|
+
}
|
29
|
+
}
|
30
|
+
};
|
31
|
+
|
32
|
+
// From Simon Willison. A safe way to fire onload w/o screwing up everyone else.
|
33
|
+
function addLoadEvent(func) {
|
34
|
+
var oldonload = window.onload;
|
35
|
+
if (typeof window.onload != 'function') {
|
36
|
+
window.onload = func;
|
37
|
+
}
|
38
|
+
else {
|
39
|
+
window.onload = function() {
|
40
|
+
if (oldonload) {
|
41
|
+
oldonload();
|
42
|
+
}
|
43
|
+
func();
|
44
|
+
}
|
45
|
+
}
|
46
|
+
};
|
47
|
+
|
48
|
+
// does the heavy work of working through the browsers idiosyncracies (let's call them that) to hook onload.
|
49
|
+
function bindReady() {
|
50
|
+
if(readyBound) {
|
51
|
+
return;
|
52
|
+
}
|
53
|
+
|
54
|
+
readyBound = true;
|
55
|
+
|
56
|
+
// Mozilla, Opera (see further below for it) and webkit nightlies currently support this event
|
57
|
+
if (document.addEventListener && !browser.opera) {
|
58
|
+
// Use the handy event callback
|
59
|
+
document.addEventListener("DOMContentLoaded", domReady, false);
|
60
|
+
}
|
61
|
+
|
62
|
+
// If IE is used and is not in a frame
|
63
|
+
// Continually check to see if the document is ready
|
64
|
+
if (browser.msie && window == top) (function() {
|
65
|
+
if (isReady) return;
|
66
|
+
try {
|
67
|
+
// If IE is used, use the trick by Diego Perini
|
68
|
+
// http://javascript.nwbox.com/IEContentLoaded/
|
69
|
+
document.documentElement.doScroll("left");
|
70
|
+
}
|
71
|
+
catch(error) {
|
72
|
+
setTimeout(arguments.callee, 0);
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
// and execute any waiting functions
|
76
|
+
domReady();
|
77
|
+
})();
|
78
|
+
|
79
|
+
if(browser.opera) {
|
80
|
+
document.addEventListener( "DOMContentLoaded", function () {
|
81
|
+
if (isReady) return;
|
82
|
+
for (var i = 0; i < document.styleSheets.length; i++)
|
83
|
+
if (document.styleSheets[i].disabled) {
|
84
|
+
setTimeout( arguments.callee, 0 );
|
85
|
+
return;
|
86
|
+
}
|
87
|
+
// and execute any waiting functions
|
88
|
+
domReady();
|
89
|
+
}, false);
|
90
|
+
}
|
91
|
+
|
92
|
+
if(browser.safari) {
|
93
|
+
var numStyles;
|
94
|
+
(function(){
|
95
|
+
if (isReady) return;
|
96
|
+
|
97
|
+
if (document.readyState != "loaded" && document.readyState != "complete") {
|
98
|
+
setTimeout( arguments.callee, 0 );
|
99
|
+
return;
|
100
|
+
}
|
101
|
+
|
102
|
+
if (numStyles === undefined) {
|
103
|
+
var links = document.getElementsByTagName("link");
|
104
|
+
for (var i=0; i < links.length; i++) {
|
105
|
+
if(links[i].getAttribute('rel') == 'stylesheet') {
|
106
|
+
numStyles++;
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
var styles = document.getElementsByTagName("style");
|
111
|
+
numStyles += styles.length;
|
112
|
+
}
|
113
|
+
|
114
|
+
if (document.styleSheets.length != numStyles) {
|
115
|
+
setTimeout( arguments.callee, 0 );
|
116
|
+
return;
|
117
|
+
}
|
118
|
+
|
119
|
+
// and execute any waiting functions
|
120
|
+
domReady();
|
121
|
+
})();
|
122
|
+
}
|
123
|
+
|
124
|
+
// A fallback to window.onload, that will always work
|
125
|
+
addLoadEvent(domReady);
|
126
|
+
};
|
127
|
+
|
128
|
+
// This is the public function that people can use to hook up ready.
|
129
|
+
DomReady.ready = function(fn, args) {
|
130
|
+
// Attach the listeners
|
131
|
+
bindReady();
|
132
|
+
|
133
|
+
// If the DOM is already ready
|
134
|
+
if (isReady) {
|
135
|
+
// Execute the function immediately
|
136
|
+
fn.call(window, []);
|
137
|
+
}
|
138
|
+
else {
|
139
|
+
// Add the function to the wait list
|
140
|
+
readyList.push( function() { return fn.call(window, []); } );
|
141
|
+
}
|
142
|
+
};
|
143
|
+
|
144
|
+
NinjsDOM = function() {
|
145
|
+
this.cached_selectors = {};
|
146
|
+
};
|
147
|
+
|
148
|
+
// This is the public function that people can use to hook up ready.
|
149
|
+
NinjsDOM.prototype.ready = function(fn, args) {
|
150
|
+
// Attach the listeners
|
151
|
+
bindReady();
|
152
|
+
|
153
|
+
// If the DOM is already ready
|
154
|
+
if (isReady) {
|
155
|
+
// Execute the function immediately
|
156
|
+
fn.call(window, args || []);
|
157
|
+
}
|
158
|
+
else {
|
159
|
+
// Add the function to the wait list
|
160
|
+
readyList.push( function() { return fn.call(window, args || []); } );
|
161
|
+
}
|
162
|
+
};
|
163
|
+
|
164
|
+
bindReady();
|
@@ -0,0 +1,60 @@
|
|
1
|
+
is_defined = function(suspect) {
|
2
|
+
return ((suspect === undefined) || (suspect === null)) ? false : true;
|
3
|
+
};
|
4
|
+
|
5
|
+
is_undefined = function(suspect) {
|
6
|
+
return (suspect === undefined) ? true : false;
|
7
|
+
};
|
8
|
+
|
9
|
+
is_typeof = function(type, suspect) {
|
10
|
+
if (is_undefined(type)) {
|
11
|
+
throw new SyntaxError("is_typeof(Type, suspect): type is undefined");
|
12
|
+
}
|
13
|
+
if (is_undefined(suspect)) {
|
14
|
+
throw new SyntaxError("is_typeof(Type, suspect): suspect is undefined");
|
15
|
+
}
|
16
|
+
|
17
|
+
return (suspect.constructor == type) ? true : false;
|
18
|
+
};
|
19
|
+
|
20
|
+
is_numeric = function(suspect) {
|
21
|
+
if(is_typeof(Number, suspect)) {
|
22
|
+
return true;
|
23
|
+
}
|
24
|
+
else {
|
25
|
+
var pattern = /^-?\d+(?:\.\d*)?(?:e[+\-]?\d+)?$/i;
|
26
|
+
return pattern.test(suspect);
|
27
|
+
}
|
28
|
+
};
|
29
|
+
|
30
|
+
is_string = function(suspect) {
|
31
|
+
return is_typeof(String, suspect);
|
32
|
+
};
|
33
|
+
|
34
|
+
is_array = function(suspect) {
|
35
|
+
return is_typeof(Array, suspect);
|
36
|
+
};
|
37
|
+
|
38
|
+
is_number = function(suspect) {
|
39
|
+
return is_typeof(Number, suspect);
|
40
|
+
};
|
41
|
+
|
42
|
+
is_date = function(suspect) {
|
43
|
+
return is_typeof(Date, suspect);
|
44
|
+
};
|
45
|
+
|
46
|
+
is_bool = function(suspect) {
|
47
|
+
return is_typeof(Boolean, suspect);
|
48
|
+
};
|
49
|
+
|
50
|
+
is_regex = function(suspect) {
|
51
|
+
return is_typeof(RegExp, suspect);
|
52
|
+
};
|
53
|
+
|
54
|
+
is_empty = function(suspect) {
|
55
|
+
return suspect.length === 0;
|
56
|
+
};
|
57
|
+
|
58
|
+
is_not_empty = function(suspect) {
|
59
|
+
return suspect.length >= 1;
|
60
|
+
};
|
@@ -0,0 +1,14 @@
|
|
1
|
+
unless = function(expression, callback, fallback) {
|
2
|
+
if (is_undefined(callback)) {
|
3
|
+
throw new SyntaxError("unless(expression, callback[, fallback]): callback is undefined");
|
4
|
+
}
|
5
|
+
|
6
|
+
if (!!!expression) {
|
7
|
+
callback.call(this);
|
8
|
+
}
|
9
|
+
else {
|
10
|
+
if (is_defined(fallback)) {
|
11
|
+
fallback.call(this);
|
12
|
+
}
|
13
|
+
}
|
14
|
+
};
|
@@ -0,0 +1,66 @@
|
|
1
|
+
NinjsModule = function(name) {
|
2
|
+
this.dom = new NinjsDOM(this);
|
3
|
+
this.data = {};
|
4
|
+
this.name = name;
|
5
|
+
};
|
6
|
+
|
7
|
+
NinjsModule.prototype.actions = function() {};
|
8
|
+
|
9
|
+
NinjsModule.prototype.run = function() {
|
10
|
+
var mod = this;
|
11
|
+
this.dom.ready(function() {
|
12
|
+
mod.execute();
|
13
|
+
});
|
14
|
+
};
|
15
|
+
|
16
|
+
NinjsModule.prototype.execute = function() {
|
17
|
+
this.actions();
|
18
|
+
};
|
19
|
+
|
20
|
+
NinjsModule.prototype.elements = function(elements) {
|
21
|
+
if (is_undefined(elements)) {
|
22
|
+
if (is_typeof(Object, elements)) {
|
23
|
+
throw new SyntaxError("NinjsModule.elements(elements): elements is undefined");
|
24
|
+
}
|
25
|
+
else if (is_string(elements)) {
|
26
|
+
throw new SyntaxError("NinjsModule.elements(name): name is undefined");
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
if (is_string(elements)) {
|
31
|
+
var name = elements;
|
32
|
+
return this.dom.cached_selectors[name];
|
33
|
+
}
|
34
|
+
else {
|
35
|
+
var dom = this.dom;
|
36
|
+
dom.ready(function() {
|
37
|
+
for(var key in elements) {
|
38
|
+
if (elements.hasOwnProperty(key)) {
|
39
|
+
dom.cached_selectors[key] = elements[key];
|
40
|
+
}
|
41
|
+
}
|
42
|
+
});
|
43
|
+
}
|
44
|
+
};
|
45
|
+
|
46
|
+
NinjsModule.prototype.set_data = function(key, value) {
|
47
|
+
if (is_undefined(key)) {
|
48
|
+
throw new SyntaxError('NinjsModule.set_data(key, value): key is undefined');
|
49
|
+
}
|
50
|
+
|
51
|
+
if (is_typeof(String, key) && is_undefined(value)) {
|
52
|
+
throw new SyntaxError('NinjsModule.set_data(key, value): value is undefined');
|
53
|
+
}
|
54
|
+
|
55
|
+
if (is_typeof(String, key)) {
|
56
|
+
this.data[key] = value;
|
57
|
+
}
|
58
|
+
else if (is_typeof(Object, key)) {
|
59
|
+
var data = key;
|
60
|
+
for(var property in data) {
|
61
|
+
this.data[property] = data[property];
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
return this;
|
66
|
+
};
|
@@ -0,0 +1,60 @@
|
|
1
|
+
(function($) {
|
2
|
+
NinjsModule.prototype.elements = function(elements, force) {
|
3
|
+
var self = this;
|
4
|
+
|
5
|
+
unless(is_defined(force), function() {
|
6
|
+
force = false;
|
7
|
+
});
|
8
|
+
|
9
|
+
if (is_string(elements)) {
|
10
|
+
var key = elements;
|
11
|
+
if (is_undefined(self.dom[key])) {
|
12
|
+
throw new SyntaxError("NinjsModule.elements('" + key + "'): " + self.name + ".dom." + key + " is undefined");
|
13
|
+
}
|
14
|
+
|
15
|
+
if (is_string(self.dom[key])) {
|
16
|
+
var selection = $(self.dom[key]);
|
17
|
+
|
18
|
+
unless(selection.length === 0, function() {
|
19
|
+
return self.dom[key] = selection;
|
20
|
+
}, function() {
|
21
|
+
return self.dom[key];
|
22
|
+
});
|
23
|
+
}
|
24
|
+
else {
|
25
|
+
if (self.dom[key].length === 0 || force) {
|
26
|
+
|
27
|
+
var return_obj = undefined;
|
28
|
+
|
29
|
+
if (is_string(force)) {
|
30
|
+
var selector = self.dom[key].selector;
|
31
|
+
self.dom[key] = $(force).find(selector);
|
32
|
+
self.dom[key].selector = selector;
|
33
|
+
|
34
|
+
return_obj = self.dom[key];
|
35
|
+
}
|
36
|
+
|
37
|
+
var selection = $(self.dom[key].selector);
|
38
|
+
|
39
|
+
unless(selection.length === 0, function() {
|
40
|
+
return_obj = selection;
|
41
|
+
});
|
42
|
+
|
43
|
+
return return_obj;
|
44
|
+
}
|
45
|
+
else {
|
46
|
+
return self.dom[key];
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
else if (is_typeof(Object, elements)) {
|
51
|
+
self.call_on_ready(function() {
|
52
|
+
for(var key in elements) {
|
53
|
+
if (elements.hasOwnProperty(key)) {
|
54
|
+
self.dom[key] = elements[key];
|
55
|
+
}
|
56
|
+
}
|
57
|
+
});
|
58
|
+
}
|
59
|
+
};
|
60
|
+
})(jQuery);
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# src_files
|
2
|
+
#
|
3
|
+
# Return an array of filepaths relative to src_dir to include before jasmine specs.
|
4
|
+
# Default: []
|
5
|
+
#
|
6
|
+
# EXAMPLE:
|
7
|
+
#
|
8
|
+
# src_files:
|
9
|
+
# - lib/source1.js
|
10
|
+
# - lib/source2.js
|
11
|
+
# - dist/**/*.js
|
12
|
+
#
|
13
|
+
src_files:
|
14
|
+
- lib/core/*.js
|
15
|
+
- lib/extensions/*.js
|
16
|
+
- lib/utilities/*.js
|
17
|
+
|
18
|
+
# stylesheets
|
19
|
+
#
|
20
|
+
# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
|
21
|
+
# Default: []
|
22
|
+
#
|
23
|
+
# EXAMPLE:
|
24
|
+
#
|
25
|
+
# stylesheets:
|
26
|
+
# - css/style.css
|
27
|
+
# - stylesheets/*.css
|
28
|
+
#
|
29
|
+
stylesheets:
|
30
|
+
|
31
|
+
# helpers
|
32
|
+
#
|
33
|
+
# Return an array of filepaths relative to spec_dir to include before jasmine specs.
|
34
|
+
# Default: ["helpers/**/*.js"]
|
35
|
+
#
|
36
|
+
# EXAMPLE:
|
37
|
+
#
|
38
|
+
# helpers:
|
39
|
+
# - helpers/**/*.js
|
40
|
+
#
|
41
|
+
helpers:
|
42
|
+
|
43
|
+
# spec_files
|
44
|
+
#
|
45
|
+
# Return an array of filepaths relative to spec_dir to include.
|
46
|
+
# Default: ["**/*[sS]pec.js"]
|
47
|
+
#
|
48
|
+
# EXAMPLE:
|
49
|
+
#
|
50
|
+
# spec_files:
|
51
|
+
# - **/*[sS]pec.js
|
52
|
+
#
|
53
|
+
spec_files:
|
54
|
+
|
55
|
+
# src_dir
|
56
|
+
#
|
57
|
+
# Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
|
58
|
+
# Default: project root
|
59
|
+
#
|
60
|
+
# EXAMPLE:
|
61
|
+
#
|
62
|
+
# src_dir: public
|
63
|
+
#
|
64
|
+
src_dir:
|
65
|
+
|
66
|
+
# spec_dir
|
67
|
+
#
|
68
|
+
# Spec directory path. Your spec_files must be returned relative to this path.
|
69
|
+
# Default: spec/javascripts
|
70
|
+
#
|
71
|
+
# EXAMPLE:
|
72
|
+
#
|
73
|
+
# spec_dir: spec/javascripts
|
74
|
+
#
|
75
|
+
spec_dir:
|