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.
@@ -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
- Module.prototype.actions = function() {};
23
+ //### init
24
+ // The init method is a placholder to be overwritten in each instance
25
+ Module.prototype.init = function() {};
14
26
 
15
- Module.prototype.run = function() {
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(function() {
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.actions = function() {};
242
+ Module.prototype.init = function() {};
243
243
 
244
- Module.prototype.run = function() {
244
+ Module.prototype.init_when_ready = function() {
245
245
  var mod = this;
246
246
  this.dom.call_when_ready(function() {
247
- mod.execute();
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)) {
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "modjs-architecture"
8
- s.version = "0.3.5"
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-04-14"
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
- "foo.js",
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",
@@ -3,9 +3,10 @@
3
3
 
4
4
  //= require "../elements/foo-elements.elements"
5
5
 
6
- m.actions = function() {
6
+ m.init = function() {
7
7
 
8
- }
8
+ };
9
+
10
+ m.init_when_ready();
9
11
 
10
- m.run();
11
12
  })(myapp);
data/spec/fixtures/foo.js CHANGED
@@ -1,9 +1,10 @@
1
1
  (function(app) {
2
2
  var m = app.add_module("foo");
3
3
 
4
- m.actions = function() {
5
-
6
- }
4
+ m.init = function() {
5
+ return this;
6
+ };
7
+
8
+ m.init_when_ready();
7
9
 
8
- m.run();
9
10
  })(myapp);
@@ -5,9 +5,10 @@
5
5
 
6
6
  //= require "../models/foo_all.model"
7
7
 
8
- m.actions = function() {
9
-
10
- }
8
+ m.init = function() {
9
+ return this;
10
+ };
11
+
12
+ m.init_when_ready();
11
13
 
12
- m.run();
13
14
  })(myapp);
@@ -3,9 +3,10 @@
3
3
 
4
4
  //= require "../elements/foo_elements.elements"
5
5
 
6
- m.actions = function() {
7
-
8
- }
6
+ m.init = function() {
7
+ return this;
8
+ };
9
+
10
+ m.init_when_ready();
9
11
 
10
- m.run();
11
12
  })(myapp);
@@ -3,9 +3,10 @@
3
3
 
4
4
  //= require "../models/foo_model.model"
5
5
 
6
- m.actions = function() {
7
-
8
- }
6
+ m.init = function() {
7
+ return this;
8
+ };
9
+
10
+ m.init_when_ready();
9
11
 
10
- m.run();
11
12
  })(myapp);
@@ -239,17 +239,11 @@ Mod.Module = (function() {
239
239
  this.name = name;
240
240
  }
241
241
 
242
- Module.prototype.actions = function() {};
242
+ Module.prototype.init = function() {};
243
243
 
244
- Module.prototype.run = function() {
244
+ Module.prototype.init_when_ready = function() {
245
245
  var mod = this;
246
- this.dom.call_when_ready(function() {
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)) {
@@ -243,17 +243,11 @@ Mod.Module = (function() {
243
243
  this.name = name;
244
244
  }
245
245
 
246
- Module.prototype.actions = function() {};
246
+ Module.prototype.init = function() {};
247
247
 
248
- Module.prototype.run = function() {
248
+ Module.prototype.init_when_ready = function() {
249
249
  var mod = this;
250
- this.dom.call_when_ready(function() {
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 actions method", function() {
38
- expect(module.actions).toBeTruthy();
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.actions = function() {
71
- this.set_data('actions_did_run', true);
72
- expect(module.data.actions_did_run).toBeTruthy();
62
+ module.init = function() {
63
+ this.set_data('init_did_run', true);
64
+ expect(module.data.init_did_run).toBeTruthy();
73
65
  };
74
- module.run();
66
+
67
+ module.init_when_ready();
75
68
  });
76
69
  });
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'simplecov'
2
+
2
3
  SimpleCov.start
3
4
 
4
5
  $: << File.join(File.dirname(__FILE__), "../lib")
data/templates/module.js CHANGED
@@ -9,9 +9,10 @@
9
9
  //= require "../models/<%= arguments[1] %>.model"
10
10
  <% end %>
11
11
 
12
- m.actions = function() {
12
+ m.init = function() {
13
13
 
14
- }
14
+ };
15
+
16
+ m.init_when_ready();
15
17
 
16
- m.run();
17
18
  })(<%= blueprint[:name] %>);
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.3.5
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-04-14 00:00:00.000000000 Z
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
- - foo.js
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: -4571541150195370455
194
+ hash: 3899685420511106559
190
195
  required_rubygems_version: !ruby/object:Gem::Requirement
191
196
  none: false
192
197
  requirements:
data/foo.js DELETED
@@ -1,9 +0,0 @@
1
- (function(app) {
2
- var m = myapp.add_module(foo);
3
-
4
- m.actions = function() {
5
-
6
- }
7
-
8
- m.run();
9
- })(myapp);