micro-rails 0.1.0.pre.alpha4 → 0.1.0.pre.alpha5
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.
- checksums.yaml +4 -4
- data/lib/micro/rails/version.rb +2 -2
- data/vendor/assets/javascripts/micro.js +1 -882
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a27a44bf4d1565a98df7e4806cebf4cc9108d317
|
4
|
+
data.tar.gz: ef6d95d799d484c1c06acf90401405250559c53a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52bd0da0d0f3fc89eacfe4979dbb70577f6082d2adb4a7fda4ba49203b0f604b733d42677a391db21175373a5fa0f4adaec7a3bd615dc219b95a77f338d32d12
|
7
|
+
data.tar.gz: 6c6fb30a16f14be37ff741f1640d91626f61735772a31ac0d34ebb3d23db8ca63949f130b3bcb31c3cb7d65761b49988f1d5044fabc4595e69b584b0ad9c7b2d
|
data/lib/micro/rails/version.rb
CHANGED
@@ -1,882 +1 @@
|
|
1
|
-
|
2
|
-
(function() {
|
3
|
-
var Component, Factory, Module, Namespace, Unit, factory, splitOnce, splitUnitName, µ,
|
4
|
-
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
5
|
-
__hasProp = {}.hasOwnProperty,
|
6
|
-
__slice = [].slice;
|
7
|
-
|
8
|
-
splitOnce = function(string, char) {
|
9
|
-
var splits;
|
10
|
-
splits = string.split(char);
|
11
|
-
return [splits.shift(), splits.join(char)];
|
12
|
-
};
|
13
|
-
|
14
|
-
splitUnitName = function(name) {
|
15
|
-
var label, namespace, _ref;
|
16
|
-
_ref = splitOnce(name, '.'), namespace = _ref[0], label = _ref[1];
|
17
|
-
if (!label) {
|
18
|
-
label = namespace;
|
19
|
-
namespace = factory.config.defaultNamespace;
|
20
|
-
}
|
21
|
-
return [namespace, label];
|
22
|
-
};
|
23
|
-
|
24
|
-
Factory = (function() {
|
25
|
-
function Factory() {
|
26
|
-
this.config = {
|
27
|
-
defaultNamespace: 'app',
|
28
|
-
dataPrefix: 'micro',
|
29
|
-
methodPrefix: 'µ'
|
30
|
-
};
|
31
|
-
this._namespaces = {};
|
32
|
-
this._initialize = [];
|
33
|
-
this._destroy = [];
|
34
|
-
}
|
35
|
-
|
36
|
-
Factory.prototype.configure = function(config) {
|
37
|
-
return _.extend(this.config, config);
|
38
|
-
};
|
39
|
-
|
40
|
-
Factory.prototype.setup = function(setup) {
|
41
|
-
return setup.call({
|
42
|
-
initialize: (function(_this) {
|
43
|
-
return function(initialize) {
|
44
|
-
return _this._initialize.push(initialize);
|
45
|
-
};
|
46
|
-
})(this),
|
47
|
-
destroy: (function(_this) {
|
48
|
-
return function(destroy) {
|
49
|
-
return _this._destroy.unshift(destroy);
|
50
|
-
};
|
51
|
-
})(this),
|
52
|
-
component: (function(_this) {
|
53
|
-
return function(name, selector, config) {
|
54
|
-
var Component;
|
55
|
-
if (!(_.isString(selector) || _.isElement(selector))) {
|
56
|
-
config = selector;
|
57
|
-
selector = null;
|
58
|
-
}
|
59
|
-
Component = _this.component(name);
|
60
|
-
selector || (selector = Component.config.defaultSelector);
|
61
|
-
if (!selector) {
|
62
|
-
throw new Error('you must provide a selector or define' + ' defaultSelector in the component configuration');
|
63
|
-
}
|
64
|
-
_this._initialize.push(function() {
|
65
|
-
Component.initialize(this.filter(selector), config);
|
66
|
-
return Component.initialize(this.find(selector), config);
|
67
|
-
});
|
68
|
-
return _this._destroy.unshift(function() {
|
69
|
-
Component.destroy(this.filter(selector));
|
70
|
-
return Component.destroy(this.find(selector));
|
71
|
-
});
|
72
|
-
};
|
73
|
-
})(this)
|
74
|
-
});
|
75
|
-
};
|
76
|
-
|
77
|
-
Factory.prototype.initialize = function(el) {
|
78
|
-
var $el, initialize, _i, _len, _ref, _results;
|
79
|
-
if (el) {
|
80
|
-
$el = $(el);
|
81
|
-
} else {
|
82
|
-
$el = $(document);
|
83
|
-
}
|
84
|
-
_ref = this._initialize;
|
85
|
-
_results = [];
|
86
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
87
|
-
initialize = _ref[_i];
|
88
|
-
_results.push(initialize.call($el));
|
89
|
-
}
|
90
|
-
return _results;
|
91
|
-
};
|
92
|
-
|
93
|
-
Factory.prototype.destroy = function(el) {
|
94
|
-
var $el, destroy, _i, _len, _ref, _results;
|
95
|
-
if (el) {
|
96
|
-
$el = $(el);
|
97
|
-
} else {
|
98
|
-
$el = $(this.config.rootElement);
|
99
|
-
}
|
100
|
-
_ref = this._destroy;
|
101
|
-
_results = [];
|
102
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
103
|
-
destroy = _ref[_i];
|
104
|
-
_results.push(destroy.call($el));
|
105
|
-
}
|
106
|
-
return _results;
|
107
|
-
};
|
108
|
-
|
109
|
-
Factory.prototype.clean = function() {
|
110
|
-
µ.destroy();
|
111
|
-
this._namespaces = {};
|
112
|
-
this._initialize = [];
|
113
|
-
return this._destroy = [];
|
114
|
-
};
|
115
|
-
|
116
|
-
Factory.prototype.namespace = function(label, doNotRaise) {
|
117
|
-
var namespace;
|
118
|
-
if (doNotRaise == null) {
|
119
|
-
doNotRaise = false;
|
120
|
-
}
|
121
|
-
if (!((namespace = this._namespaces[label]) || doNotRaise)) {
|
122
|
-
throw new Error("could not find namespace " + label);
|
123
|
-
}
|
124
|
-
return namespace;
|
125
|
-
};
|
126
|
-
|
127
|
-
Factory.prototype.component = function(name, doNotRaise) {
|
128
|
-
var label, namespace, _ref;
|
129
|
-
if (doNotRaise == null) {
|
130
|
-
doNotRaise = false;
|
131
|
-
}
|
132
|
-
_ref = splitUnitName(name), namespace = _ref[0], label = _ref[1];
|
133
|
-
return this.namespace(namespace, doNotRaise).component(label, doNotRaise);
|
134
|
-
};
|
135
|
-
|
136
|
-
Factory.prototype.module = function(name, doNotRaise) {
|
137
|
-
var label, namespace, _ref;
|
138
|
-
if (doNotRaise == null) {
|
139
|
-
doNotRaise = false;
|
140
|
-
}
|
141
|
-
_ref = splitUnitName(name), namespace = _ref[0], label = _ref[1];
|
142
|
-
return this.namespace(namespace, doNotRaise).module(label, doNotRaise);
|
143
|
-
};
|
144
|
-
|
145
|
-
Factory.prototype.createNamespace = function(label) {
|
146
|
-
if (this._namespaces[label]) {
|
147
|
-
throw new Error("namespace " + label + " already exists");
|
148
|
-
}
|
149
|
-
return this._namespaces[label] = new Namespace(this, label);
|
150
|
-
};
|
151
|
-
|
152
|
-
Factory.prototype.data = function(el, name, value) {
|
153
|
-
if (arguments.length < 3) {
|
154
|
-
return $(el).data(this._dataName(name));
|
155
|
-
} else {
|
156
|
-
return $(el).data(this._dataName(name), value);
|
157
|
-
}
|
158
|
-
};
|
159
|
-
|
160
|
-
Factory.prototype.removeData = function(el, name) {
|
161
|
-
return $(el).removeData(this._dataName(name));
|
162
|
-
};
|
163
|
-
|
164
|
-
Factory.prototype._dataName = function(name) {
|
165
|
-
return this.config.dataPrefix + "-" + name;
|
166
|
-
};
|
167
|
-
|
168
|
-
return Factory;
|
169
|
-
|
170
|
-
})();
|
171
|
-
|
172
|
-
Namespace = (function() {
|
173
|
-
Namespace.labelFormat = /^[a-z][a-zA-Z0-9]*$/;
|
174
|
-
|
175
|
-
Namespace.prototype.µObject = function() {
|
176
|
-
return {
|
177
|
-
configure: (function(_this) {
|
178
|
-
return function(config) {
|
179
|
-
_this.configure(config);
|
180
|
-
return _this.µObject();
|
181
|
-
};
|
182
|
-
})(this)
|
183
|
-
};
|
184
|
-
};
|
185
|
-
|
186
|
-
function Namespace(_at_factory, _at_label) {
|
187
|
-
this.factory = _at_factory;
|
188
|
-
this.label = _at_label;
|
189
|
-
if (!this.label.match(this.constructor.labelFormat)) {
|
190
|
-
throw new Error(this.label + " is not a valid namespace name");
|
191
|
-
}
|
192
|
-
this._components = {};
|
193
|
-
this._modules = {};
|
194
|
-
this.config = {};
|
195
|
-
}
|
196
|
-
|
197
|
-
Namespace.prototype.configure = function(config) {
|
198
|
-
if (config == null) {
|
199
|
-
config = {};
|
200
|
-
}
|
201
|
-
return _.extend(this.config, config);
|
202
|
-
};
|
203
|
-
|
204
|
-
Namespace.prototype.component = function(label, doNotRaise) {
|
205
|
-
var Component;
|
206
|
-
if (doNotRaise == null) {
|
207
|
-
doNotRaise = false;
|
208
|
-
}
|
209
|
-
if (!((Component = this._components[label]) || doNotRaise)) {
|
210
|
-
throw new Error("component " + label + " could not be found in namespace " + this.name);
|
211
|
-
}
|
212
|
-
return Component;
|
213
|
-
};
|
214
|
-
|
215
|
-
Namespace.prototype.module = function(label, doNotRaise) {
|
216
|
-
var Module;
|
217
|
-
if (doNotRaise == null) {
|
218
|
-
doNotRaise = false;
|
219
|
-
}
|
220
|
-
if (!((Module = this._modules[label]) || doNotRaise)) {
|
221
|
-
throw new Error("module " + label + " could not be found in namespace " + this.name);
|
222
|
-
}
|
223
|
-
return Module;
|
224
|
-
};
|
225
|
-
|
226
|
-
Namespace.prototype.addUnit = function(Unit) {
|
227
|
-
var prototype;
|
228
|
-
prototype = Unit.prototype;
|
229
|
-
if (prototype instanceof Component) {
|
230
|
-
return this._addComponent(Unit);
|
231
|
-
} else if (prototype instanceof Module) {
|
232
|
-
return this._addModule(Unit);
|
233
|
-
} else {
|
234
|
-
throw new Error('the unit must be a module or a component');
|
235
|
-
}
|
236
|
-
};
|
237
|
-
|
238
|
-
Namespace.prototype._addComponent = function(Component) {
|
239
|
-
Component.namespace = this;
|
240
|
-
return this._components[Component.label] = Component;
|
241
|
-
};
|
242
|
-
|
243
|
-
Namespace.prototype._addModule = function(Module) {
|
244
|
-
Module.namespace = this;
|
245
|
-
return this._modules[Module.label] = Module;
|
246
|
-
};
|
247
|
-
|
248
|
-
return Namespace;
|
249
|
-
|
250
|
-
})();
|
251
|
-
|
252
|
-
Unit = (function() {
|
253
|
-
Unit.namespace = null;
|
254
|
-
|
255
|
-
Unit.label = null;
|
256
|
-
|
257
|
-
Unit.labelFormat = /^[A-Z][A-Za-z0-9]*$/;
|
258
|
-
|
259
|
-
Unit.config = {};
|
260
|
-
|
261
|
-
Unit._initializeMethods = [];
|
262
|
-
|
263
|
-
Unit._destroyMethods = [];
|
264
|
-
|
265
|
-
Unit.extend = function(options) {
|
266
|
-
var Child, Parent;
|
267
|
-
if (!options.namespace) {
|
268
|
-
throw new Error('you must provide a namespace when creating a component');
|
269
|
-
}
|
270
|
-
if (!options.label) {
|
271
|
-
throw new Error('you must provide a name when creating a component');
|
272
|
-
}
|
273
|
-
if (!options.label.match(this.labelFormat)) {
|
274
|
-
throw new Error(options.label + " is not a valid component name");
|
275
|
-
}
|
276
|
-
Parent = this;
|
277
|
-
Child = (function(_super) {
|
278
|
-
var _destroy, _initialize;
|
279
|
-
|
280
|
-
__extends(Child, _super);
|
281
|
-
|
282
|
-
function Child() {
|
283
|
-
return Child.__super__.constructor.apply(this, arguments);
|
284
|
-
}
|
285
|
-
|
286
|
-
Child.label = options.label;
|
287
|
-
|
288
|
-
Child.config = _.clone(Child.config);
|
289
|
-
|
290
|
-
if (options.config) {
|
291
|
-
_.extend(Child.config, options.config);
|
292
|
-
}
|
293
|
-
|
294
|
-
Child._modules = _.clone(Child._modules);
|
295
|
-
|
296
|
-
if (options.properties) {
|
297
|
-
if (_initialize = options.properties._initialize) {
|
298
|
-
Child._initializeMethods = _.clone(Child._initializeMethods);
|
299
|
-
Child._initializeMethods.push(_initialize);
|
300
|
-
delete options.properties._initialize;
|
301
|
-
}
|
302
|
-
if (_destroy = options.properties._destroy) {
|
303
|
-
Child._destroyMethods = _.clone(Child._destroyMethods);
|
304
|
-
Child._destroyMethods.unshift(_destroy);
|
305
|
-
delete options.properties._destroy;
|
306
|
-
}
|
307
|
-
_.extend(Child.prototype, options.properties);
|
308
|
-
}
|
309
|
-
|
310
|
-
return Child;
|
311
|
-
|
312
|
-
})(Parent);
|
313
|
-
return options.namespace.addUnit(Child);
|
314
|
-
};
|
315
|
-
|
316
|
-
Unit.configure = function(config) {
|
317
|
-
_.extend(this.config, config);
|
318
|
-
return this.µObject();
|
319
|
-
};
|
320
|
-
|
321
|
-
Unit.fullName = function() {
|
322
|
-
return this.namespace.label + "-" + this.label;
|
323
|
-
};
|
324
|
-
|
325
|
-
function Unit(_at_config) {
|
326
|
-
var initialize, method, name, _i, _len, _ref, _ref1;
|
327
|
-
this.config = _at_config != null ? _at_config : {};
|
328
|
-
if (this.constructor.__super__) {
|
329
|
-
this["super"] = {};
|
330
|
-
_ref = this.constructor.__super__;
|
331
|
-
for (name in _ref) {
|
332
|
-
method = _ref[name];
|
333
|
-
this["super"][name] = _.bind(method, this);
|
334
|
-
}
|
335
|
-
}
|
336
|
-
_.defaults(this.config, this.constructor.config, this.constructor.namespace.config);
|
337
|
-
_ref1 = this.constructor._initializeMethods;
|
338
|
-
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
339
|
-
initialize = _ref1[_i];
|
340
|
-
initialize.call(this);
|
341
|
-
}
|
342
|
-
}
|
343
|
-
|
344
|
-
Unit.prototype.destroy = function() {
|
345
|
-
var destroy, _i, _len, _ref, _results;
|
346
|
-
_ref = this.constructor._destroyMethods;
|
347
|
-
_results = [];
|
348
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
349
|
-
destroy = _ref[_i];
|
350
|
-
_results.push(destroy.call(this));
|
351
|
-
}
|
352
|
-
return _results;
|
353
|
-
};
|
354
|
-
|
355
|
-
return Unit;
|
356
|
-
|
357
|
-
})();
|
358
|
-
|
359
|
-
Component = (function(_super) {
|
360
|
-
__extends(Component, _super);
|
361
|
-
|
362
|
-
Component._modules = {};
|
363
|
-
|
364
|
-
Component.µObject = function(options) {
|
365
|
-
var prototype;
|
366
|
-
prototype = this.prototype;
|
367
|
-
if (prototype instanceof Component) {
|
368
|
-
return {
|
369
|
-
configure: (function(_this) {
|
370
|
-
return function(config) {
|
371
|
-
return _this.configure(config);
|
372
|
-
};
|
373
|
-
})(this),
|
374
|
-
initialize: (function(_this) {
|
375
|
-
return function(el, config) {
|
376
|
-
return _this.initialize(el, config);
|
377
|
-
};
|
378
|
-
})(this),
|
379
|
-
instance: (function(_this) {
|
380
|
-
return function(el) {
|
381
|
-
return _this.instance(el);
|
382
|
-
};
|
383
|
-
})(this),
|
384
|
-
destroy: (function(_this) {
|
385
|
-
return function(el) {
|
386
|
-
return _this.destroy(el);
|
387
|
-
};
|
388
|
-
})(this)
|
389
|
-
};
|
390
|
-
} else {
|
391
|
-
return {
|
392
|
-
extend: (function(_this) {
|
393
|
-
return function(componentName) {
|
394
|
-
options.extend = factory.component(componentName);
|
395
|
-
return _this.µObject(options);
|
396
|
-
};
|
397
|
-
})(this),
|
398
|
-
module: (function(_this) {
|
399
|
-
return function(moduleName) {
|
400
|
-
if (options.modules) {
|
401
|
-
options.modules.push(moduleName);
|
402
|
-
} else {
|
403
|
-
options.modules = [moduleName];
|
404
|
-
}
|
405
|
-
return _this.µObject(options);
|
406
|
-
};
|
407
|
-
})(this),
|
408
|
-
configure: (function(_this) {
|
409
|
-
return function(config) {
|
410
|
-
if (options.config) {
|
411
|
-
_.extend(options.config, config);
|
412
|
-
} else {
|
413
|
-
options.config = config;
|
414
|
-
}
|
415
|
-
return _this.µObject(options);
|
416
|
-
};
|
417
|
-
})(this),
|
418
|
-
create: (function(_this) {
|
419
|
-
return function(properties) {
|
420
|
-
var Parent;
|
421
|
-
options.properties = properties;
|
422
|
-
Parent = options.extend || _this;
|
423
|
-
return Parent.extend(options);
|
424
|
-
};
|
425
|
-
})(this)
|
426
|
-
};
|
427
|
-
}
|
428
|
-
};
|
429
|
-
|
430
|
-
Component.extend = function(options) {
|
431
|
-
var Child, moduleName, _i, _len, _ref;
|
432
|
-
Child = Component.__super__.constructor.extend.call(this, options);
|
433
|
-
if (options.modules) {
|
434
|
-
_ref = options.modules;
|
435
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
436
|
-
moduleName = _ref[_i];
|
437
|
-
Child.include(moduleName);
|
438
|
-
}
|
439
|
-
}
|
440
|
-
return Child.µObject();
|
441
|
-
};
|
442
|
-
|
443
|
-
Component.include = function(moduleName) {
|
444
|
-
var Module;
|
445
|
-
Module = this.namespace.factory.module(moduleName);
|
446
|
-
if (this._modules[Module.fullName()]) {
|
447
|
-
throw new Error("module " + Module.namespace + "." + Module.label + " is already included");
|
448
|
-
}
|
449
|
-
this._modules[Module.fullName()] = Module;
|
450
|
-
return Module.included(this);
|
451
|
-
};
|
452
|
-
|
453
|
-
Component.initialize = function(el, config) {
|
454
|
-
var instances;
|
455
|
-
instances = [];
|
456
|
-
$(el).each((function(_this) {
|
457
|
-
return function(i, el) {
|
458
|
-
return instances.push(new _this($(el), config));
|
459
|
-
};
|
460
|
-
})(this));
|
461
|
-
return this._methods(instances);
|
462
|
-
};
|
463
|
-
|
464
|
-
Component.instance = function(el) {
|
465
|
-
var instances;
|
466
|
-
instances = $(el).map((function(_this) {
|
467
|
-
return function(i, el) {
|
468
|
-
return _this._instance($(el));
|
469
|
-
};
|
470
|
-
})(this)).get();
|
471
|
-
return this._methods(instances);
|
472
|
-
};
|
473
|
-
|
474
|
-
Component.destroy = function(el, config) {
|
475
|
-
$(el).each((function(_this) {
|
476
|
-
return function(i, el) {
|
477
|
-
return _this._instance($(el)).destroy();
|
478
|
-
};
|
479
|
-
})(this));
|
480
|
-
return this.µObject();
|
481
|
-
};
|
482
|
-
|
483
|
-
Component._methods = function(instances) {
|
484
|
-
var methodName, methodNames, methods, prefix, _fn, _i, _len;
|
485
|
-
prefix = this.namespace.factory.config.methodPrefix;
|
486
|
-
methodNames = _.chain(this.prototype).functions().filter(function(name) {
|
487
|
-
return name.match(new RegExp("^" + prefix + "[A-Z]"));
|
488
|
-
}).value();
|
489
|
-
methods = {};
|
490
|
-
_fn = function(oldName) {
|
491
|
-
var newName;
|
492
|
-
newName = methodName[prefix.length].toLowerCase() + methodName.slice(prefix.length + 1);
|
493
|
-
return methods[newName] = function() {
|
494
|
-
var args, lastResult, results;
|
495
|
-
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
496
|
-
results = _.invoke.apply(_, [instances, oldName].concat(__slice.call(args)));
|
497
|
-
lastResult = results.pop();
|
498
|
-
if (_.isNull(lastResult)) {
|
499
|
-
return methods;
|
500
|
-
} else {
|
501
|
-
return lastResult;
|
502
|
-
}
|
503
|
-
};
|
504
|
-
};
|
505
|
-
for (_i = 0, _len = methodNames.length; _i < _len; _i++) {
|
506
|
-
methodName = methodNames[_i];
|
507
|
-
_fn(methodName);
|
508
|
-
}
|
509
|
-
methods.destroy = (function(_this) {
|
510
|
-
return function() {
|
511
|
-
_.invoke(instances, 'destroy');
|
512
|
-
return _this.µObject();
|
513
|
-
};
|
514
|
-
})(this);
|
515
|
-
return methods;
|
516
|
-
};
|
517
|
-
|
518
|
-
Component._instance = function($el) {
|
519
|
-
var components;
|
520
|
-
components = this.namespace.factory.data($el, 'components') || {};
|
521
|
-
if (!components[this.fullName()]) {
|
522
|
-
throw new Error('component is not initialized');
|
523
|
-
}
|
524
|
-
return components[this.fullName()];
|
525
|
-
};
|
526
|
-
|
527
|
-
function Component(_at_$el, config) {
|
528
|
-
var Module, components, factory, moduleName, name, _ref;
|
529
|
-
this.$el = _at_$el;
|
530
|
-
factory = this.constructor.namespace.factory;
|
531
|
-
components = factory.data(this.$el, 'components') || {};
|
532
|
-
name = this.constructor.fullName();
|
533
|
-
if (components[name]) {
|
534
|
-
throw new Error('component is already initialized');
|
535
|
-
}
|
536
|
-
components[name] = this;
|
537
|
-
factory.data(this.$el, 'components', components);
|
538
|
-
this._uniqueId = _.uniqueId((this.constructor.fullName()) + "-");
|
539
|
-
this._listeners = $();
|
540
|
-
this._dataFull = $();
|
541
|
-
this._dataNames = [];
|
542
|
-
Component.__super__.constructor.call(this, config);
|
543
|
-
this._moduleInstances = {};
|
544
|
-
_ref = this.constructor._modules;
|
545
|
-
for (moduleName in _ref) {
|
546
|
-
Module = _ref[moduleName];
|
547
|
-
this._moduleInstances[moduleName] = new Module(this, this.config);
|
548
|
-
}
|
549
|
-
}
|
550
|
-
|
551
|
-
Component.prototype.destroy = function() {
|
552
|
-
var components, dataName, factory, moduleInstance, moduleName, _i, _len, _ref, _ref1;
|
553
|
-
Component.__super__.destroy.apply(this, arguments);
|
554
|
-
_ref = this._moduleInstances;
|
555
|
-
for (moduleName in _ref) {
|
556
|
-
moduleInstance = _ref[moduleName];
|
557
|
-
moduleInstance.destroy();
|
558
|
-
}
|
559
|
-
factory = this.constructor.namespace.factory;
|
560
|
-
this._listeners.off("." + this._uniqueId);
|
561
|
-
_ref1 = this._dataNames;
|
562
|
-
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
563
|
-
dataName = _ref1[_i];
|
564
|
-
factory.removeData(this._dataFull, dataName);
|
565
|
-
}
|
566
|
-
components = factory.data(this.$el, 'components');
|
567
|
-
delete components[this.constructor.fullName()];
|
568
|
-
return factory.data(this.$el, 'components', components);
|
569
|
-
};
|
570
|
-
|
571
|
-
Component.prototype.$ = function(selector) {
|
572
|
-
return this.$el.find(selector);
|
573
|
-
};
|
574
|
-
|
575
|
-
Component.prototype.on = function(el, handlers) {
|
576
|
-
var $el, event, handler, selector, type, _ref, _results;
|
577
|
-
if (!handlers) {
|
578
|
-
handlers = el;
|
579
|
-
$el = this.$el;
|
580
|
-
} else {
|
581
|
-
$el = $(el);
|
582
|
-
}
|
583
|
-
this._listeners = this._listeners.add($el);
|
584
|
-
_results = [];
|
585
|
-
for (event in handlers) {
|
586
|
-
handler = handlers[event];
|
587
|
-
_ref = splitOnce(event, ' '), type = _ref[0], selector = _ref[1];
|
588
|
-
type = type + "." + this._uniqueId;
|
589
|
-
if (_.isString(handler)) {
|
590
|
-
(function(_this) {
|
591
|
-
return (function(method) {
|
592
|
-
return handler = function() {
|
593
|
-
var args;
|
594
|
-
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
595
|
-
return _this[method].apply(_this, args);
|
596
|
-
};
|
597
|
-
});
|
598
|
-
})(this)(handler);
|
599
|
-
}
|
600
|
-
if (selector) {
|
601
|
-
_results.push($el.on(type, selector, handler));
|
602
|
-
} else {
|
603
|
-
_results.push($el.on(type, handler));
|
604
|
-
}
|
605
|
-
}
|
606
|
-
return _results;
|
607
|
-
};
|
608
|
-
|
609
|
-
Component.prototype.off = function(el, eventType) {
|
610
|
-
var $el;
|
611
|
-
if (arguments.length < 2 && _.isString(el) || _.isUndefined(el)) {
|
612
|
-
eventType = el;
|
613
|
-
$el = this.$el;
|
614
|
-
} else {
|
615
|
-
$el = $(el);
|
616
|
-
}
|
617
|
-
if (eventType) {
|
618
|
-
return $el.off(eventType + "." + this._uniqueId);
|
619
|
-
} else {
|
620
|
-
return $el.off("." + this._uniqueId);
|
621
|
-
}
|
622
|
-
};
|
623
|
-
|
624
|
-
Component.prototype.trigger = function() {
|
625
|
-
var componentLabel, eventType, namespace, namespaceLabel, params, _ref;
|
626
|
-
eventType = arguments[0], params = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
627
|
-
namespaceLabel = this.constructor.namespace.label.toLowerCase();
|
628
|
-
componentLabel = this.constructor.label.toLowerCase();
|
629
|
-
namespace = namespaceLabel + ":" + componentLabel;
|
630
|
-
return (_ref = this.$el).trigger.apply(_ref, [namespace + ":" + eventType].concat(__slice.call(params)));
|
631
|
-
};
|
632
|
-
|
633
|
-
Component.prototype.data = function(el, name, value) {
|
634
|
-
var factory;
|
635
|
-
if (arguments.length < 3 && _.isString(el)) {
|
636
|
-
value = name;
|
637
|
-
name = el;
|
638
|
-
el = this.$el;
|
639
|
-
}
|
640
|
-
factory = this.constructor.namespace.factory;
|
641
|
-
name = this._dataName(name);
|
642
|
-
if (_.isUndefined(value)) {
|
643
|
-
return factory.data(el, name);
|
644
|
-
} else {
|
645
|
-
factory.data(el, name, value);
|
646
|
-
this._dataFull.add(el);
|
647
|
-
return this._dataNames.push(name);
|
648
|
-
}
|
649
|
-
};
|
650
|
-
|
651
|
-
Component.prototype.removeData = function(el, name) {
|
652
|
-
var factory;
|
653
|
-
if (arguments.length < 2) {
|
654
|
-
name = el;
|
655
|
-
el = this.$el;
|
656
|
-
}
|
657
|
-
factory = this.constructor.namespace.factory;
|
658
|
-
name = this._dataName(name);
|
659
|
-
return factory.removeData(el, name);
|
660
|
-
};
|
661
|
-
|
662
|
-
Component.prototype._dataName = function(name) {
|
663
|
-
return this._uniqueId + "-" + name;
|
664
|
-
};
|
665
|
-
|
666
|
-
return Component;
|
667
|
-
|
668
|
-
})(Unit);
|
669
|
-
|
670
|
-
Module = (function(_super) {
|
671
|
-
var componentMethod, delegatedMethods, _fn, _i, _len;
|
672
|
-
|
673
|
-
__extends(Module, _super);
|
674
|
-
|
675
|
-
Module._extensions = {};
|
676
|
-
|
677
|
-
Module.µObject = function(options) {
|
678
|
-
var prototype;
|
679
|
-
prototype = this.prototype;
|
680
|
-
if (prototype instanceof Module) {
|
681
|
-
return {
|
682
|
-
configure: (function(_this) {
|
683
|
-
return function(config) {
|
684
|
-
return _this.configure(config);
|
685
|
-
};
|
686
|
-
})(this)
|
687
|
-
};
|
688
|
-
} else {
|
689
|
-
return {
|
690
|
-
configure: (function(_this) {
|
691
|
-
return function(config) {
|
692
|
-
options.config = config;
|
693
|
-
return _this.µObject(options);
|
694
|
-
};
|
695
|
-
})(this),
|
696
|
-
extend: (function(_this) {
|
697
|
-
return function(moduleName) {
|
698
|
-
options.extend = factory.module(moduleName);
|
699
|
-
return _this.µObject(options);
|
700
|
-
};
|
701
|
-
})(this),
|
702
|
-
extensions: (function(_this) {
|
703
|
-
return function(extensions) {
|
704
|
-
options.extensions = extensions;
|
705
|
-
return _this.µObject(options);
|
706
|
-
};
|
707
|
-
})(this),
|
708
|
-
create: (function(_this) {
|
709
|
-
return function(properties) {
|
710
|
-
var Parent;
|
711
|
-
options.properties = properties;
|
712
|
-
Parent = options.extend || _this;
|
713
|
-
return Parent.extend(options);
|
714
|
-
};
|
715
|
-
})(this)
|
716
|
-
};
|
717
|
-
}
|
718
|
-
};
|
719
|
-
|
720
|
-
Module.extend = function(options) {
|
721
|
-
var Child;
|
722
|
-
Child = Module.__super__.constructor.extend.call(this, options);
|
723
|
-
if (options.extensions) {
|
724
|
-
_.extend(Child._extensions, options.extensions);
|
725
|
-
}
|
726
|
-
return Child.µObject();
|
727
|
-
};
|
728
|
-
|
729
|
-
Module.included = function(Component) {
|
730
|
-
var extension, fullName, name, _ref, _results;
|
731
|
-
fullName = this.fullName();
|
732
|
-
_ref = this._extensions;
|
733
|
-
_results = [];
|
734
|
-
for (name in _ref) {
|
735
|
-
extension = _ref[name];
|
736
|
-
_results.push((function(extension) {
|
737
|
-
return Component.prototype[name] = function() {
|
738
|
-
var args, instance;
|
739
|
-
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
740
|
-
instance = this._moduleInstances[fullName];
|
741
|
-
return extension.apply(instance, args);
|
742
|
-
};
|
743
|
-
})(extension));
|
744
|
-
}
|
745
|
-
return _results;
|
746
|
-
};
|
747
|
-
|
748
|
-
function Module(_at_component, config) {
|
749
|
-
this.component = _at_component;
|
750
|
-
this.$el = this.component.$el;
|
751
|
-
Module.__super__.constructor.call(this, config);
|
752
|
-
}
|
753
|
-
|
754
|
-
Module.prototype.on = function(el, handlers) {
|
755
|
-
var event, handler;
|
756
|
-
if (!handlers) {
|
757
|
-
handlers = el;
|
758
|
-
el = this.$el;
|
759
|
-
}
|
760
|
-
for (event in handlers) {
|
761
|
-
handler = handlers[event];
|
762
|
-
if (_.isString(handler)) {
|
763
|
-
(function(_this) {
|
764
|
-
return (function(method) {
|
765
|
-
return handler = function() {
|
766
|
-
var args;
|
767
|
-
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
768
|
-
return _this[method].apply(_this, args);
|
769
|
-
};
|
770
|
-
});
|
771
|
-
})(this)(handler);
|
772
|
-
handlers[event] = handler;
|
773
|
-
}
|
774
|
-
}
|
775
|
-
return this.component.on(el, handlers);
|
776
|
-
};
|
777
|
-
|
778
|
-
delegatedMethods = ['$', 'off', 'trigger', 'data', 'removeData'];
|
779
|
-
|
780
|
-
_fn = function(name) {
|
781
|
-
return Module.prototype[name] = function() {
|
782
|
-
var args, _ref;
|
783
|
-
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
784
|
-
return (_ref = this.component)[name].apply(_ref, args);
|
785
|
-
};
|
786
|
-
};
|
787
|
-
for (_i = 0, _len = delegatedMethods.length; _i < _len; _i++) {
|
788
|
-
componentMethod = delegatedMethods[_i];
|
789
|
-
_fn(componentMethod);
|
790
|
-
}
|
791
|
-
|
792
|
-
return Module;
|
793
|
-
|
794
|
-
})(Unit);
|
795
|
-
|
796
|
-
factory = new Factory();
|
797
|
-
|
798
|
-
µ = function(objectName) {
|
799
|
-
var C, M, componentName, currentName, moduleName, names, namespace, namespaceName;
|
800
|
-
if (objectName == null) {
|
801
|
-
objectName = '';
|
802
|
-
}
|
803
|
-
names = objectName.split('.');
|
804
|
-
currentName = names.shift();
|
805
|
-
switch (currentName) {
|
806
|
-
case 'components':
|
807
|
-
case 'modules':
|
808
|
-
case '':
|
809
|
-
namespaceName = factory.config.defaultNamespace;
|
810
|
-
break;
|
811
|
-
default:
|
812
|
-
if (currentName.match(Unit.labelFormat)) {
|
813
|
-
namespaceName = factory.config.defaultNamespace;
|
814
|
-
} else {
|
815
|
-
namespaceName = currentName;
|
816
|
-
currentName = names.shift();
|
817
|
-
}
|
818
|
-
}
|
819
|
-
if (!(namespace = factory.namespace(namespaceName, true))) {
|
820
|
-
namespace = factory.createNamespace(namespaceName);
|
821
|
-
}
|
822
|
-
if (!currentName) {
|
823
|
-
return namespace.µObject();
|
824
|
-
}
|
825
|
-
switch (currentName) {
|
826
|
-
case 'components':
|
827
|
-
componentName = names.shift();
|
828
|
-
if (C = namespace.component(componentName, true)) {
|
829
|
-
return C.µObject();
|
830
|
-
} else {
|
831
|
-
return Component.µObject({
|
832
|
-
namespace: namespace,
|
833
|
-
label: componentName
|
834
|
-
});
|
835
|
-
}
|
836
|
-
break;
|
837
|
-
case 'modules':
|
838
|
-
moduleName = names.shift();
|
839
|
-
if (M = namespace.module(moduleName, true)) {
|
840
|
-
return M.µObject();
|
841
|
-
} else {
|
842
|
-
return Module.µObject({
|
843
|
-
namespace: namespace,
|
844
|
-
label: moduleName
|
845
|
-
});
|
846
|
-
}
|
847
|
-
break;
|
848
|
-
default:
|
849
|
-
if (C = namespace.component(currentName, true)) {
|
850
|
-
return C.µObject();
|
851
|
-
} else if (M = namespace.module(currentName, true)) {
|
852
|
-
return M.µObject();
|
853
|
-
} else {
|
854
|
-
return Component.µObject({
|
855
|
-
namespace: namespace,
|
856
|
-
label: currentName
|
857
|
-
});
|
858
|
-
}
|
859
|
-
}
|
860
|
-
};
|
861
|
-
|
862
|
-
_.extend(µ, {
|
863
|
-
configure: function(config) {
|
864
|
-
return factory.configure(config);
|
865
|
-
},
|
866
|
-
setup: function(setup) {
|
867
|
-
return factory.setup(setup);
|
868
|
-
},
|
869
|
-
initialize: function(el) {
|
870
|
-
return factory.initialize(el);
|
871
|
-
},
|
872
|
-
destroy: function(el) {
|
873
|
-
return factory.destroy(el);
|
874
|
-
},
|
875
|
-
clean: function() {
|
876
|
-
return factory.clean();
|
877
|
-
}
|
878
|
-
});
|
879
|
-
|
880
|
-
window.Micro = window.µ = µ;
|
881
|
-
|
882
|
-
}).call(this);
|
1
|
+
Not Found
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: micro-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.pre.
|
4
|
+
version: 0.1.0.pre.alpha5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jérôme Guyon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jquery-rails
|