modjs-architecture 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.2-p290@modjs --create
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
data/foo.js ADDED
@@ -0,0 +1,9 @@
1
+ (function(app) {
2
+ var m = myapp.add_module(foo);
3
+
4
+ m.actions = function() {
5
+
6
+ }
7
+
8
+ m.run();
9
+ })(myapp);
@@ -0,0 +1,6 @@
1
+ framework: none
2
+ src_dir: src
3
+ build_dir: lib
4
+ asset_root: ../
5
+ output: expanded
6
+ name: mod
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "modjs-architecture"
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
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-02-27"
12
+ s.date = "2012-04-14"
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 = [
@@ -19,12 +19,14 @@ Gem::Specification.new do |s|
19
19
  s.files = [
20
20
  ".document",
21
21
  ".rspec",
22
+ ".rvmrc",
22
23
  ".travis.yml",
23
24
  "Gemfile",
24
25
  "LICENSE.txt",
25
26
  "README.md",
26
27
  "Rakefile",
27
28
  "VERSION",
29
+ "foo.js",
28
30
  "lib/modjs-architecture.rb",
29
31
  "lib/modjs-architecture/core/application.js",
30
32
  "lib/modjs-architecture/core/dom.js",
@@ -38,17 +40,22 @@ Gem::Specification.new do |s|
38
40
  "lib/modjs-architecture/jasmine/jasmine.js",
39
41
  "lib/modjs-architecture/jasmine/jasmine_favicon.png",
40
42
  "lib/modjs-architecture/lib/mod.js",
43
+ "lib/modjs-architecture/modjs.architecture",
41
44
  "lib/modjs-architecture/modjs.blueprint",
42
45
  "lib/modjs-architecture/src/mod.js",
43
46
  "modjs-architecture.gemspec",
47
+ "spec/fixtures/foo-elements.js",
44
48
  "spec/fixtures/foo.js",
45
49
  "spec/fixtures/foo_all.js",
46
50
  "spec/fixtures/foo_elements.js",
47
51
  "spec/fixtures/foo_model.js",
52
+ "spec/fixtures/model_name.js",
53
+ "spec/fixtures/myapp.architecture",
48
54
  "spec/fixtures/myapp.blueprint",
49
55
  "spec/fixtures/myapp.js",
50
56
  "spec/fixtures/test.js",
51
57
  "spec/fixtures/test.module.js",
58
+ "spec/fixtures/update.architecture",
52
59
  "spec/fixtures/update.blueprint",
53
60
  "spec/fixtures/update.js",
54
61
  "spec/javascripts/application_spec.js",
@@ -62,13 +69,35 @@ Gem::Specification.new do |s|
62
69
  "spec/modjs-architecture_spec.rb",
63
70
  "spec/spec_helper.rb",
64
71
  "spec/templates_spec.rb",
72
+ "spec/tmp/application/myapp.js",
73
+ "spec/tmp/application/test.js",
74
+ "spec/tmp/application/test.module.js",
75
+ "spec/tmp/foo-elements.js",
76
+ "spec/tmp/foo.js",
77
+ "spec/tmp/foo_all.js",
78
+ "spec/tmp/foo_elements.js",
79
+ "spec/tmp/foo_model.js",
80
+ "spec/tmp/lib/mod.js",
81
+ "spec/tmp/modules/test.module.js",
82
+ "spec/tmp/myapp.architecture",
83
+ "spec/tmp/myapp.blueprint",
84
+ "spec/tmp/spec/application_spec.js",
85
+ "spec/tmp/spec/dom_spec.js",
86
+ "spec/tmp/spec/existence_spec.js",
87
+ "spec/tmp/spec/jasmine/MIT.LICENSE",
88
+ "spec/tmp/spec/jasmine/index.html",
89
+ "spec/tmp/spec/jasmine/jasmine-html.js",
90
+ "spec/tmp/spec/jasmine/jasmine.css",
91
+ "spec/tmp/spec/jasmine/jasmine.js",
92
+ "spec/tmp/spec/jasmine/jasmine_favicon.png",
93
+ "spec/tmp/spec/module_spec.js",
65
94
  "templates/model.js",
66
95
  "templates/module.js"
67
96
  ]
68
97
  s.homepage = "http://github.com/daytonn/modjs-architecture"
69
98
  s.licenses = ["MIT"]
70
99
  s.require_paths = ["lib"]
71
- s.rubygems_version = "1.8.10"
100
+ s.rubygems_version = "1.8.21"
72
101
  s.summary = "Mod.js is an a la carte javascript framework"
73
102
 
74
103
  if s.respond_to? :specification_version then
@@ -0,0 +1,11 @@
1
+ (function(app) {
2
+ var m = app.add_module("foo-elements");
3
+
4
+ //= require "../elements/foo-elements.elements"
5
+
6
+ m.actions = function() {
7
+
8
+ }
9
+
10
+ m.run();
11
+ })(myapp);
File without changes
@@ -0,0 +1,8 @@
1
+ framework: modjs
2
+ src_dir: modules
3
+ build_dir: application
4
+ asset_root: ../
5
+ output: compressed
6
+ dependencies: []
7
+ autoload: []
8
+ name: myapp
@@ -0,0 +1,8 @@
1
+ framework: modjs
2
+ src_dir: modules
3
+ build_dir: application
4
+ asset_root: ../
5
+ output: expanded
6
+ dependencies: ["../modules/test.module"]
7
+ autoload: ["../modules/test.module"]
8
+ name: myapp
@@ -0,0 +1,322 @@
1
+ is_defined = function(suspect) {
2
+ return typeof suspect == "undefined" ? false : true;
3
+ };
4
+
5
+ is_undefined = function(suspect) {
6
+ return typeof suspect == "undefined" ? true : false;
7
+ };
8
+
9
+ is_typeof = function(type, suspect) {
10
+ if (is_undefined(type)) {
11
+ throw new Error("is_typeof(Type, suspect): type is undefined");
12
+ }
13
+
14
+ if (is_undefined(suspect)) {
15
+ throw new Error("is_typeof(Type, suspect): suspect is undefined");
16
+ }
17
+
18
+ return suspect.constructor == type ? true : false;
19
+ };
20
+
21
+ is_numeric = function(suspect) {
22
+ if (isNaN(suspect)) {
23
+ return false;
24
+ }
25
+ return !isNaN(parseFloat(suspect)) && isFinite(suspect);
26
+ };
27
+
28
+ is_string = function(suspect) {
29
+ return is_typeof(String, suspect);
30
+ };
31
+
32
+ is_array = function(suspect) {
33
+ return is_typeof(Array, suspect);
34
+ };
35
+
36
+ is_number = function(suspect) {
37
+ return is_typeof(Number, suspect);
38
+ };
39
+
40
+ is_date = function(suspect) {
41
+ return is_typeof(Date, suspect);
42
+ };
43
+
44
+ is_bool = function(suspect) {
45
+ return is_typeof(Boolean, suspect);
46
+ };
47
+
48
+ is_regex = function(suspect) {
49
+ return is_typeof(RegExp, suspect);
50
+ };
51
+
52
+ is_empty = function(suspect) {
53
+ if (is_undefined(suspect)) {
54
+ return true;
55
+ }
56
+
57
+ return suspect.length === 0;
58
+ };
59
+
60
+ is_not_empty = function(suspect) {
61
+ return suspect.length >= 1;
62
+ };
63
+ if (!Element.prototype.addEventListener) {
64
+ var oListeners = {};
65
+
66
+ function runListeners(oEvent) {
67
+ if (!oEvent) {
68
+ oEvent = window.event;
69
+ }
70
+
71
+ for (var iLstId = 0, iElId = 0, oEvtListeners = oListeners[oEvent.type]; iElId < oEvtListeners.aEls.length; iElId++) {
72
+ if (oEvtListeners.aEls[iElId] === this) {
73
+ for (iLstId; iLstId < oEvtListeners.aEvts[iElId].length; iLstId++) {
74
+ oEvtListeners.aEvts[iElId][iLstId].call(this, oEvent);
75
+ }
76
+
77
+ break;
78
+ }
79
+ }
80
+ }
81
+
82
+ Element.prototype.addEventListener = function (sEventType, fListener) {
83
+ if (oListeners.hasOwnProperty(sEventType)) {
84
+ var oEvtListeners = oListeners[sEventType];
85
+
86
+ for (var nElIdx = -1, iElId = 0; iElId < oEvtListeners.aEls.length; iElId++) {
87
+ if (oEvtListeners.aEls[iElId] === this) {
88
+ nElIdx = iElId; break;
89
+ }
90
+ }
91
+
92
+ if (nElIdx === -1) {
93
+ oEvtListeners.aEls.push(this);
94
+ oEvtListeners.aEvts.push([fListener]);
95
+ this["on" + sEventType] = runListeners;
96
+ }
97
+ else {
98
+ var aElListeners = oEvtListeners.aEvts[nElIdx];
99
+
100
+ if (this["on" + sEventType] !== runListeners) {
101
+ aElListeners.splice(0);
102
+ this["on" + sEventType] = runListeners;
103
+ }
104
+
105
+ for (var iLstId = 0; iLstId < aElListeners.length; iLstId++) {
106
+ if (aElListeners[iLstId] === fListener) {
107
+ return;
108
+ }
109
+ }
110
+
111
+ aElListeners.push(fListener);
112
+ }
113
+ }
114
+ else {
115
+ oListeners[sEventType] = {
116
+ aEls: [this],
117
+ aEvts: [[fListener]]
118
+ };
119
+
120
+ this["on" + sEventType] = runListeners;
121
+ }
122
+ };
123
+
124
+ Element.prototype.removeEventListener = function (sEventType) {
125
+ if (!oListeners.hasOwnProperty(sEventType)) {
126
+ return;
127
+ }
128
+
129
+ var oEvtListeners = oListeners[sEventType];
130
+
131
+ for (var nElIdx = -1, iElId = 0; iElId < oEvtListeners.aEls.length; iElId++) {
132
+ if (oEvtListeners.aEls[iElId] === this) {
133
+ nElIdx = iElId;
134
+ break;
135
+ }
136
+ }
137
+
138
+ if (nElIdx === -1) {
139
+ return;
140
+ }
141
+
142
+ for (var iLstId = 0, aElListeners = oEvtListeners.aEvts[nElIdx]; iLstId < aElListeners.length; iLstId++) {
143
+ aElListeners.splice(iLstId, 1);
144
+ }
145
+ };
146
+ }
147
+
148
+ var Mod = {};
149
+
150
+ Mod.DOM = (function() {
151
+
152
+ var timer,
153
+ queue = [];
154
+
155
+ function DOM() {
156
+ this.cache = {};
157
+ this.is_ready = false;
158
+ }
159
+
160
+ DOM.prototype.add_event = function(element, type, fn, capture) {
161
+ if (is_undefined(capture)) {
162
+ capture = false;
163
+ }
164
+
165
+ if (is_string(element)) {
166
+ element = this.cache[element];
167
+ }
168
+
169
+ element.addEventListener(type, fn, capture);
170
+ };
171
+
172
+ DOM.prototype.remove_event = function(element, type, fn, capture) {
173
+ if (is_undefined(capture)) {
174
+ capture = false;
175
+ }
176
+
177
+ if (is_string(element)) {
178
+ element = this.cache[element];
179
+ }
180
+
181
+ element.removeEventListener(type, fn, capture);
182
+ };
183
+
184
+ DOM.prototype.call_when_ready = function(func) {
185
+ if (this.is_ready) {
186
+ return func();
187
+ }
188
+
189
+ if (timer) {
190
+ queue.push(func);
191
+ }
192
+ else {
193
+ this.add_event(window, 'load', this.execute_ready_queue);
194
+ queue.push(func);
195
+ timer = setInterval(this.execute_ready_queue, 13);
196
+ }
197
+ };
198
+
199
+ DOM.prototype.execute_ready_queue = function() {
200
+ if (this.is_ready) {
201
+ return false;
202
+ }
203
+
204
+ if (document && document.getElementsByTagName && document.getElementById && document.body) {
205
+ clearInterval(timer);
206
+ timer = null;
207
+ for(var i = 0, j = queue.length; i < j; i++) {
208
+ queue[i]();
209
+ }
210
+
211
+ queue = [];
212
+ this.is_ready = true;
213
+ }
214
+ };
215
+
216
+ DOM.prototype.add_elements = function(elements) {
217
+ for(var key in elements) {
218
+ if (elements.hasOwnProperty(key)) {
219
+ this.add_element(key, elements[key]);
220
+ }
221
+ }
222
+ };
223
+
224
+ DOM.prototype.add_element = function(key, element) {
225
+ this.cache[key] = element;
226
+ };
227
+
228
+ return DOM;
229
+ })();
230
+ Mod.Module = (function() {
231
+
232
+ function Module(name) {
233
+ if (is_undefined(name)) {
234
+ throw new Error("Mod.Module(name): name is undefined");
235
+ }
236
+
237
+ this.dom = new Mod.DOM;
238
+ this.data = {};
239
+ this.name = name;
240
+ }
241
+
242
+ Module.prototype.actions = function() {};
243
+
244
+ Module.prototype.run = function() {
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();
253
+ };
254
+
255
+ Module.prototype.elements = function(elements) {
256
+ if (is_undefined(elements)) {
257
+ return this.dom.cache;
258
+ }
259
+
260
+ if (is_string(elements)) {
261
+ var name = elements;
262
+ return this.dom.cache[name];
263
+ }
264
+ else {
265
+ this.dom.add_elements(elements);
266
+ }
267
+ };
268
+
269
+ Module.prototype.set_data = function(key, value) {
270
+ if (is_undefined(key)) {
271
+ throw new Error(this.name + '.set_data(key, value): key is undefined');
272
+ }
273
+
274
+ if (is_typeof(String, key) && is_undefined(value)) {
275
+ throw new SyntaxError(this.name + 'Module.set_data(key, value): value is undefined');
276
+ }
277
+
278
+ if (is_typeof(String, key)) {
279
+ this.data[key] = value;
280
+ }
281
+ else if (is_typeof(Object, key)) {
282
+ var data = key;
283
+ for(var property in data) {
284
+ this.data[property] = data[property];
285
+ }
286
+ }
287
+
288
+ return this;
289
+ };
290
+
291
+ return Module;
292
+ })();
293
+ Mod.Application = (function() {
294
+
295
+ function Application(name) {
296
+ if (is_undefined(name)) {
297
+ throw new Error("new Mod.Application(name): name is undefined");
298
+ }
299
+
300
+ this.name = name
301
+ };
302
+
303
+ Application.prototype.add_module = function(name) {
304
+ if (is_undefined(name)) {
305
+ throw new Error("Mod.Application.add_module(name): name is undefined");
306
+ }
307
+
308
+ if (is_defined(this[name])) {
309
+ throw new Error("Mod.Application.add_module('" + name + "'): '" + name + "' already declared");
310
+ }
311
+
312
+ if (this.name === name) {
313
+ throw new Error("Mod.Application.add_module('" + name + "'): a module cannot have the same name as the application. It's bad idea. Do you really want to write " + name + "." + name + "? It's confusing.'");
314
+ }
315
+
316
+ return this[name] = new Mod.Module(name);
317
+ };
318
+
319
+ return Application;
320
+ })();
321
+
322
+ var myapp = new Mod.Application('myapp');