modjs-architecture 0.3.5 → 0.4.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/README.md +272 -2
- data/Rakefile +8 -0
- data/VERSION +1 -1
- data/docs/application.html +28 -0
- data/docs/docco.css +186 -0
- data/docs/dom.html +73 -0
- data/docs/events.html +87 -0
- data/docs/existence.html +69 -0
- data/docs/module.html +67 -0
- data/lib/modjs-architecture/core/application.js +11 -3
- data/lib/modjs-architecture/core/dom.js +17 -0
- data/lib/modjs-architecture/core/module.js +22 -9
- data/lib/modjs-architecture/extensions/events.js +4 -0
- data/lib/modjs-architecture/helpers/existence.js +28 -0
- data/lib/modjs-architecture/lib/mod.js +5 -9
- data/modjs-architecture.gemspec +8 -3
- data/spec/fixtures/foo-elements.js +4 -3
- data/spec/fixtures/foo.js +5 -4
- data/spec/fixtures/foo_all.js +5 -4
- data/spec/fixtures/foo_elements.js +5 -4
- data/spec/fixtures/foo_model.js +5 -4
- data/spec/fixtures/myapp.js +5 -11
- data/spec/fixtures/update.js +5 -11
- data/spec/javascripts/module_spec.js +7 -14
- data/spec/spec_helper.rb +1 -0
- data/templates/module.js +4 -3
- metadata +9 -4
- data/foo.js +0 -9
@@ -1,5 +1,15 @@
|
|
1
|
+
//## Mod.Module
|
2
|
+
|
3
|
+
// Modules are responsible for defining the specific behavior
|
4
|
+
// of pieces of your application. All the functionality of your
|
5
|
+
// application will be defined in modules.
|
1
6
|
Mod.Module = (function() {
|
2
7
|
|
8
|
+
// Each module contains a `dom` property which is a [Mod.DOM](dom.html)
|
9
|
+
// instance to act as the module's API to the DOM. The `data` attribute
|
10
|
+
// is a simple object literal that serves to store module-wide configuration
|
11
|
+
// and properties (which prevents polluting the modules namespace and collision with public methods).
|
12
|
+
// The `name` property is a convenience to be able to ask a module it's name.
|
3
13
|
function Module(name) {
|
4
14
|
if (is_undefined(name)) {
|
5
15
|
throw new Error("Mod.Module(name): name is undefined");
|
@@ -10,19 +20,20 @@ Mod.Module = (function() {
|
|
10
20
|
this.name = name;
|
11
21
|
}
|
12
22
|
|
13
|
-
|
23
|
+
//### init
|
24
|
+
// The init method is a placholder to be overwritten in each instance
|
25
|
+
Module.prototype.init = function() {};
|
14
26
|
|
15
|
-
|
27
|
+
//### init_when_ready
|
28
|
+
// Wait for the DOM to be ready and execute the actions
|
29
|
+
Module.prototype.init_when_ready = function() {
|
16
30
|
var mod = this;
|
17
|
-
this.dom.call_when_ready(
|
18
|
-
mod.execute();
|
19
|
-
});
|
20
|
-
};
|
21
|
-
|
22
|
-
Module.prototype.execute = function() {
|
23
|
-
this.actions();
|
31
|
+
this.dom.call_when_ready(mod.init);
|
24
32
|
};
|
25
33
|
|
34
|
+
//### elements
|
35
|
+
// Serves as an api to set and get elements from the module's `dom` property.
|
36
|
+
// passing a string retrieves an element, passing an object sets elements
|
26
37
|
Module.prototype.elements = function(elements) {
|
27
38
|
if (is_undefined(elements)) {
|
28
39
|
return this.dom.cache;
|
@@ -39,6 +50,8 @@ Mod.Module = (function() {
|
|
39
50
|
}
|
40
51
|
};
|
41
52
|
|
53
|
+
//### set_data
|
54
|
+
// Convenience method to add properties to the `data` property of the module
|
42
55
|
Module.prototype.set_data = function(key, value) {
|
43
56
|
if (is_undefined(key)) {
|
44
57
|
throw new Error(this.name + '.set_data(key, value): key is undefined');
|
@@ -1,3 +1,7 @@
|
|
1
|
+
//## Events
|
2
|
+
|
3
|
+
// Standardizes events accross all browsers and adds W3C events if not present.
|
4
|
+
// Taken directly form [Mozilla Docs](https://developer.mozilla.org/en/DOM/element.removeEventListener)
|
1
5
|
if (!Element.prototype.addEventListener) {
|
2
6
|
var oListeners = {};
|
3
7
|
|
@@ -1,11 +1,21 @@
|
|
1
|
+
//## Existence
|
2
|
+
// Provides convenience methods to determine the existence and
|
3
|
+
// identity of variables.
|
4
|
+
|
5
|
+
//### is_defined
|
6
|
+
// Convenience method to detect defined status
|
1
7
|
is_defined = function(suspect) {
|
2
8
|
return typeof suspect == "undefined" ? false : true;
|
3
9
|
};
|
4
10
|
|
11
|
+
//### is_undefined
|
12
|
+
// Convenience function to detect undefined status
|
5
13
|
is_undefined = function(suspect) {
|
6
14
|
return typeof suspect == "undefined" ? true : false;
|
7
15
|
};
|
8
16
|
|
17
|
+
//### is_typeof
|
18
|
+
// Strict type checking against the `suspect`'s constructor
|
9
19
|
is_typeof = function(type, suspect) {
|
10
20
|
if (is_undefined(type)) {
|
11
21
|
throw new Error("is_typeof(Type, suspect): type is undefined");
|
@@ -18,6 +28,8 @@ is_typeof = function(type, suspect) {
|
|
18
28
|
return suspect.constructor == type ? true : false;
|
19
29
|
};
|
20
30
|
|
31
|
+
//### is_numeric
|
32
|
+
// Determines `suspect` holds a numeric value
|
21
33
|
is_numeric = function(suspect) {
|
22
34
|
if (isNaN(suspect)) {
|
23
35
|
return false;
|
@@ -25,30 +37,44 @@ is_numeric = function(suspect) {
|
|
25
37
|
return !isNaN(parseFloat(suspect)) && isFinite(suspect);
|
26
38
|
};
|
27
39
|
|
40
|
+
//### is_string
|
41
|
+
// Alias method for String detection
|
28
42
|
is_string = function(suspect) {
|
29
43
|
return is_typeof(String, suspect);
|
30
44
|
};
|
31
45
|
|
46
|
+
//### is_array
|
47
|
+
// Alias method for Array detection
|
32
48
|
is_array = function(suspect) {
|
33
49
|
return is_typeof(Array, suspect);
|
34
50
|
};
|
35
51
|
|
52
|
+
//### is_number
|
53
|
+
// Alias method for Number detection
|
36
54
|
is_number = function(suspect) {
|
37
55
|
return is_typeof(Number, suspect);
|
38
56
|
};
|
39
57
|
|
58
|
+
//### is_date
|
59
|
+
// Alias method for Date detection
|
40
60
|
is_date = function(suspect) {
|
41
61
|
return is_typeof(Date, suspect);
|
42
62
|
};
|
43
63
|
|
64
|
+
//### is_bool
|
65
|
+
// Alias method for Boolean detection
|
44
66
|
is_bool = function(suspect) {
|
45
67
|
return is_typeof(Boolean, suspect);
|
46
68
|
};
|
47
69
|
|
70
|
+
//### is_regex
|
71
|
+
// Alias method for RegExp detection
|
48
72
|
is_regex = function(suspect) {
|
49
73
|
return is_typeof(RegExp, suspect);
|
50
74
|
};
|
51
75
|
|
76
|
+
//### is_empty
|
77
|
+
// Convenience method to detect whether the `suspect` is empty
|
52
78
|
is_empty = function(suspect) {
|
53
79
|
if (is_undefined(suspect)) {
|
54
80
|
return true;
|
@@ -57,6 +83,8 @@ is_empty = function(suspect) {
|
|
57
83
|
return suspect.length === 0;
|
58
84
|
};
|
59
85
|
|
86
|
+
//### is_not_empty
|
87
|
+
// Convenience method to detect whether the `suspect` is not empty
|
60
88
|
is_not_empty = function(suspect) {
|
61
89
|
return suspect.length >= 1;
|
62
90
|
};
|
@@ -239,19 +239,15 @@ Mod.Module = (function() {
|
|
239
239
|
this.name = name;
|
240
240
|
}
|
241
241
|
|
242
|
-
Module.prototype.
|
242
|
+
Module.prototype.init = function() {};
|
243
243
|
|
244
|
-
Module.prototype.
|
244
|
+
Module.prototype.init_when_ready = function() {
|
245
245
|
var mod = this;
|
246
246
|
this.dom.call_when_ready(function() {
|
247
|
-
mod.
|
247
|
+
mod.init();
|
248
248
|
});
|
249
249
|
};
|
250
250
|
|
251
|
-
Module.prototype.execute = function() {
|
252
|
-
this.actions();
|
253
|
-
};
|
254
|
-
|
255
251
|
Module.prototype.elements = function(elements) {
|
256
252
|
if (is_undefined(elements)) {
|
257
253
|
return this.dom.cache;
|
@@ -297,8 +293,8 @@ Mod.Application = (function() {
|
|
297
293
|
throw new Error("new Mod.Application(name): name is undefined");
|
298
294
|
}
|
299
295
|
|
300
|
-
this.name = name
|
301
|
-
}
|
296
|
+
this.name = name;
|
297
|
+
}
|
302
298
|
|
303
299
|
Application.prototype.add_module = function(name) {
|
304
300
|
if (is_undefined(name)) {
|
data/modjs-architecture.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "modjs-architecture"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dayton Nolan"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-05-11"
|
13
13
|
s.description = "Mod.js is a modular javascript library that provides a base application strucure to build large javascript applications. Mod.js is designed to work with architecture.js."
|
14
14
|
s.email = "daytonn@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,7 +26,12 @@ Gem::Specification.new do |s|
|
|
26
26
|
"README.md",
|
27
27
|
"Rakefile",
|
28
28
|
"VERSION",
|
29
|
-
"
|
29
|
+
"docs/application.html",
|
30
|
+
"docs/docco.css",
|
31
|
+
"docs/dom.html",
|
32
|
+
"docs/events.html",
|
33
|
+
"docs/existence.html",
|
34
|
+
"docs/module.html",
|
30
35
|
"lib/modjs-architecture.rb",
|
31
36
|
"lib/modjs-architecture/core/application.js",
|
32
37
|
"lib/modjs-architecture/core/dom.js",
|
data/spec/fixtures/foo.js
CHANGED
data/spec/fixtures/foo_all.js
CHANGED
data/spec/fixtures/foo_model.js
CHANGED
data/spec/fixtures/myapp.js
CHANGED
@@ -239,17 +239,11 @@ Mod.Module = (function() {
|
|
239
239
|
this.name = name;
|
240
240
|
}
|
241
241
|
|
242
|
-
Module.prototype.
|
242
|
+
Module.prototype.init = function() {};
|
243
243
|
|
244
|
-
Module.prototype.
|
244
|
+
Module.prototype.init_when_ready = function() {
|
245
245
|
var mod = this;
|
246
|
-
this.dom.call_when_ready(
|
247
|
-
mod.execute();
|
248
|
-
});
|
249
|
-
};
|
250
|
-
|
251
|
-
Module.prototype.execute = function() {
|
252
|
-
this.actions();
|
246
|
+
this.dom.call_when_ready(mod.init);
|
253
247
|
};
|
254
248
|
|
255
249
|
Module.prototype.elements = function(elements) {
|
@@ -297,8 +291,8 @@ Mod.Application = (function() {
|
|
297
291
|
throw new Error("new Mod.Application(name): name is undefined");
|
298
292
|
}
|
299
293
|
|
300
|
-
this.name = name
|
301
|
-
}
|
294
|
+
this.name = name;
|
295
|
+
}
|
302
296
|
|
303
297
|
Application.prototype.add_module = function(name) {
|
304
298
|
if (is_undefined(name)) {
|
data/spec/fixtures/update.js
CHANGED
@@ -243,17 +243,11 @@ Mod.Module = (function() {
|
|
243
243
|
this.name = name;
|
244
244
|
}
|
245
245
|
|
246
|
-
Module.prototype.
|
246
|
+
Module.prototype.init = function() {};
|
247
247
|
|
248
|
-
Module.prototype.
|
248
|
+
Module.prototype.init_when_ready = function() {
|
249
249
|
var mod = this;
|
250
|
-
this.dom.call_when_ready(
|
251
|
-
mod.execute();
|
252
|
-
});
|
253
|
-
};
|
254
|
-
|
255
|
-
Module.prototype.execute = function() {
|
256
|
-
this.actions();
|
250
|
+
this.dom.call_when_ready(mod.init);
|
257
251
|
};
|
258
252
|
|
259
253
|
Module.prototype.elements = function(elements) {
|
@@ -301,8 +295,8 @@ Mod.Application = (function() {
|
|
301
295
|
throw new Error("new Mod.Application(name): name is undefined");
|
302
296
|
}
|
303
297
|
|
304
|
-
this.name = name
|
305
|
-
}
|
298
|
+
this.name = name;
|
299
|
+
}
|
306
300
|
|
307
301
|
Application.prototype.add_module = function(name) {
|
308
302
|
if (is_undefined(name)) {
|
@@ -34,16 +34,8 @@ describe("Mod.Module", function() {
|
|
34
34
|
expect(module.data.three).toEqual('three');
|
35
35
|
});
|
36
36
|
|
37
|
-
it("should have an
|
38
|
-
expect(module.
|
39
|
-
});
|
40
|
-
|
41
|
-
it("should have an execute method to call the actions", function() {
|
42
|
-
module.actions = function() {
|
43
|
-
this.set_data('actions_did_run', true);
|
44
|
-
};
|
45
|
-
module.execute();
|
46
|
-
expect(module.data.actions_did_run).toBeTruthy();
|
37
|
+
it("should have an init method", function() {
|
38
|
+
expect(module.init).toBeTruthy();
|
47
39
|
});
|
48
40
|
|
49
41
|
it("should have an elements method to cache DOM elements", function() {
|
@@ -67,10 +59,11 @@ describe("Mod.Module", function() {
|
|
67
59
|
});
|
68
60
|
|
69
61
|
it("should run the execute method when the dom is ready", function() {
|
70
|
-
module.
|
71
|
-
this.set_data('
|
72
|
-
expect(module.data.
|
62
|
+
module.init = function() {
|
63
|
+
this.set_data('init_did_run', true);
|
64
|
+
expect(module.data.init_did_run).toBeTruthy();
|
73
65
|
};
|
74
|
-
|
66
|
+
|
67
|
+
module.init_when_ready();
|
75
68
|
});
|
76
69
|
});
|
data/spec/spec_helper.rb
CHANGED
data/templates/module.js
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modjs-architecture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: architecture-js
|
@@ -126,7 +126,12 @@ files:
|
|
126
126
|
- README.md
|
127
127
|
- Rakefile
|
128
128
|
- VERSION
|
129
|
-
-
|
129
|
+
- docs/application.html
|
130
|
+
- docs/docco.css
|
131
|
+
- docs/dom.html
|
132
|
+
- docs/events.html
|
133
|
+
- docs/existence.html
|
134
|
+
- docs/module.html
|
130
135
|
- lib/modjs-architecture.rb
|
131
136
|
- lib/modjs-architecture/core/application.js
|
132
137
|
- lib/modjs-architecture/core/dom.js
|
@@ -186,7 +191,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
186
191
|
version: '0'
|
187
192
|
segments:
|
188
193
|
- 0
|
189
|
-
hash:
|
194
|
+
hash: 3899685420511106559
|
190
195
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
196
|
none: false
|
192
197
|
requirements:
|