wingman_rails 0.0.1

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.
@@ -0,0 +1,4 @@
1
+ module WingmanRails
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1 @@
1
+ require "wingman_rails/engine"
@@ -0,0 +1,2498 @@
1
+ (function(window) {
2
+
3
+ (function(/*! Stitch !*/) {
4
+ if (!this.require) {
5
+ var modules = {}, cache = {}, require = function(name, root) {
6
+ var path = expand(root, name), module = cache[path], fn;
7
+ if (module) {
8
+ return module.exports;
9
+ } else if (fn = modules[path] || modules[path = expand(path, './index')]) {
10
+ module = {id: path, exports: {}};
11
+ try {
12
+ cache[path] = module;
13
+ fn(module.exports, function(name) {
14
+ return require(name, dirname(path));
15
+ }, module);
16
+ return module.exports;
17
+ } catch (err) {
18
+ delete cache[path];
19
+ throw err;
20
+ }
21
+ } else {
22
+ throw 'module \'' + name + '\' not found';
23
+ }
24
+ }, expand = function(root, name) {
25
+ var results = [], parts, part;
26
+ if (/^\.\.?(\/|$)/.test(name)) {
27
+ parts = [root, name].join('/').split('/');
28
+ } else {
29
+ parts = name.split('/');
30
+ }
31
+ for (var i = 0, length = parts.length; i < length; i++) {
32
+ part = parts[i];
33
+ if (part == '..') {
34
+ results.pop();
35
+ } else if (part != '.' && part != '') {
36
+ results.push(part);
37
+ }
38
+ }
39
+ return results.join('/');
40
+ }, dirname = function(path) {
41
+ return path.split('/').slice(0, -1).join('/');
42
+ };
43
+ this.require = function(name) {
44
+ return require(name, '');
45
+ }
46
+ this.require.define = function(bundle) {
47
+ for (var key in bundle)
48
+ modules[key] = bundle[key];
49
+ };
50
+ }
51
+ return this.require.define;
52
+ }).call(this)({"wingman": function(exports, require, module) {(function() {
53
+
54
+ if (typeof window !== "undefined" && window !== null) {
55
+ exports.document = window.document;
56
+ exports.window = window;
57
+ exports.localStorage = localStorage;
58
+ }
59
+
60
+ exports.request = require('./wingman/request');
61
+
62
+ exports.Template = require('./wingman/template');
63
+
64
+ exports.View = require('./wingman/view');
65
+
66
+ exports.Model = require('./wingman/model');
67
+
68
+ exports.Controller = require('./wingman/controller');
69
+
70
+ exports.Application = require('./wingman/application');
71
+
72
+ exports.Module = require('./wingman/shared/module');
73
+
74
+ exports.Events = require('./wingman/shared/events');
75
+
76
+ }).call(this);
77
+ }, "wingman/application": function(exports, require, module) {(function() {
78
+ var Application, Events, Fleck, Navigator, Wingman, WingmanObject,
79
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
80
+ __hasProp = Object.prototype.hasOwnProperty,
81
+ __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; };
82
+
83
+ Wingman = require('../wingman');
84
+
85
+ Events = require('./shared/events');
86
+
87
+ WingmanObject = require('./shared/object');
88
+
89
+ Navigator = require('./shared/navigator');
90
+
91
+ Fleck = require('fleck');
92
+
93
+ module.exports = Application = (function(_super) {
94
+
95
+ __extends(Application, _super);
96
+
97
+ Application.include(Navigator);
98
+
99
+ Application.include(Events);
100
+
101
+ function Application(options) {
102
+ this.handlePopStateChange = __bind(this.handlePopStateChange, this);
103
+ this.buildController = __bind(this.buildController, this);
104
+ var key, value, _ref;
105
+ if (this.constructor.__super__.constructor.instance) {
106
+ throw new Error('You cannot instantiate two Wingman apps at the same time.');
107
+ }
108
+ this.constructor.__super__.constructor.instance = this;
109
+ _ref = this.constructor;
110
+ for (key in _ref) {
111
+ value = _ref[key];
112
+ if (key.match("(.+)View$") && key !== 'RootView') {
113
+ this.constructor.RootView[key] = value;
114
+ }
115
+ }
116
+ this.bind('viewCreated', this.buildController);
117
+ this.el = (options != null ? options.el : void 0) || Wingman.document.body;
118
+ this.view = (options != null ? options.view : void 0) || this.buildView();
119
+ Wingman.window.addEventListener('popstate', this.handlePopStateChange);
120
+ this.updatePath();
121
+ if (typeof this.ready === "function") this.ready();
122
+ }
123
+
124
+ Application.prototype.buildView = function() {
125
+ var view,
126
+ _this = this;
127
+ view = new this.constructor.RootView({
128
+ parent: this,
129
+ el: this.el,
130
+ app: this
131
+ });
132
+ view.bind('descendantCreated', function(view) {
133
+ return _this.trigger('viewCreated', view);
134
+ });
135
+ this.trigger('viewCreated', view);
136
+ view.render();
137
+ return view;
138
+ };
139
+
140
+ Application.prototype.buildController = function(view) {
141
+ var Controller;
142
+ Controller = this.controllerClassForView(view);
143
+ if (Controller) return new Controller(view);
144
+ };
145
+
146
+ Application.prototype.controllerClassForView = function(view) {
147
+ var klassName, part, parts, scope, _i, _len;
148
+ parts = view.path().split('.');
149
+ scope = this.constructor;
150
+ for (_i = 0, _len = parts.length; _i < _len; _i++) {
151
+ part = parts[_i];
152
+ klassName = Fleck.camelize(part, true) + 'Controller';
153
+ scope = scope[klassName];
154
+ if (!scope) return;
155
+ }
156
+ return scope;
157
+ };
158
+
159
+ Application.prototype.handlePopStateChange = function(e) {
160
+ if (Wingman.window.navigator.userAgent.match('WebKit') && !this._firstRun) {
161
+ return this._firstRun = true;
162
+ } else {
163
+ this.updateNavigationOptions(e.state);
164
+ return this.updatePath();
165
+ }
166
+ };
167
+
168
+ Application.prototype.updatePath = function() {
169
+ return this.set({
170
+ path: Wingman.document.location.pathname.substr(1)
171
+ });
172
+ };
173
+
174
+ Application.prototype.updateNavigationOptions = function(options) {
175
+ return this.set({
176
+ navigationOptions: options
177
+ });
178
+ };
179
+
180
+ Application.prototype.findView = function(path) {
181
+ return this.view.get(path);
182
+ };
183
+
184
+ return Application;
185
+
186
+ })(WingmanObject);
187
+
188
+ }).call(this);
189
+ }, "wingman/controller": function(exports, require, module) {(function() {
190
+ var Navigator, Wingman, WingmanObject,
191
+ __hasProp = Object.prototype.hasOwnProperty,
192
+ __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; };
193
+
194
+ WingmanObject = require('./shared/object');
195
+
196
+ Wingman = require('../wingman');
197
+
198
+ Navigator = require('./shared/navigator');
199
+
200
+ module.exports = (function(_super) {
201
+
202
+ __extends(_Class, _super);
203
+
204
+ _Class.include(Navigator);
205
+
206
+ function _Class(view) {
207
+ _Class.__super__.constructor.call(this);
208
+ this.set({
209
+ view: view
210
+ });
211
+ this.set({
212
+ app: view.app
213
+ });
214
+ if (typeof this.ready === "function") this.ready();
215
+ }
216
+
217
+ return _Class;
218
+
219
+ })(WingmanObject);
220
+
221
+ }).call(this);
222
+ }, "wingman/model": function(exports, require, module) {(function() {
223
+ var Fleck, HasManyAssociation, Model, Scope, StorageAdapter, Store, Wingman, WingmanObject,
224
+ __hasProp = Object.prototype.hasOwnProperty,
225
+ __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; },
226
+ __slice = Array.prototype.slice;
227
+
228
+ Wingman = require('../wingman');
229
+
230
+ WingmanObject = require('./shared/object');
231
+
232
+ StorageAdapter = require('./model/storage_adapter');
233
+
234
+ Store = require('./model/store');
235
+
236
+ Scope = require('./model/scope');
237
+
238
+ HasManyAssociation = require('./model/has_many_association');
239
+
240
+ Fleck = require('fleck');
241
+
242
+ module.exports = Model = (function(_super) {
243
+
244
+ __extends(Model, _super);
245
+
246
+ Model.extend(StorageAdapter);
247
+
248
+ Model.store = function() {
249
+ return this._store || (this._store = new Store);
250
+ };
251
+
252
+ Model.count = function() {
253
+ return this.store().count();
254
+ };
255
+
256
+ Model.load = function() {
257
+ var args;
258
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
259
+ if (typeof args[0] === 'number') {
260
+ return this.loadOne(args[0], args[1]);
261
+ } else {
262
+ return this.loadMany(args[0]);
263
+ }
264
+ };
265
+
266
+ Model.hasMany = function(name) {
267
+ return (this.hasManyNames || (this.hasManyNames = [])).push(name);
268
+ };
269
+
270
+ Model.loadOne = function(id, callback) {
271
+ var _this = this;
272
+ return this.storageAdapter().load(id, {
273
+ success: function(hash) {
274
+ var model;
275
+ model = new _this(hash);
276
+ if (callback) return callback(model);
277
+ }
278
+ });
279
+ };
280
+
281
+ Model.loadMany = function(callback) {
282
+ var _this = this;
283
+ return this.storageAdapter().load({
284
+ success: function(array) {
285
+ var model, modelData, models, _i, _len;
286
+ models = [];
287
+ for (_i = 0, _len = array.length; _i < _len; _i++) {
288
+ modelData = array[_i];
289
+ model = new _this(modelData);
290
+ models.push(model);
291
+ }
292
+ if (callback) return callback(models);
293
+ }
294
+ });
295
+ };
296
+
297
+ Model.scoped = function(params) {
298
+ return new Scope(this.store(), params);
299
+ };
300
+
301
+ Model.find = function(id) {
302
+ return this.store().find(id);
303
+ };
304
+
305
+ function Model(properties, options) {
306
+ var _this = this;
307
+ this.storageAdapter = this.constructor.storageAdapter();
308
+ this.dirtyStaticPropertyNames = [];
309
+ if (this.constructor.hasManyNames) this.setupHasManyAssociations();
310
+ this.observeOnce('id', function() {
311
+ return _this.constructor.store().add(_this);
312
+ });
313
+ this.set(properties);
314
+ }
315
+
316
+ Model.prototype.setupHasManyAssociations = function() {
317
+ var association, hasManyName, klass, klassName, _i, _len, _ref, _results,
318
+ _this = this;
319
+ _ref = this.constructor.hasManyNames;
320
+ _results = [];
321
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
322
+ hasManyName = _ref[_i];
323
+ klassName = Fleck.camelize(Fleck.singularize(Fleck.underscore(hasManyName)), true);
324
+ klass = Wingman.Application.instance.constructor[klassName];
325
+ association = new HasManyAssociation(this, klass);
326
+ this.setProperty(hasManyName, association);
327
+ association.bind('add', function(model) {
328
+ return _this.trigger("add:" + hasManyName, model);
329
+ });
330
+ _results.push(association.bind('remove', function(model) {
331
+ return _this.trigger("remove:" + hasManyName, model);
332
+ }));
333
+ }
334
+ return _results;
335
+ };
336
+
337
+ Model.prototype.save = function(options) {
338
+ var operation,
339
+ _this = this;
340
+ if (options == null) options = {};
341
+ operation = this.isPersisted() ? 'update' : 'create';
342
+ return this.storageAdapter[operation](this, {
343
+ success: function(data) {
344
+ if (data) {
345
+ if (operation === 'update') delete data.id;
346
+ _this.set(data);
347
+ }
348
+ _this.clean();
349
+ return typeof options.success === "function" ? options.success() : void 0;
350
+ },
351
+ error: function() {
352
+ return typeof options.error === "function" ? options.error() : void 0;
353
+ }
354
+ });
355
+ };
356
+
357
+ Model.prototype.destroy = function() {
358
+ this.trigger('destroy', this);
359
+ return this.storageAdapter["delete"](this.get('id'));
360
+ };
361
+
362
+ Model.prototype.toParam = function() {
363
+ return this.get('id');
364
+ };
365
+
366
+ Model.prototype.load = function() {
367
+ var _this = this;
368
+ return this.storageAdapter.load(this.get('id'), {
369
+ success: function(hash) {
370
+ delete hash.id;
371
+ return _this.set(hash);
372
+ }
373
+ });
374
+ };
375
+
376
+ Model.prototype.clean = function() {
377
+ return this.dirtyStaticPropertyNames.length = 0;
378
+ };
379
+
380
+ Model.prototype.dirtyStaticProperties = function() {
381
+ return this.toJSON({
382
+ only: this.dirtyStaticPropertyNames
383
+ });
384
+ };
385
+
386
+ Model.prototype.set = function(hash) {
387
+ return Model.__super__.set.call(this, hash);
388
+ };
389
+
390
+ Model.prototype.setProperty = function(propertyName, values) {
391
+ if (propertyName === 'id' && this.get('id')) {
392
+ throw new Error('You cannot change the ID of a model when set.');
393
+ }
394
+ if (this.get(propertyName) instanceof HasManyAssociation) {
395
+ return this.get(propertyName).build(values);
396
+ } else {
397
+ this.dirtyStaticPropertyNames.push(propertyName);
398
+ Model.__super__.setProperty.call(this, propertyName, values);
399
+ if (this.storageAdapter.autoSave) return this.save();
400
+ }
401
+ };
402
+
403
+ Model.prototype.isPersisted = function() {
404
+ return !!this.get('id');
405
+ };
406
+
407
+ Model.prototype.isDirty = function() {
408
+ return this.dirtyStaticPropertyNames.length !== 0;
409
+ };
410
+
411
+ return Model;
412
+
413
+ })(WingmanObject);
414
+
415
+ }).call(this);
416
+ }, "wingman/model/has_many_association": function(exports, require, module) {(function() {
417
+ var Events, Fleck, HasManyAssociation, Module,
418
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
419
+ __hasProp = Object.prototype.hasOwnProperty,
420
+ __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; },
421
+ __slice = Array.prototype.slice;
422
+
423
+ Fleck = require('fleck');
424
+
425
+ Module = require('./../shared/module');
426
+
427
+ Events = require('./../shared/events');
428
+
429
+ module.exports = HasManyAssociation = (function(_super) {
430
+
431
+ __extends(HasManyAssociation, _super);
432
+
433
+ HasManyAssociation.include(Events);
434
+
435
+ function HasManyAssociation(model, associatedClass) {
436
+ this.model = model;
437
+ this.associatedClass = associatedClass;
438
+ this.setupScope = __bind(this.setupScope, this);
439
+ this.model.observeOnce('id', this.setupScope);
440
+ }
441
+
442
+ HasManyAssociation.prototype.setupScope = function() {
443
+ var _this = this;
444
+ this.scope = this.associatedClass.scoped(this.scopeOptions());
445
+ this.scope.forEach(function(model) {
446
+ return _this.trigger('add', model);
447
+ });
448
+ this.scope.bind('add', function() {
449
+ var args;
450
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
451
+ return _this.trigger.apply(_this, ['add'].concat(__slice.call(args)));
452
+ });
453
+ return this.scope.bind('remove', function() {
454
+ var args;
455
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
456
+ return _this.trigger.apply(_this, ['remove'].concat(__slice.call(args)));
457
+ });
458
+ };
459
+
460
+ HasManyAssociation.prototype.scopeOptions = function() {
461
+ var options;
462
+ options = {};
463
+ options[this.foreignKey()] = this.model.get('id');
464
+ return options;
465
+ };
466
+
467
+ HasManyAssociation.prototype.foreignKey = function() {
468
+ return Fleck.camelize(Fleck.underscore(this.model.constructor.name)) + 'Id';
469
+ };
470
+
471
+ HasManyAssociation.prototype.count = function() {
472
+ if (this.scope) {
473
+ return this.scope.count();
474
+ } else {
475
+ return 0;
476
+ }
477
+ };
478
+
479
+ HasManyAssociation.prototype.buildOne = function(hash) {
480
+ var foreignId;
481
+ foreignId = this.model.get('id');
482
+ if (!foreignId) {
483
+ throw new Error("Parent's ID must be set to use HasManyAssociation#build.");
484
+ }
485
+ hash[this.foreignKey()] = foreignId;
486
+ return new this.associatedClass(hash);
487
+ };
488
+
489
+ HasManyAssociation.prototype.build = function(arrayOrHash) {
490
+ var array, hash, _i, _len, _results;
491
+ array = Array.isArray(arrayOrHash) ? arrayOrHash : [arrayOrHash];
492
+ _results = [];
493
+ for (_i = 0, _len = array.length; _i < _len; _i++) {
494
+ hash = array[_i];
495
+ _results.push(this.buildOne(hash));
496
+ }
497
+ return _results;
498
+ };
499
+
500
+ HasManyAssociation.prototype.forEach = function(callback) {
501
+ var model, _i, _len, _ref, _results;
502
+ _ref = this.models();
503
+ _results = [];
504
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
505
+ model = _ref[_i];
506
+ _results.push(callback(model));
507
+ }
508
+ return _results;
509
+ };
510
+
511
+ HasManyAssociation.prototype.models = function() {
512
+ var key, models, value, _ref;
513
+ if (this.scope) {
514
+ models = [];
515
+ _ref = this.scope.models;
516
+ for (key in _ref) {
517
+ value = _ref[key];
518
+ models.push(value);
519
+ }
520
+ return models;
521
+ } else {
522
+ return [];
523
+ }
524
+ };
525
+
526
+ return HasManyAssociation;
527
+
528
+ })(Module);
529
+
530
+ }).call(this);
531
+ }, "wingman/model/scope": function(exports, require, module) {(function() {
532
+ var Events, Module, Scope,
533
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
534
+ __hasProp = Object.prototype.hasOwnProperty,
535
+ __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; };
536
+
537
+ Module = require('./../shared/module');
538
+
539
+ Events = require('./../shared/events');
540
+
541
+ module.exports = Scope = (function(_super) {
542
+
543
+ __extends(Scope, _super);
544
+
545
+ Scope.include(Events);
546
+
547
+ function Scope(store, params) {
548
+ var _this = this;
549
+ this.params = params;
550
+ this.remove = __bind(this.remove, this);
551
+ this.check = __bind(this.check, this);
552
+ this.listen = __bind(this.listen, this);
553
+ this.models = {};
554
+ store.forEach(function(model) {
555
+ return _this.check(model);
556
+ });
557
+ store.bind('add', this.listen);
558
+ }
559
+
560
+ Scope.prototype.listen = function(model) {
561
+ var key, _i, _len, _ref, _results,
562
+ _this = this;
563
+ this.check(model);
564
+ _ref = Object.keys(this.params);
565
+ _results = [];
566
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
567
+ key = _ref[_i];
568
+ _results.push(model.observe(key, function() {
569
+ return _this.check(model);
570
+ }));
571
+ }
572
+ return _results;
573
+ };
574
+
575
+ Scope.prototype.check = function(model) {
576
+ if (this.shouldBeAdded(model)) {
577
+ return this.add(model);
578
+ } else if (this.shouldBeRemoved(model)) {
579
+ return this.remove(model);
580
+ }
581
+ };
582
+
583
+ Scope.prototype.shouldBeAdded = function(model) {
584
+ return this.matches(model) && !this.exists(model);
585
+ };
586
+
587
+ Scope.prototype.shouldBeRemoved = function(model) {
588
+ return !this.matches(model) && this.exists(model);
589
+ };
590
+
591
+ Scope.prototype.add = function(model) {
592
+ if (!model.get('id')) throw new Error('Model must have ID to be stored.');
593
+ if (this.exists(model)) {
594
+ throw new Error("" + model.constructor.name + " model with ID " + (model.get('id')) + " already in scope.");
595
+ }
596
+ this.models[model.get('id')] = model;
597
+ this.trigger('add', model);
598
+ return model.bind('destroy', this.remove);
599
+ };
600
+
601
+ Scope.prototype.matches = function(model) {
602
+ var _this = this;
603
+ return Object.keys(this.params).every(function(key) {
604
+ return model.get(key) === _this.params[key];
605
+ });
606
+ };
607
+
608
+ Scope.prototype.count = function() {
609
+ return Object.keys(this.models).length;
610
+ };
611
+
612
+ Scope.prototype.find = function(id) {
613
+ return this.models[id] || (function() {
614
+ throw new Error('Model not found in scope.');
615
+ })();
616
+ };
617
+
618
+ Scope.prototype.remove = function(model) {
619
+ delete this.models[model.get('id')];
620
+ model.unbind('destroy', this.remove);
621
+ return this.trigger('remove', model);
622
+ };
623
+
624
+ Scope.prototype.exists = function(model) {
625
+ return !!this.models[model.get('id')];
626
+ };
627
+
628
+ Scope.prototype.forEach = function(callback) {
629
+ var key, value, _ref, _results;
630
+ _ref = this.models;
631
+ _results = [];
632
+ for (key in _ref) {
633
+ value = _ref[key];
634
+ _results.push(callback(value));
635
+ }
636
+ return _results;
637
+ };
638
+
639
+ return Scope;
640
+
641
+ })(Module);
642
+
643
+ }).call(this);
644
+ }, "wingman/model/storage_adapter": function(exports, require, module) {(function() {
645
+ var LocalStorage, RestStorage;
646
+
647
+ RestStorage = require('./storage_adapters/rest');
648
+
649
+ LocalStorage = require('./storage_adapters/local');
650
+
651
+ module.exports = {
652
+ storageTypes: {
653
+ 'rest': RestStorage,
654
+ 'local': LocalStorage
655
+ },
656
+ storage: function(type, options) {
657
+ if (options == null) options = {};
658
+ if (!this.storageAdapterTypeSupported(type)) {
659
+ throw new Error("Storage engine " + type + " not supported.");
660
+ }
661
+ options.type = type;
662
+ return this.storageAdapterOptions = options;
663
+ },
664
+ storageAdapterTypeSupported: function(type) {
665
+ return !!this.storageTypes[type];
666
+ },
667
+ storageAdapter: function() {
668
+ return this._storageAdapter || (this._storageAdapter = this.buildStorageAdapter());
669
+ },
670
+ buildStorageAdapter: function() {
671
+ var key, klass, options, value, _ref;
672
+ this.storageAdapterOptions || (this.storageAdapterOptions = {
673
+ type: 'rest'
674
+ });
675
+ klass = this.storageTypes[this.storageAdapterOptions.type];
676
+ options = {};
677
+ _ref = this.storageAdapterOptions;
678
+ for (key in _ref) {
679
+ value = _ref[key];
680
+ if (key !== 'type') options[key] = value;
681
+ }
682
+ return new klass(options);
683
+ }
684
+ };
685
+
686
+ }).call(this);
687
+ }, "wingman/model/storage_adapters/local": function(exports, require, module) {(function() {
688
+ var Wingman;
689
+
690
+ Wingman = require('../../../wingman');
691
+
692
+ module.exports = (function() {
693
+
694
+ _Class.prototype.autoSave = true;
695
+
696
+ function _Class(options) {
697
+ this.options = options;
698
+ }
699
+
700
+ _Class.prototype.create = function(model, options) {
701
+ model.set({
702
+ id: this.generateId()
703
+ });
704
+ Wingman.localStorage.setItem(this.key(model.get('id')), JSON.stringify(model.toJSON()));
705
+ return options != null ? typeof options.success === "function" ? options.success() : void 0 : void 0;
706
+ };
707
+
708
+ _Class.prototype.update = function(model, options) {
709
+ var _this = this;
710
+ return this.load(model.get('id'), {
711
+ success: function(existingProperties) {
712
+ var key, newProperties, value;
713
+ newProperties = model.toJSON();
714
+ for (key in existingProperties) {
715
+ value = existingProperties[key];
716
+ if (newProperties[key] == null) newProperties[key] = value;
717
+ }
718
+ Wingman.localStorage.setItem(_this.key(model.get('id')), JSON.stringify(newProperties));
719
+ return options != null ? typeof options.success === "function" ? options.success() : void 0 : void 0;
720
+ }
721
+ });
722
+ };
723
+
724
+ _Class.prototype.load = function(id, options) {
725
+ var itemAsJson, itemAsString;
726
+ itemAsString = Wingman.localStorage.getItem(this.key(id));
727
+ itemAsJson = JSON.parse(itemAsString);
728
+ return options.success(itemAsJson);
729
+ };
730
+
731
+ _Class.prototype.key = function(id) {
732
+ return [this.options.namespace, id].join('.');
733
+ };
734
+
735
+ _Class.prototype.generateId = function() {
736
+ return Math.round(Math.random() * 5000000);
737
+ };
738
+
739
+ return _Class;
740
+
741
+ })();
742
+
743
+ }).call(this);
744
+ }, "wingman/model/storage_adapters/rest": function(exports, require, module) {(function() {
745
+ var Wingman,
746
+ __slice = Array.prototype.slice;
747
+
748
+ Wingman = require('../../../wingman');
749
+
750
+ module.exports = (function() {
751
+
752
+ function _Class(options) {
753
+ this.options = options;
754
+ }
755
+
756
+ _Class.prototype.create = function(model, options) {
757
+ if (options == null) options = {};
758
+ return Wingman.request({
759
+ type: 'POST',
760
+ url: this.options.url,
761
+ data: model.dirtyStaticProperties(),
762
+ error: options.error,
763
+ success: options.success
764
+ });
765
+ };
766
+
767
+ _Class.prototype.update = function(model, options) {
768
+ if (options == null) options = {};
769
+ return Wingman.request({
770
+ type: 'PUT',
771
+ url: "" + this.options.url + "/" + (model.get('id')),
772
+ data: model.dirtyStaticProperties(),
773
+ error: options.error,
774
+ success: options.success
775
+ });
776
+ };
777
+
778
+ _Class.prototype.load = function() {
779
+ var args, options;
780
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
781
+ if (args.length === 2) {
782
+ options = args[1];
783
+ options.url = [this.options.url, args[0]].join('/');
784
+ } else {
785
+ options = args[0];
786
+ options.url = this.options.url;
787
+ }
788
+ options.type = 'GET';
789
+ return Wingman.request(options);
790
+ };
791
+
792
+ _Class.prototype["delete"] = function(id) {
793
+ return Wingman.request({
794
+ url: [this.options.url, id].join('/'),
795
+ type: 'DELETE'
796
+ });
797
+ };
798
+
799
+ return _Class;
800
+
801
+ })();
802
+
803
+ }).call(this);
804
+ }, "wingman/model/store": function(exports, require, module) {(function() {
805
+ var Events, Module, Store,
806
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
807
+ __hasProp = Object.prototype.hasOwnProperty,
808
+ __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; };
809
+
810
+ Module = require('./../shared/module');
811
+
812
+ Events = require('./../shared/events');
813
+
814
+ module.exports = Store = (function(_super) {
815
+
816
+ __extends(Store, _super);
817
+
818
+ Store.include(Events);
819
+
820
+ function Store() {
821
+ this.remove = __bind(this.remove, this); this.models = {};
822
+ }
823
+
824
+ Store.prototype.add = function(model) {
825
+ if (!model.get('id')) throw new Error('Model must have ID to be stored.');
826
+ if (this.exists(model)) {
827
+ return this.update(this.models[model.get('id')], model);
828
+ } else {
829
+ return this.insert(model);
830
+ }
831
+ };
832
+
833
+ Store.prototype.insert = function(model) {
834
+ this.models[model.get('id')] = model;
835
+ this.trigger('add', model);
836
+ return model.bind('destroy', this.remove);
837
+ };
838
+
839
+ Store.prototype.update = function(model, model2) {
840
+ var key, value, _ref, _results;
841
+ _ref = model2.toJSON();
842
+ _results = [];
843
+ for (key in _ref) {
844
+ value = _ref[key];
845
+ if (key !== 'id') {
846
+ _results.push(model.setProperty(key, value));
847
+ } else {
848
+ _results.push(void 0);
849
+ }
850
+ }
851
+ return _results;
852
+ };
853
+
854
+ Store.prototype.find = function(id) {
855
+ return this.models[id];
856
+ };
857
+
858
+ Store.prototype.count = function() {
859
+ return Object.keys(this.models).length;
860
+ };
861
+
862
+ Store.prototype.remove = function(model) {
863
+ delete this.models[model.get('id')];
864
+ model.unbind(this.remove);
865
+ return this.trigger('remove', model);
866
+ };
867
+
868
+ Store.prototype.exists = function(model) {
869
+ return !!this.models[model.get('id')];
870
+ };
871
+
872
+ Store.prototype.forEach = function(callback) {
873
+ var key, value, _ref, _results;
874
+ _ref = this.models;
875
+ _results = [];
876
+ for (key in _ref) {
877
+ value = _ref[key];
878
+ _results.push(callback(value));
879
+ }
880
+ return _results;
881
+ };
882
+
883
+ return Store;
884
+
885
+ })(Module);
886
+
887
+ }).call(this);
888
+ }, "wingman/request": function(exports, require, module) {(function() {
889
+ var Wingman, request,
890
+ __slice = Array.prototype.slice;
891
+
892
+ Wingman = require('../wingman');
893
+
894
+ request = function() {
895
+ var args, _base, _ref;
896
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
897
+ if (((_ref = Wingman.Application.instance) != null ? _ref.host : void 0) != null) {
898
+ args[0].url = ['http://', Wingman.Application.instance.host, args[0].url].join('');
899
+ }
900
+ (_base = args[0]).dataType || (_base.dataType = 'json');
901
+ return request.realRequest.apply(request, args);
902
+ };
903
+
904
+ if (typeof jQuery !== "undefined" && jQuery !== null) {
905
+ request.realRequest = jQuery.ajax;
906
+ }
907
+
908
+ module.exports = request;
909
+
910
+ }).call(this);
911
+ }, "wingman/shared/elementary": function(exports, require, module) {(function() {
912
+
913
+ module.exports = {
914
+ classCache: function() {
915
+ return this._classCache || (this._classCache = {});
916
+ },
917
+ addClass: function(className) {
918
+ var _base;
919
+ (_base = this.classCache())[className] || (_base[className] = 0);
920
+ this.classCache()[className]++;
921
+ if (this.classCache()[className] === 1) {
922
+ return this.domElement.className = this.domElement.className ? this.domElement.className.split(' ').concat(className).join(' ') : className;
923
+ }
924
+ },
925
+ removeClass: function(className) {
926
+ var reg;
927
+ if (this.classCache()[className]) this.classCache()[className]--;
928
+ if (this.classCache()[className] === 0) {
929
+ reg = new RegExp('(\\s|^)' + className + '(\\s|$)');
930
+ return this.domElement.className = this.domElement.className.replace(reg, '');
931
+ }
932
+ },
933
+ setStyle: function(key, value) {
934
+ var keyCssNotation;
935
+ keyCssNotation = this.convertCssPropertyFromDomToCssNotation(key);
936
+ return this.domElement.style[keyCssNotation] = value;
937
+ },
938
+ setAttribute: function(key, value) {
939
+ return this.domElement.setAttribute(key, value);
940
+ },
941
+ remove: function() {
942
+ return this.domElement.parentNode.removeChild(this.domElement);
943
+ },
944
+ convertCssPropertyFromDomToCssNotation: function(propertyName) {
945
+ return propertyName.replace(/(-[a-z]{1})/g, function(s) {
946
+ return s[1].toUpperCase();
947
+ });
948
+ }
949
+ };
950
+
951
+ }).call(this);
952
+ }, "wingman/shared/events": function(exports, require, module) {(function() {
953
+ var __slice = Array.prototype.slice;
954
+
955
+ module.exports = {
956
+ bind: function(eventName, callback) {
957
+ var _base;
958
+ if (!callback) throw new Error('Callback must be set!');
959
+ this._callbacks || (this._callbacks = {});
960
+ (_base = this._callbacks)[eventName] || (_base[eventName] = []);
961
+ this._callbacks[eventName].push(callback);
962
+ return this._callbacks;
963
+ },
964
+ unbind: function(eventName, callback) {
965
+ var index, list;
966
+ list = this._callbacks && this._callbacks[eventName];
967
+ if (!list) return false;
968
+ index = list.indexOf(callback);
969
+ return list.splice(index, 1);
970
+ },
971
+ trigger: function() {
972
+ var args, callback, eventName, list, _i, _len, _ref, _results;
973
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
974
+ eventName = args.shift();
975
+ list = this._callbacks && this._callbacks[eventName];
976
+ if (!list) return;
977
+ _ref = list.slice();
978
+ _results = [];
979
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
980
+ callback = _ref[_i];
981
+ _results.push(callback.apply(this, args));
982
+ }
983
+ return _results;
984
+ }
985
+ };
986
+
987
+ }).call(this);
988
+ }, "wingman/shared/module": function(exports, require, module) {(function() {
989
+
990
+ module.exports = (function() {
991
+
992
+ function _Class() {}
993
+
994
+ _Class.include = function(obj) {
995
+ var key, value;
996
+ if (!obj) throw 'Module.include requires obj';
997
+ for (key in obj) {
998
+ value = obj[key];
999
+ this.prototype[key] = value;
1000
+ }
1001
+ return typeof obj.included === "function" ? obj.included(this) : void 0;
1002
+ };
1003
+
1004
+ _Class.extend = function(obj) {
1005
+ var key, value;
1006
+ if (!obj) throw 'Module.extend requires obj';
1007
+ for (key in obj) {
1008
+ value = obj[key];
1009
+ this[key] = value;
1010
+ }
1011
+ return typeof obj.extended === "function" ? obj.extended(this) : void 0;
1012
+ };
1013
+
1014
+ return _Class;
1015
+
1016
+ })();
1017
+
1018
+ }).call(this);
1019
+ }, "wingman/shared/navigator": function(exports, require, module) {(function() {
1020
+ var Wingman;
1021
+
1022
+ Wingman = require('../../wingman');
1023
+
1024
+ module.exports = {
1025
+ navigate: function(location, options) {
1026
+ if (options == null) options = {};
1027
+ Wingman.window.history.pushState(options, '', "/" + location);
1028
+ Wingman.Application.instance.updateNavigationOptions(options);
1029
+ return Wingman.Application.instance.updatePath();
1030
+ },
1031
+ back: function(times) {
1032
+ if (times == null) times = 1;
1033
+ return Wingman.window.history.go(-times);
1034
+ }
1035
+ };
1036
+
1037
+ }).call(this);
1038
+ }, "wingman/shared/object": function(exports, require, module) {(function() {
1039
+ var Events, Module, WingmanObject, propertyDependencies,
1040
+ __hasProp = Object.prototype.hasOwnProperty,
1041
+ __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; },
1042
+ __slice = Array.prototype.slice,
1043
+ __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
1044
+
1045
+ Module = require('./module');
1046
+
1047
+ Events = require('./events');
1048
+
1049
+ propertyDependencies = {};
1050
+
1051
+ WingmanObject = WingmanObject = (function(_super) {
1052
+
1053
+ __extends(WingmanObject, _super);
1054
+
1055
+ WingmanObject.include(Events);
1056
+
1057
+ WingmanObject.parentPropertyDependencies = function() {
1058
+ var _ref, _ref2;
1059
+ if ((_ref = this.__super__) != null ? (_ref2 = _ref.constructor) != null ? _ref2.propertyDependencies : void 0 : void 0) {
1060
+ return this.__super__.constructor.propertyDependencies();
1061
+ } else {
1062
+ return {};
1063
+ }
1064
+ };
1065
+
1066
+ WingmanObject.buildPropertyDependencies = function() {
1067
+ var dependencies, key, value, _ref;
1068
+ dependencies = {};
1069
+ _ref = this.parentPropertyDependencies();
1070
+ for (key in _ref) {
1071
+ value = _ref[key];
1072
+ dependencies[key] = value;
1073
+ }
1074
+ return dependencies;
1075
+ };
1076
+
1077
+ WingmanObject.propertyDependencies = function(hash) {
1078
+ if (hash) {
1079
+ return this.addPropertyDependencies(hash);
1080
+ } else {
1081
+ return propertyDependencies[this] || (propertyDependencies[this] = this.buildPropertyDependencies());
1082
+ }
1083
+ };
1084
+
1085
+ WingmanObject.addPropertyDependencies = function(hash) {
1086
+ var config, key, value, _results;
1087
+ config = this.propertyDependencies();
1088
+ _results = [];
1089
+ for (key in hash) {
1090
+ value = hash[key];
1091
+ _results.push(config[key] = value);
1092
+ }
1093
+ return _results;
1094
+ };
1095
+
1096
+ function WingmanObject() {
1097
+ if (this.constructor.propertyDependencies()) this.initPropertyDependencies();
1098
+ }
1099
+
1100
+ WingmanObject.prototype.initPropertyDependencies = function() {
1101
+ var dependentPropertyKey, dependingPropertiesKeys, dependingPropertyKey, _ref, _results;
1102
+ _ref = this.constructor.propertyDependencies();
1103
+ _results = [];
1104
+ for (dependentPropertyKey in _ref) {
1105
+ dependingPropertiesKeys = _ref[dependentPropertyKey];
1106
+ if (!Array.isArray(dependingPropertiesKeys)) {
1107
+ dependingPropertiesKeys = [dependingPropertiesKeys];
1108
+ }
1109
+ _results.push((function() {
1110
+ var _i, _len, _results2;
1111
+ _results2 = [];
1112
+ for (_i = 0, _len = dependingPropertiesKeys.length; _i < _len; _i++) {
1113
+ dependingPropertyKey = dependingPropertiesKeys[_i];
1114
+ _results2.push(this.initPropertyDependency(dependentPropertyKey, dependingPropertyKey));
1115
+ }
1116
+ return _results2;
1117
+ }).call(this));
1118
+ }
1119
+ return _results;
1120
+ };
1121
+
1122
+ WingmanObject.prototype.initPropertyDependency = function(dependentPropertyKey, dependingPropertyKey) {
1123
+ var observeArrayLike, trigger, unobserveArrayLike,
1124
+ _this = this;
1125
+ trigger = function() {
1126
+ return _this.triggerPropertyChange(dependentPropertyKey);
1127
+ };
1128
+ this.observe(dependingPropertyKey, function(newValue, oldValue) {
1129
+ trigger();
1130
+ if (!(oldValue != null ? oldValue.forEach : void 0) && (newValue != null ? newValue.forEach : void 0)) {
1131
+ return observeArrayLike();
1132
+ } else if (oldValue != null ? oldValue.forEach : void 0) {
1133
+ return unobserveArrayLike();
1134
+ }
1135
+ });
1136
+ observeArrayLike = function() {
1137
+ _this.observe(dependingPropertyKey, 'add', trigger);
1138
+ return _this.observe(dependingPropertyKey, 'remove', trigger);
1139
+ };
1140
+ return unobserveArrayLike = function() {
1141
+ _this.unobserve(dependingPropertyKey, 'add', trigger);
1142
+ return _this.unobserve(dependingPropertyKey, 'remove', trigger);
1143
+ };
1144
+ };
1145
+
1146
+ WingmanObject.prototype.set = function(hash) {
1147
+ return this.setProperties(hash);
1148
+ };
1149
+
1150
+ WingmanObject.prototype.setProperties = function(hash) {
1151
+ var propertyName, value, _results;
1152
+ _results = [];
1153
+ for (propertyName in hash) {
1154
+ value = hash[propertyName];
1155
+ _results.push(this.setProperty(propertyName, value));
1156
+ }
1157
+ return _results;
1158
+ };
1159
+
1160
+ WingmanObject.prototype.triggerPropertyChange = function(propertyName) {
1161
+ var newValue;
1162
+ this.previousProperties || (this.previousProperties = {});
1163
+ newValue = this.get(propertyName);
1164
+ if (!this.previousProperties.hasOwnProperty(propertyName) || this.previousProperties[propertyName] !== newValue) {
1165
+ this.trigger("change:" + propertyName, newValue, this.previousProperties[propertyName]);
1166
+ return this.previousProperties[propertyName] = newValue;
1167
+ }
1168
+ };
1169
+
1170
+ WingmanObject.prototype.observeOnce = function(chainAsString, callback) {
1171
+ var observer,
1172
+ _this = this;
1173
+ observer = function() {
1174
+ var args;
1175
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
1176
+ callback.apply(null, args);
1177
+ return _this.unobserve(chainAsString, observer);
1178
+ };
1179
+ return this.observe(chainAsString, observer);
1180
+ };
1181
+
1182
+ WingmanObject.prototype.observe = function() {
1183
+ var args, callback, chain, chainAsString, chainExceptFirst, chainExceptFirstAsString, getAndSendToCallback, nested, observeOnNested, observeType, property, type,
1184
+ _this = this;
1185
+ chainAsString = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
1186
+ callback = args.pop();
1187
+ type = args.pop() || 'change';
1188
+ chain = chainAsString.split('.');
1189
+ chainExceptFirst = chain.slice(1, chain.length);
1190
+ chainExceptFirstAsString = chainExceptFirst.join('.');
1191
+ nested = chainExceptFirst.length !== 0;
1192
+ getAndSendToCallback = function(newValue, oldValue) {
1193
+ if (type === 'change') {
1194
+ return callback(newValue, oldValue);
1195
+ } else {
1196
+ return callback(newValue);
1197
+ }
1198
+ };
1199
+ property = this.get(chain[0]);
1200
+ observeOnNested = function(p) {
1201
+ return p.observe(chainExceptFirstAsString, type, function(newValue, oldValue) {
1202
+ return getAndSendToCallback(newValue, oldValue);
1203
+ });
1204
+ };
1205
+ if (nested && property) observeOnNested(property);
1206
+ observeType = nested ? 'change' : type;
1207
+ return this.observeProperty(chain[0], observeType, function(newValue, oldValue) {
1208
+ var ov;
1209
+ if (nested) {
1210
+ if (newValue) {
1211
+ ov = oldValue ? oldValue.get(chainExceptFirst.join('.')) : void 0;
1212
+ if (type === 'change') {
1213
+ getAndSendToCallback(newValue.get(chainExceptFirst.join('.')), ov);
1214
+ }
1215
+ observeOnNested(newValue);
1216
+ }
1217
+ if (oldValue) {
1218
+ return oldValue.unobserve(chainExceptFirstAsString, type, getAndSendToCallback);
1219
+ }
1220
+ } else {
1221
+ return getAndSendToCallback(newValue, oldValue);
1222
+ }
1223
+ });
1224
+ };
1225
+
1226
+ WingmanObject.prototype.observeProperty = function(propertyName, type, callback) {
1227
+ return this.bind("" + type + ":" + propertyName, callback);
1228
+ };
1229
+
1230
+ WingmanObject.prototype.unobserve = function() {
1231
+ var args, callback, propertyName, type;
1232
+ propertyName = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
1233
+ callback = args.pop();
1234
+ type = args.pop() || 'change';
1235
+ return this.unbind("" + type + ":" + propertyName, callback);
1236
+ };
1237
+
1238
+ WingmanObject.prototype.setProperty = function(propertyName, value) {
1239
+ var i, parent, _len, _ref;
1240
+ value = this.convertIfNecessary(value);
1241
+ this.registerPropertySet(propertyName);
1242
+ this[propertyName] = value;
1243
+ this.triggerPropertyChange(propertyName);
1244
+ parent = this;
1245
+ if (Array.isArray(this[propertyName])) {
1246
+ _ref = this[propertyName];
1247
+ for (i = 0, _len = _ref.length; i < _len; i++) {
1248
+ value = _ref[i];
1249
+ this[propertyName][i] = this.convertIfNecessary(value);
1250
+ }
1251
+ return this.addTriggersToArray(propertyName);
1252
+ }
1253
+ };
1254
+
1255
+ WingmanObject.prototype.registerPropertySet = function(propertyName) {
1256
+ return this.setPropertyNames().push(propertyName);
1257
+ };
1258
+
1259
+ WingmanObject.prototype.setPropertyNames = function() {
1260
+ return this._setPropertyNames || (this._setPropertyNames = []);
1261
+ };
1262
+
1263
+ WingmanObject.prototype.get = function(chainAsString) {
1264
+ var chain, nestedProperty, nestedPropertyName;
1265
+ chain = chainAsString.split('.');
1266
+ if (chain.length === 1) {
1267
+ return this.getProperty(chain[0]);
1268
+ } else {
1269
+ nestedPropertyName = chain.shift();
1270
+ nestedProperty = this.getProperty(nestedPropertyName);
1271
+ if (nestedProperty) {
1272
+ return nestedProperty.get(chain.join('.'));
1273
+ } else {
1274
+ return;
1275
+ }
1276
+ }
1277
+ };
1278
+
1279
+ WingmanObject.prototype.getProperty = function(propertyName) {
1280
+ if (typeof this[propertyName] === 'function') {
1281
+ return this[propertyName].apply(this);
1282
+ } else {
1283
+ return this[propertyName];
1284
+ }
1285
+ };
1286
+
1287
+ WingmanObject.prototype.toJSON = function(options) {
1288
+ var json, propertyName, shouldBeIncluded, _i, _len, _ref;
1289
+ if (options == null) options = {};
1290
+ if (options.only && !Array.isArray(options.only)) {
1291
+ options.only = [options.only];
1292
+ }
1293
+ json = {};
1294
+ _ref = this.setPropertyNames();
1295
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1296
+ propertyName = _ref[_i];
1297
+ shouldBeIncluded = (!options.only || (__indexOf.call(options.only, propertyName) >= 0)) && this.serializable(this.get(propertyName));
1298
+ if (shouldBeIncluded) json[propertyName] = this.get(propertyName);
1299
+ }
1300
+ return json;
1301
+ };
1302
+
1303
+ WingmanObject.prototype.serializable = function(value) {
1304
+ var _ref;
1305
+ return ((_ref = typeof value) === 'number' || _ref === 'string') || this.convertable(value);
1306
+ };
1307
+
1308
+ WingmanObject.prototype.convertIfNecessary = function(value) {
1309
+ var wo;
1310
+ if (this.convertable(value)) {
1311
+ wo = new WingmanObject;
1312
+ wo.set(value);
1313
+ return wo;
1314
+ } else {
1315
+ return value;
1316
+ }
1317
+ };
1318
+
1319
+ WingmanObject.prototype.convertable = function(value) {
1320
+ return typeof value === 'object' && ((value != null ? value.constructor : void 0) != null) && value.constructor.name === 'Object' && (!(value instanceof WingmanObject)) && !((value != null ? value._ownerDocument : void 0) != null);
1321
+ };
1322
+
1323
+ WingmanObject.prototype.addTriggersToArray = function(propertyName) {
1324
+ var array, parent;
1325
+ parent = this;
1326
+ array = this[propertyName];
1327
+ array.push = function() {
1328
+ Array.prototype.push.apply(this, arguments);
1329
+ return parent.trigger("add:" + propertyName, arguments['0']);
1330
+ };
1331
+ return array.remove = function(value) {
1332
+ var index;
1333
+ index = this.indexOf(value);
1334
+ if (index !== -1) {
1335
+ this.splice(index, 1);
1336
+ return parent.trigger("remove:" + propertyName, value);
1337
+ }
1338
+ };
1339
+ };
1340
+
1341
+ return WingmanObject;
1342
+
1343
+ })(Module);
1344
+
1345
+ module.exports = WingmanObject;
1346
+
1347
+ }).call(this);
1348
+ }, "wingman/template": function(exports, require, module) {(function() {
1349
+ var Fleck, NodeFactory, Parser, Template;
1350
+
1351
+ module.exports = Template = (function() {
1352
+
1353
+ Template.compile = function(source) {
1354
+ var template;
1355
+ template = new this(source);
1356
+ return function(el, context) {
1357
+ return template.evaluate(el, context);
1358
+ };
1359
+ };
1360
+
1361
+ function Template(source) {
1362
+ this.tree = Parser.parse(source);
1363
+ }
1364
+
1365
+ Template.prototype.evaluate = function(el, context) {
1366
+ var nodeData, _i, _len, _ref, _results;
1367
+ _ref = this.tree.children;
1368
+ _results = [];
1369
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1370
+ nodeData = _ref[_i];
1371
+ _results.push(NodeFactory.create(nodeData, el, context));
1372
+ }
1373
+ return _results;
1374
+ };
1375
+
1376
+ return Template;
1377
+
1378
+ })();
1379
+
1380
+ Parser = require('./template/parser');
1381
+
1382
+ NodeFactory = require('./template/node_factory');
1383
+
1384
+ Fleck = require('fleck');
1385
+
1386
+ }).call(this);
1387
+ }, "wingman/template/node_factory": function(exports, require, module) {(function() {
1388
+ var ChildView, Conditional, Element, ForBlock;
1389
+
1390
+ exports.create = function(nodeData, scope, context) {
1391
+ this.nodeData = nodeData;
1392
+ this.scope = scope;
1393
+ this.context = context;
1394
+ if (this.nodeData.type === 'for') {
1395
+ return new ForBlock(this.nodeData, this.scope, this.context);
1396
+ } else if (this.nodeData.type === 'childView') {
1397
+ return new ChildView(this.nodeData, this.scope, this.context);
1398
+ } else if (this.nodeData.type === 'conditional') {
1399
+ return new Conditional(this.nodeData, this.scope, this.context);
1400
+ } else {
1401
+ return new Element(this.nodeData, this.scope, this.context);
1402
+ }
1403
+ };
1404
+
1405
+ ForBlock = require('./node_factory/for_block');
1406
+
1407
+ ChildView = require('./node_factory/child_view');
1408
+
1409
+ Conditional = require('./node_factory/conditional');
1410
+
1411
+ Element = require('./node_factory/element');
1412
+
1413
+ }).call(this);
1414
+ }, "wingman/template/node_factory/child_view": function(exports, require, module) {(function() {
1415
+ var ChildView;
1416
+
1417
+ module.exports = ChildView = (function() {
1418
+
1419
+ function ChildView(nodeData, scope, context) {
1420
+ var element;
1421
+ this.nodeData = nodeData;
1422
+ this.scope = scope;
1423
+ this.context = context;
1424
+ this.view = this.context.createChildView(this.nodeData.name);
1425
+ if (this.context.get(this.nodeData.name)) {
1426
+ this.view.setProperty(this.nodeData.name, this.context.get(this.nodeData.name));
1427
+ }
1428
+ element = this.view.el;
1429
+ this.scope.appendChild(element);
1430
+ }
1431
+
1432
+ ChildView.prototype.remove = function() {
1433
+ return this.view.remove();
1434
+ };
1435
+
1436
+ return ChildView;
1437
+
1438
+ })();
1439
+
1440
+ }).call(this);
1441
+ }, "wingman/template/node_factory/conditional": function(exports, require, module) {(function() {
1442
+ var Conditional, NodeFactory,
1443
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
1444
+
1445
+ NodeFactory = require('../node_factory');
1446
+
1447
+ module.exports = Conditional = (function() {
1448
+
1449
+ function Conditional(nodeData, scope, context) {
1450
+ this.nodeData = nodeData;
1451
+ this.scope = scope;
1452
+ this.context = context;
1453
+ this.update = __bind(this.update, this);
1454
+ this.nodes = [];
1455
+ this.context.observe(this.nodeData.source, this.update);
1456
+ this.update(this.context.get(this.nodeData.source));
1457
+ }
1458
+
1459
+ Conditional.prototype.add = function(currentValue) {
1460
+ var newNodeData, node, _i, _j, _len, _len2, _ref, _ref2, _results, _results2;
1461
+ if (currentValue) {
1462
+ _ref = this.nodeData.trueChildren;
1463
+ _results = [];
1464
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1465
+ newNodeData = _ref[_i];
1466
+ node = NodeFactory.create(newNodeData, this.scope, this.context);
1467
+ _results.push(this.nodes.push(node));
1468
+ }
1469
+ return _results;
1470
+ } else if (this.nodeData.falseChildren) {
1471
+ _ref2 = this.nodeData.falseChildren;
1472
+ _results2 = [];
1473
+ for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
1474
+ newNodeData = _ref2[_j];
1475
+ node = NodeFactory.create(newNodeData, this.scope, this.context);
1476
+ _results2.push(this.nodes.push(node));
1477
+ }
1478
+ return _results2;
1479
+ }
1480
+ };
1481
+
1482
+ Conditional.prototype.remove = function() {
1483
+ var node, _results;
1484
+ _results = [];
1485
+ while (node = this.nodes.shift()) {
1486
+ _results.push(node.remove());
1487
+ }
1488
+ return _results;
1489
+ };
1490
+
1491
+ Conditional.prototype.update = function(currentValue) {
1492
+ this.remove();
1493
+ return this.add(currentValue);
1494
+ };
1495
+
1496
+ return Conditional;
1497
+
1498
+ })();
1499
+
1500
+ }).call(this);
1501
+ }, "wingman/template/node_factory/element": function(exports, require, module) {(function() {
1502
+ var Element, Elementary, Module, NodeFactory, Wingman,
1503
+ __hasProp = Object.prototype.hasOwnProperty,
1504
+ __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; };
1505
+
1506
+ Module = require('../../shared/module');
1507
+
1508
+ Elementary = require('../../shared/elementary');
1509
+
1510
+ module.exports = Element = (function(_super) {
1511
+
1512
+ __extends(Element, _super);
1513
+
1514
+ Element.include(Elementary);
1515
+
1516
+ function Element(elementData, scope, context) {
1517
+ this.elementData = elementData;
1518
+ this.scope = scope;
1519
+ this.context = context;
1520
+ this.domElement = Wingman.document.createElement(this.elementData.tag);
1521
+ this.addToScope();
1522
+ if (this.elementData.styles) this.setupStyles();
1523
+ if (this.elementData.classes) this.setupClasses();
1524
+ if (this.elementData.attributes) this.setupAttributes();
1525
+ if (this.elementData.value) {
1526
+ this.setupInnerHTML();
1527
+ } else if (this.elementData.children) {
1528
+ this.setupChildren();
1529
+ }
1530
+ }
1531
+
1532
+ Element.prototype.addToScope = function() {
1533
+ return this.scope.appendChild(this.domElement);
1534
+ };
1535
+
1536
+ Element.prototype.setupClasses = function() {
1537
+ var className, _i, _len, _ref, _results;
1538
+ _ref = this.elementData.classes;
1539
+ _results = [];
1540
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1541
+ className = _ref[_i];
1542
+ if (className.isDynamic) this.observeClass(className);
1543
+ _results.push(this.addClass(className.get(this.context)));
1544
+ }
1545
+ return _results;
1546
+ };
1547
+
1548
+ Element.prototype.setupAttributes = function() {
1549
+ var key, value, _ref, _results;
1550
+ _ref = this.elementData.attributes;
1551
+ _results = [];
1552
+ for (key in _ref) {
1553
+ value = _ref[key];
1554
+ this.setAttribute(key, value.get(this.context));
1555
+ if (value.isDynamic) {
1556
+ _results.push(this.observeAttribute(key, value));
1557
+ } else {
1558
+ _results.push(void 0);
1559
+ }
1560
+ }
1561
+ return _results;
1562
+ };
1563
+
1564
+ Element.prototype.observeAttribute = function(key, value) {
1565
+ var _this = this;
1566
+ return this.context.observe(value.get(), function(newValue) {
1567
+ return _this.setAttribute(key, newValue);
1568
+ });
1569
+ };
1570
+
1571
+ Element.prototype.observeClass = function(className) {
1572
+ var _this = this;
1573
+ return this.context.observe(className.get(), function(newClassName, oldClassName) {
1574
+ _this.removeClass(oldClassName);
1575
+ return _this.addClass(newClassName);
1576
+ });
1577
+ };
1578
+
1579
+ Element.prototype.setupStyles = function() {
1580
+ var key, value, _ref, _results;
1581
+ _ref = this.elementData.styles;
1582
+ _results = [];
1583
+ for (key in _ref) {
1584
+ value = _ref[key];
1585
+ if (value.isDynamic) this.observeStyle(key, value);
1586
+ _results.push(this.setStyle(key, value.get(this.context)));
1587
+ }
1588
+ return _results;
1589
+ };
1590
+
1591
+ Element.prototype.observeStyle = function(key, value) {
1592
+ var _this = this;
1593
+ return this.context.observe(value.get(), function(newValue) {
1594
+ return _this.setStyle(key, newValue);
1595
+ });
1596
+ };
1597
+
1598
+ Element.prototype.setupInnerHTML = function() {
1599
+ var _this = this;
1600
+ return this.domElement.innerHTML = this.elementData.value.isDynamic ? (this.context.observe(this.elementData.value.get(), function(newValue) {
1601
+ return _this.domElement.innerHTML = newValue;
1602
+ }), this.context.get(this.elementData.value.get())) : this.elementData.value.get();
1603
+ };
1604
+
1605
+ Element.prototype.setupChildren = function() {
1606
+ var child, _i, _len, _ref, _results;
1607
+ _ref = this.elementData.children;
1608
+ _results = [];
1609
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1610
+ child = _ref[_i];
1611
+ _results.push(NodeFactory.create(child, this.domElement, this.context));
1612
+ }
1613
+ return _results;
1614
+ };
1615
+
1616
+ return Element;
1617
+
1618
+ })(Module);
1619
+
1620
+ Wingman = require('../../../wingman');
1621
+
1622
+ NodeFactory = require('../node_factory');
1623
+
1624
+ }).call(this);
1625
+ }, "wingman/template/node_factory/for_block": function(exports, require, module) {(function() {
1626
+ var Fleck, ForBlock, NodeFactory, WingmanObject,
1627
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
1628
+
1629
+ WingmanObject = require('../../shared/object');
1630
+
1631
+ Fleck = require('fleck');
1632
+
1633
+ NodeFactory = require('../node_factory');
1634
+
1635
+ module.exports = ForBlock = (function() {
1636
+
1637
+ function ForBlock(nodeData, scope, context) {
1638
+ this.nodeData = nodeData;
1639
+ this.scope = scope;
1640
+ this.context = context;
1641
+ this.rebuild = __bind(this.rebuild, this);
1642
+ this.remove = __bind(this.remove, this);
1643
+ this.add = __bind(this.add, this);
1644
+ this.nodes = {};
1645
+ if (this.source()) this.addAll();
1646
+ this.context.observe(this.nodeData.source, this.rebuild);
1647
+ this.context.observe(this.nodeData.source, 'add', this.add);
1648
+ this.context.observe(this.nodeData.source, 'remove', this.remove);
1649
+ }
1650
+
1651
+ ForBlock.prototype.add = function(value) {
1652
+ var hash, key, newContext, newNodeData, node, _i, _len, _ref, _results,
1653
+ _this = this;
1654
+ this.nodes[value] = [];
1655
+ newContext = new WingmanObject;
1656
+ if (this.context.createChildView) {
1657
+ newContext.createChildView = function(name) {
1658
+ return _this.context.createChildView.call(_this.context, name);
1659
+ };
1660
+ }
1661
+ key = Fleck.singularize(this.nodeData.source.split('.').pop());
1662
+ hash = {};
1663
+ hash[key] = value;
1664
+ newContext.set(hash);
1665
+ _ref = this.nodeData.children;
1666
+ _results = [];
1667
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1668
+ newNodeData = _ref[_i];
1669
+ node = NodeFactory.create(newNodeData, this.scope, newContext);
1670
+ _results.push(this.nodes[value].push(node));
1671
+ }
1672
+ return _results;
1673
+ };
1674
+
1675
+ ForBlock.prototype.remove = function(value) {
1676
+ var node;
1677
+ while (this.nodes[value].length) {
1678
+ node = this.nodes[value].pop();
1679
+ node.remove();
1680
+ }
1681
+ return delete this.nodes[value];
1682
+ };
1683
+
1684
+ ForBlock.prototype.source = function() {
1685
+ return this.context.get(this.nodeData.source);
1686
+ };
1687
+
1688
+ ForBlock.prototype.addAll = function() {
1689
+ var _this = this;
1690
+ return this.source().forEach(function(value) {
1691
+ return _this.add(value);
1692
+ });
1693
+ };
1694
+
1695
+ ForBlock.prototype.removeAll = function() {
1696
+ var element, value, _ref, _results;
1697
+ _ref = this.nodes;
1698
+ _results = [];
1699
+ for (value in _ref) {
1700
+ element = _ref[value];
1701
+ _results.push(this.remove(value));
1702
+ }
1703
+ return _results;
1704
+ };
1705
+
1706
+ ForBlock.prototype.rebuild = function() {
1707
+ this.removeAll();
1708
+ if (this.source()) return this.addAll();
1709
+ };
1710
+
1711
+ return ForBlock;
1712
+
1713
+ })();
1714
+
1715
+ }).call(this);
1716
+ }, "wingman/template/parser": function(exports, require, module) {(function() {
1717
+ var StringScanner, Value, selfClosingTags;
1718
+
1719
+ StringScanner = require("strscan").StringScanner;
1720
+
1721
+ Value = require("./parser/value");
1722
+
1723
+ selfClosingTags = ['input', 'img', 'br', 'hr'];
1724
+
1725
+ module.exports = (function() {
1726
+
1727
+ _Class.parse = function(source) {
1728
+ var parser;
1729
+ parser = new this(source);
1730
+ parser.execute();
1731
+ return parser.tree;
1732
+ };
1733
+
1734
+ _Class.trimSource = function(source) {
1735
+ var line, lines, _i, _len, _ref;
1736
+ lines = [];
1737
+ _ref = source.split("\n");
1738
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1739
+ line = _ref[_i];
1740
+ lines.push(line.replace(/^ +/, ''));
1741
+ }
1742
+ return lines.join('').replace(/[\n\r\t]/g, '');
1743
+ };
1744
+
1745
+ function _Class(source) {
1746
+ this.scanner = new StringScanner(this.constructor.trimSource(source));
1747
+ this.tree = {
1748
+ children: []
1749
+ };
1750
+ this.currentScope = this.tree;
1751
+ }
1752
+
1753
+ _Class.prototype.execute = function() {
1754
+ var _results;
1755
+ _results = [];
1756
+ while (!this.done) {
1757
+ if (this.scanner.hasTerminated()) {
1758
+ _results.push(this.done = true);
1759
+ } else {
1760
+ _results.push(this.scan());
1761
+ }
1762
+ }
1763
+ return _results;
1764
+ };
1765
+
1766
+ _Class.prototype.scan = function() {
1767
+ return this.scanForEndTag() || this.scanForStartTag() || this.scanForIfToken() || this.scanForElseToken() || this.scanForViewToken() || this.scanForForToken() || this.scanForEndToken() || this.scanForText();
1768
+ };
1769
+
1770
+ _Class.prototype.scanForEndTag = function() {
1771
+ var result;
1772
+ result = this.scanner.scan(/<\/(.*?)>/);
1773
+ if (result) this.currentScope = this.currentScope.parent;
1774
+ return result;
1775
+ };
1776
+
1777
+ _Class.prototype.scanForStartTag = function() {
1778
+ var attributes, newNode, result;
1779
+ result = this.scanner.scan(/<([a-zA-Z0-9]+) *(.*?)>/);
1780
+ if (result) {
1781
+ newNode = {
1782
+ tag: this.scanner.getCapture(0),
1783
+ children: [],
1784
+ parent: this.currentScope,
1785
+ type: 'element'
1786
+ };
1787
+ if (this.scanner.getCapture(1)) {
1788
+ attributes = this.parseAttributes(this.scanner.getCapture(1));
1789
+ this.addAttributes(newNode, attributes);
1790
+ }
1791
+ this.currentScope.children.push(newNode);
1792
+ if (selfClosingTags.indexOf(newNode.tag) === -1) {
1793
+ this.currentScope = newNode;
1794
+ }
1795
+ }
1796
+ return result;
1797
+ };
1798
+
1799
+ _Class.prototype.scanForForToken = function() {
1800
+ var newNode, result;
1801
+ result = this.scanner.scan(/\{for (.*?)\}/);
1802
+ if (result) {
1803
+ newNode = {
1804
+ source: this.scanner.getCapture(0),
1805
+ children: [],
1806
+ parent: this.currentScope,
1807
+ type: 'for'
1808
+ };
1809
+ this.currentScope.children.push(newNode);
1810
+ this.currentScope = newNode;
1811
+ }
1812
+ return result;
1813
+ };
1814
+
1815
+ _Class.prototype.scanForViewToken = function() {
1816
+ var newNode, result;
1817
+ result = this.scanner.scan(/\{view (.*?)\}/);
1818
+ if (result) {
1819
+ newNode = {
1820
+ name: this.scanner.getCapture(0),
1821
+ parent: this.currentScope,
1822
+ type: 'childView'
1823
+ };
1824
+ this.currentScope.children.push(newNode);
1825
+ }
1826
+ return result;
1827
+ };
1828
+
1829
+ _Class.prototype.scanForIfToken = function() {
1830
+ var newNode, result;
1831
+ result = this.scanner.scan(/\{if (.*?)\}/);
1832
+ if (result) {
1833
+ newNode = {
1834
+ source: this.scanner.getCapture(0),
1835
+ parent: this.currentScope,
1836
+ type: 'conditional',
1837
+ children: []
1838
+ };
1839
+ newNode.trueChildren = newNode.children;
1840
+ this.currentScope.children.push(newNode);
1841
+ this.currentScope = newNode;
1842
+ }
1843
+ return result;
1844
+ };
1845
+
1846
+ _Class.prototype.scanForElseToken = function() {
1847
+ var result;
1848
+ result = this.scanner.scan(/\{else\}/);
1849
+ if (result) {
1850
+ this.currentScope.children = this.currentScope.falseChildren = [];
1851
+ }
1852
+ return result;
1853
+ };
1854
+
1855
+ _Class.prototype.scanForEndToken = function() {
1856
+ var result;
1857
+ result = this.scanner.scan(/\{end\}/);
1858
+ if (result) {
1859
+ if (this.currentScope.type === 'conditional') {
1860
+ delete this.currentScope.children;
1861
+ }
1862
+ this.currentScope = this.currentScope.parent;
1863
+ }
1864
+ return result;
1865
+ };
1866
+
1867
+ _Class.prototype.scanForText = function() {
1868
+ var result;
1869
+ result = this.scanner.scanUntil(/</);
1870
+ this.currentScope.value = new Value(result.substr(0, result.length - 1));
1871
+ this.scanner.head -= 1;
1872
+ return result;
1873
+ };
1874
+
1875
+ _Class.prototype.parseAttributes = function(attributesAsString) {
1876
+ var attributes;
1877
+ attributes = {};
1878
+ attributesAsString.replace(new RegExp('([a-z]+)="(.*?)"', "g"), function($0, $1, $2) {
1879
+ return attributes[$1] = $2;
1880
+ });
1881
+ return attributes;
1882
+ };
1883
+
1884
+ _Class.prototype.parseStyle = function(stylesAsString) {
1885
+ var re, split, styleAsString, styles, _i, _len, _ref;
1886
+ re = new RegExp(' ', 'g');
1887
+ styles = {};
1888
+ _ref = stylesAsString.replace(re, '').split(';');
1889
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1890
+ styleAsString = _ref[_i];
1891
+ split = styleAsString.split(':');
1892
+ styles[split[0]] = new Value(split[1]);
1893
+ }
1894
+ return styles;
1895
+ };
1896
+
1897
+ _Class.prototype.parseClass = function(classesAsString) {
1898
+ var classes, klass, _i, _len, _ref;
1899
+ classes = [];
1900
+ _ref = classesAsString.split(' ');
1901
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1902
+ klass = _ref[_i];
1903
+ classes.push(new Value(klass));
1904
+ }
1905
+ return classes;
1906
+ };
1907
+
1908
+ _Class.prototype.addAttributes = function(node, attributes) {
1909
+ var key, value, _results;
1910
+ if (attributes.style) {
1911
+ node.styles = this.parseStyle(attributes.style);
1912
+ delete attributes.style;
1913
+ }
1914
+ if (attributes["class"]) {
1915
+ node.classes = this.parseClass(attributes["class"]);
1916
+ delete attributes["class"];
1917
+ }
1918
+ if (Object.keys(attributes).length !== 0) {
1919
+ node.attributes = {};
1920
+ _results = [];
1921
+ for (key in attributes) {
1922
+ value = attributes[key];
1923
+ _results.push(node.attributes[key] = new Value(value));
1924
+ }
1925
+ return _results;
1926
+ }
1927
+ };
1928
+
1929
+ return _Class;
1930
+
1931
+ })();
1932
+
1933
+ }).call(this);
1934
+ }, "wingman/template/parser/value": function(exports, require, module) {(function() {
1935
+
1936
+ module.exports = (function() {
1937
+
1938
+ function _Class(body) {
1939
+ var match;
1940
+ this.body = body;
1941
+ match = this.body.match(/^\{(.*?)\}$/);
1942
+ this.isDynamic = !!match;
1943
+ if (this.isDynamic) this.body = match[1];
1944
+ }
1945
+
1946
+ _Class.prototype.get = function(context) {
1947
+ if (this.isDynamic && context) {
1948
+ return context.get(this.body);
1949
+ } else {
1950
+ return this.body;
1951
+ }
1952
+ };
1953
+
1954
+ return _Class;
1955
+
1956
+ })();
1957
+
1958
+ }).call(this);
1959
+ }, "wingman/view": function(exports, require, module) {(function() {
1960
+ var Elementary, Fleck, STYLE_NAMES, Wingman, WingmanObject,
1961
+ __hasProp = Object.prototype.hasOwnProperty,
1962
+ __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; },
1963
+ __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
1964
+
1965
+ Wingman = require('../wingman');
1966
+
1967
+ WingmanObject = require('./shared/object');
1968
+
1969
+ Elementary = require('./shared/elementary');
1970
+
1971
+ Fleck = require('fleck');
1972
+
1973
+ STYLE_NAMES = ['backgroundImage', 'left', 'right', 'top', 'bottom', 'backgroundPosition'];
1974
+
1975
+ module.exports = (function(_super) {
1976
+
1977
+ __extends(_Class, _super);
1978
+
1979
+ _Class.include(Elementary);
1980
+
1981
+ _Class.parseEvents = function(eventsHash) {
1982
+ var key, trigger, _results;
1983
+ _results = [];
1984
+ for (key in eventsHash) {
1985
+ trigger = eventsHash[key];
1986
+ _results.push(this.parseEvent(key, trigger));
1987
+ }
1988
+ return _results;
1989
+ };
1990
+
1991
+ _Class.parseEvent = function(key, trigger) {
1992
+ var type;
1993
+ type = key.split(' ')[0];
1994
+ return {
1995
+ selector: key.substring(type.length + 1),
1996
+ type: type,
1997
+ trigger: trigger
1998
+ };
1999
+ };
2000
+
2001
+ function _Class(options) {
2002
+ _Class.__super__.constructor.call(this);
2003
+ if ((options != null ? options.parent : void 0) != null) {
2004
+ this.set({
2005
+ parent: options.parent
2006
+ });
2007
+ }
2008
+ if ((options != null ? options.app : void 0) != null) {
2009
+ this.set({
2010
+ app: options.app
2011
+ });
2012
+ }
2013
+ this.el = this.domElement = (options != null ? options.el : void 0) || Wingman.document.createElement(this.tag || 'div');
2014
+ if (options != null ? options.render : void 0) this.render();
2015
+ }
2016
+
2017
+ _Class.prototype.render = function() {
2018
+ var template, templateSource;
2019
+ templateSource = this.get('templateSource');
2020
+ if (templateSource) {
2021
+ template = Wingman.Template.compile(templateSource);
2022
+ template(this.el, this);
2023
+ }
2024
+ this.addClass(this.pathName());
2025
+ this.setupListeners();
2026
+ this.setupStyles();
2027
+ return typeof this.ready === "function" ? this.ready() : void 0;
2028
+ };
2029
+
2030
+ _Class.prototype.createChildView = function(viewName) {
2031
+ var className, klass, view,
2032
+ _this = this;
2033
+ className = Fleck.camelize(Fleck.underscore(viewName), true) + 'View';
2034
+ klass = this.constructor[className];
2035
+ view = new klass({
2036
+ parent: this,
2037
+ app: this.get('app')
2038
+ });
2039
+ view.bind('descendantCreated', function(view) {
2040
+ return _this.trigger('descendantCreated', view);
2041
+ });
2042
+ this.trigger('descendantCreated', view);
2043
+ view.render();
2044
+ return view;
2045
+ };
2046
+
2047
+ _Class.prototype.templateSource = function() {
2048
+ var name, templateSource;
2049
+ name = this.get('templateName');
2050
+ templateSource = this.constructor.templateSources[name];
2051
+ if (!templateSource) throw new Error("Template '" + name + "' not found.");
2052
+ return templateSource;
2053
+ };
2054
+
2055
+ _Class.prototype.templateName = function() {
2056
+ return this.path();
2057
+ };
2058
+
2059
+ _Class.prototype.setupListeners = function() {
2060
+ var _this = this;
2061
+ this.el.addEventListener('click', function(e) {
2062
+ if (_this.click) return _this.click(e);
2063
+ });
2064
+ if (this.events) return this.setupEvents();
2065
+ };
2066
+
2067
+ _Class.prototype.setupEvents = function() {
2068
+ var event, _i, _len, _ref, _results;
2069
+ _ref = this.constructor.parseEvents(this.events);
2070
+ _results = [];
2071
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
2072
+ event = _ref[_i];
2073
+ _results.push(this.setupEvent(event));
2074
+ }
2075
+ return _results;
2076
+ };
2077
+
2078
+ _Class.prototype.triggerWithCustomArguments = function(trigger) {
2079
+ var args, argumentsMethodName, customArguments;
2080
+ args = [trigger];
2081
+ argumentsMethodName = Fleck.camelize(trigger) + "Arguments";
2082
+ customArguments = typeof this[argumentsMethodName] === "function" ? this[argumentsMethodName]() : void 0;
2083
+ if (customArguments) args.push.apply(args, customArguments);
2084
+ return this.trigger.apply(this, args);
2085
+ };
2086
+
2087
+ _Class.prototype.setupEvent = function(event) {
2088
+ var _this = this;
2089
+ return this.el.addEventListener(event.type, function(e) {
2090
+ var current, elm, match, _i, _len, _ref, _results;
2091
+ _ref = Array.prototype.slice.call(_this.el.querySelectorAll(event.selector), 0);
2092
+ _results = [];
2093
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
2094
+ elm = _ref[_i];
2095
+ current = e.target;
2096
+ while (current !== _this.el && !match) {
2097
+ match = elm === current;
2098
+ current = current.parentNode;
2099
+ }
2100
+ if (match) {
2101
+ _this.triggerWithCustomArguments(event.trigger);
2102
+ _results.push(e.preventDefault());
2103
+ } else {
2104
+ _results.push(void 0);
2105
+ }
2106
+ }
2107
+ return _results;
2108
+ });
2109
+ };
2110
+
2111
+ _Class.prototype.pathName = function() {
2112
+ return Fleck.underscore(this.constructor.name.replace(/([A-Z])/g, ' $1').substring(1).split(' ').slice(0, -1).join(''));
2113
+ };
2114
+
2115
+ _Class.prototype.append = function(view) {
2116
+ return this.el.appendChild(view.el);
2117
+ };
2118
+
2119
+ _Class.prototype.pathKeys = function() {
2120
+ var pathKeys, _ref;
2121
+ if (this.isRoot()) return [];
2122
+ pathKeys = [this.pathName()];
2123
+ if (((_ref = this.get('parent')) != null ? _ref.pathKeys : void 0) != null) {
2124
+ pathKeys = this.get('parent').pathKeys().concat(pathKeys);
2125
+ }
2126
+ return pathKeys;
2127
+ };
2128
+
2129
+ _Class.prototype.isRoot = function() {
2130
+ return this.get('parent') instanceof Wingman.Application;
2131
+ };
2132
+
2133
+ _Class.prototype.path = function() {
2134
+ if (this.get('parent') instanceof Wingman.Application) {
2135
+ return 'root';
2136
+ } else {
2137
+ return this.pathKeys().join('.');
2138
+ }
2139
+ };
2140
+
2141
+ _Class.prototype.setupStyles = function() {
2142
+ var name, property, _results;
2143
+ _results = [];
2144
+ for (name in this) {
2145
+ property = this[name];
2146
+ if (__indexOf.call(STYLE_NAMES, name) >= 0) {
2147
+ _results.push(this.setupStyle(name));
2148
+ } else {
2149
+ _results.push(void 0);
2150
+ }
2151
+ }
2152
+ return _results;
2153
+ };
2154
+
2155
+ _Class.prototype.setupStyle = function(name) {
2156
+ var _this = this;
2157
+ this.setStyle(name, this.get(name));
2158
+ return this.observe(name, function(newValue) {
2159
+ return _this.setStyle(name, newValue);
2160
+ });
2161
+ };
2162
+
2163
+ return _Class;
2164
+
2165
+ })(WingmanObject);
2166
+
2167
+ }).call(this);
2168
+ }, "strscan": function(exports, require, module) {(function() {
2169
+ var StringScanner;
2170
+ ((typeof exports !== "undefined" && exports !== null) ? exports : this).StringScanner = (function() {
2171
+ StringScanner = function(source) {
2172
+ this.source = source.toString();
2173
+ this.reset();
2174
+ return this;
2175
+ };
2176
+ StringScanner.prototype.scan = function(regexp) {
2177
+ var matches;
2178
+ return (matches = regexp.exec(this.getRemainder())) && matches.index === 0 ? this.setState(matches, {
2179
+ head: this.head + matches[0].length,
2180
+ last: this.head
2181
+ }) : this.setState([]);
2182
+ };
2183
+ StringScanner.prototype.scanUntil = function(regexp) {
2184
+ var matches;
2185
+ if (matches = regexp.exec(this.getRemainder())) {
2186
+ this.setState(matches, {
2187
+ head: this.head + matches.index + matches[0].length,
2188
+ last: this.head
2189
+ });
2190
+ return this.source.slice(this.last, this.head);
2191
+ } else {
2192
+ return this.setState([]);
2193
+ }
2194
+ };
2195
+ StringScanner.prototype.scanChar = function() {
2196
+ return this.scan(/[\s\S]/);
2197
+ };
2198
+ StringScanner.prototype.skip = function(regexp) {
2199
+ if (this.scan(regexp)) {
2200
+ return this.match.length;
2201
+ }
2202
+ };
2203
+ StringScanner.prototype.skipUntil = function(regexp) {
2204
+ if (this.scanUntil(regexp)) {
2205
+ return this.head - this.last;
2206
+ }
2207
+ };
2208
+ StringScanner.prototype.check = function(regexp) {
2209
+ var matches;
2210
+ return (matches = regexp.exec(this.getRemainder())) && matches.index === 0 ? this.setState(matches) : this.setState([]);
2211
+ };
2212
+ StringScanner.prototype.checkUntil = function(regexp) {
2213
+ var matches;
2214
+ if (matches = regexp.exec(this.getRemainder())) {
2215
+ this.setState(matches);
2216
+ return this.source.slice(this.head, this.head + matches.index + matches[0].length);
2217
+ } else {
2218
+ return this.setState([]);
2219
+ }
2220
+ };
2221
+ StringScanner.prototype.peek = function(length) {
2222
+ return this.source.substr(this.head, (typeof length !== "undefined" && length !== null) ? length : 1);
2223
+ };
2224
+ StringScanner.prototype.getSource = function() {
2225
+ return this.source;
2226
+ };
2227
+ StringScanner.prototype.getRemainder = function() {
2228
+ return this.source.slice(this.head);
2229
+ };
2230
+ StringScanner.prototype.getPosition = function() {
2231
+ return this.head;
2232
+ };
2233
+ StringScanner.prototype.hasTerminated = function() {
2234
+ return this.head === this.source.length;
2235
+ };
2236
+ StringScanner.prototype.getPreMatch = function() {
2237
+ if (this.match) {
2238
+ return this.source.slice(0, this.head - this.match.length);
2239
+ }
2240
+ };
2241
+ StringScanner.prototype.getMatch = function() {
2242
+ return this.match;
2243
+ };
2244
+ StringScanner.prototype.getPostMatch = function() {
2245
+ if (this.match) {
2246
+ return this.source.slice(this.head);
2247
+ }
2248
+ };
2249
+ StringScanner.prototype.getCapture = function(index) {
2250
+ return this.captures[index];
2251
+ };
2252
+ StringScanner.prototype.reset = function() {
2253
+ return this.setState([], {
2254
+ head: 0,
2255
+ last: 0
2256
+ });
2257
+ };
2258
+ StringScanner.prototype.terminate = function() {
2259
+ return this.setState([], {
2260
+ head: this.source.length,
2261
+ last: this.head
2262
+ });
2263
+ };
2264
+ StringScanner.prototype.concat = function(string) {
2265
+ return this.source += string;
2266
+ };
2267
+ StringScanner.prototype.unscan = function() {
2268
+ if (this.match) {
2269
+ return this.setState([], {
2270
+ head: this.last,
2271
+ last: 0
2272
+ });
2273
+ } else {
2274
+ throw "nothing to unscan";
2275
+ }
2276
+ };
2277
+ StringScanner.prototype.setState = function(matches, values) {
2278
+ var _a, _b;
2279
+ this.head = (typeof (_a = ((typeof values === "undefined" || values === null) ? undefined : values.head)) !== "undefined" && _a !== null) ? _a : this.head;
2280
+ this.last = (typeof (_b = ((typeof values === "undefined" || values === null) ? undefined : values.last)) !== "undefined" && _b !== null) ? _b : this.last;
2281
+ this.captures = matches.slice(1);
2282
+ return (this.match = matches[0]);
2283
+ };
2284
+ return StringScanner;
2285
+ })();
2286
+ })();
2287
+ }, "fleck": function(exports, require, module) {/*!
2288
+ * fleck - functional style string inflections
2289
+ * https://github.com/trek/fleck
2290
+ * copyright Trek Glowacki
2291
+ * MIT License
2292
+ */
2293
+
2294
+ !function (name, definition) {
2295
+ if (typeof module != 'undefined') module.exports = definition()
2296
+ else if (typeof define == 'function' && typeof define.amd == 'object') define(definition)
2297
+ else this[name] = definition()
2298
+ }('fleck', function () {
2299
+
2300
+ var lib = {
2301
+ // plural rules, singular rules, and starting uncountables
2302
+ // from http://code.google.com/p/inflection-js/
2303
+ // with corrections for ordering and spelling
2304
+ pluralRules: [
2305
+ [new RegExp('(m)an$', 'gi'), '$1en'],
2306
+ [new RegExp('(pe)rson$', 'gi'), '$1ople'],
2307
+ [new RegExp('(child)$', 'gi'), '$1ren'],
2308
+ [new RegExp('^(ox)$', 'gi'), '$1en'],
2309
+ [new RegExp('(ax|test)is$', 'gi'), '$1es'],
2310
+ [new RegExp('(octop|vir)us$', 'gi'), '$1i'],
2311
+ [new RegExp('(alias|status)$', 'gi'), '$1es'],
2312
+ [new RegExp('(bu)s$', 'gi'), '$1ses'],
2313
+ [new RegExp('(buffal|tomat|potat)o$', 'gi'), '$1oes'],
2314
+ [new RegExp('([ti])um$', 'gi'), '$1a'],
2315
+ [new RegExp('sis$', 'gi'), 'ses'],
2316
+ [new RegExp('(?:([^f])fe|([lr])f)$', 'gi'), '$1$2ves'],
2317
+ [new RegExp('(hive)$', 'gi'), '$1s'],
2318
+ [new RegExp('([^aeiouy]|qu)y$', 'gi'), '$1ies'],
2319
+ [new RegExp('(matr|vert|ind)ix|ex$', 'gi'), '$1ices'],
2320
+ [new RegExp('(x|ch|ss|sh)$', 'gi'), '$1es'],
2321
+ [new RegExp('([m|l])ouse$', 'gi'), '$1ice'],
2322
+ [new RegExp('(quiz)$', 'gi'), '$1zes'],
2323
+ [new RegExp('s$', 'gi'), 's'],
2324
+ [new RegExp('$', 'gi'), 's']
2325
+ ],
2326
+ singularRules: [
2327
+ [new RegExp('(m)en$', 'gi'), '$1an'],
2328
+ [new RegExp('(pe)ople$', 'gi'), '$1rson'],
2329
+ [new RegExp('(child)ren$', 'gi'), '$1'],
2330
+ [new RegExp('([ti])a$', 'gi'), '$1um'],
2331
+ [new RegExp('((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$','gi'), '$1$2sis'],
2332
+ [new RegExp('(hive)s$', 'gi'), '$1'],
2333
+ [new RegExp('(tive)s$', 'gi'), '$1'],
2334
+ [new RegExp('(curve)s$', 'gi'), '$1'],
2335
+ [new RegExp('([lr])ves$', 'gi'), '$1f'],
2336
+ [new RegExp('([^fo])ves$', 'gi'), '$1fe'],
2337
+ [new RegExp('([^aeiouy]|qu)ies$', 'gi'), '$1y'],
2338
+ [new RegExp('(s)eries$', 'gi'), '$1eries'],
2339
+ [new RegExp('(m)ovies$', 'gi'), '$1ovie'],
2340
+ [new RegExp('(x|ch|ss|sh)es$', 'gi'), '$1'],
2341
+ [new RegExp('([m|l])ice$', 'gi'), '$1ouse'],
2342
+ [new RegExp('(bus)es$', 'gi'), '$1'],
2343
+ [new RegExp('(o)es$', 'gi'), '$1'],
2344
+ [new RegExp('(shoe)s$', 'gi'), '$1'],
2345
+ [new RegExp('(cris|ax|test)es$', 'gi'), '$1is'],
2346
+ [new RegExp('(octop|vir)i$', 'gi'), '$1us'],
2347
+ [new RegExp('(alias|status)es$', 'gi'), '$1'],
2348
+ [new RegExp('^(ox)en', 'gi'), '$1'],
2349
+ [new RegExp('(vert|ind)ices$', 'gi'), '$1ex'],
2350
+ [new RegExp('(matr)ices$', 'gi'), '$1ix'],
2351
+ [new RegExp('(quiz)zes$', 'gi'), '$1'],
2352
+ [new RegExp('s$', 'gi'), '']
2353
+ ],
2354
+ uncountableWords: {
2355
+ 'equipment': true,
2356
+ 'information': true,
2357
+ 'rice': true,
2358
+ 'money': true,
2359
+ 'species': true,
2360
+ 'series':true,
2361
+ 'fish':true,
2362
+ 'sheep':true,
2363
+ 'moose':true,
2364
+ 'deer':true,
2365
+ 'news':true
2366
+ },
2367
+ // Chain multiple inflections into a signle call
2368
+ // Examples:
2369
+ // lib.inflect(' posts', 'strip', 'singularize', 'capitalize') == 'Post'
2370
+ inflect: function(str){
2371
+ for (var i = 1, l = arguments.length; i < l; i++) {
2372
+ str = lib[arguments[i]](str);
2373
+ };
2374
+
2375
+ return str;
2376
+ },
2377
+ // Uppercases the first letter and lowercases all other letters
2378
+ // Examples:
2379
+ // lib.capitalize("message_properties") == "Message_properties"
2380
+ // lib.capitalize("message properties") == "Message properties"
2381
+ capitalize: function(str) {
2382
+ return str.charAt(0).toUpperCase() + str.substring(1).toLowerCase();
2383
+ },
2384
+ // lib.camelize("message_properties") == "messageProperties"
2385
+ // lib.camelize('-moz-border-radius') == 'mozBorderRadius'
2386
+ // lib.camelize("message_properties", true) == "MessageProperties"
2387
+ camelize: function(str, upper){
2388
+ if (upper) { return lib.upperCamelize(str) };
2389
+ return str.replace(/[-_]+(.)?/g, function(match, chr) {
2390
+ return chr ? chr.toUpperCase() : '';
2391
+ });
2392
+ },
2393
+ // lib.upperCamelize("message_properties") == "MessageProperties"
2394
+ upperCamelize: function(str){
2395
+ return lib.camelize(lib.capitalize(str));
2396
+ },
2397
+ // Replaces all spaces or underscores with dashes
2398
+ // Examples:
2399
+ // lib.dasherize("message_properties") == "message-properties"
2400
+ // lib.dasherize("Message properties") == "Message-properties"
2401
+ dasherize: function(str){
2402
+ return str.replace(/\s|_/g, '-');
2403
+ },
2404
+ // turns number or string formatted number into ordinalize version
2405
+ // Examples:
2406
+ // lib.ordinalize(4) == "4th"
2407
+ // lib.ordinalize("13") == "13th"
2408
+ // lib.ordinalize("122") == "122nd"
2409
+ ordinalize: function(str){
2410
+ var isTeen, r, n;
2411
+ n = parseInt(str, 10) % 100;
2412
+ isTeen = { 11: true, 12: true, 13: true}[n];
2413
+ if(isTeen) {return str + 'th'};
2414
+ n = parseInt(str, 10) % 10
2415
+ switch(n) {
2416
+ case 1:
2417
+ r = str + 'st';
2418
+ break;
2419
+ case 2:
2420
+ r = str + 'nd';
2421
+ break;
2422
+ case 3:
2423
+ r = str + 'rd';
2424
+ break;
2425
+ default:
2426
+ r = str + 'th';
2427
+ }
2428
+ return r;
2429
+ },
2430
+ pluralize: function(str){
2431
+ var uncountable = lib.uncountableWords[str.toLowerCase()];
2432
+ if (uncountable) {
2433
+ return str;
2434
+ };
2435
+ var rules = lib.pluralRules;
2436
+ for(var i = 0, l = rules.length; i < l; i++){
2437
+ if (str.match(rules[i][0])) {
2438
+ str = str.replace(rules[i][0], rules[i][1]);
2439
+ break;
2440
+ };
2441
+ }
2442
+
2443
+ return str;
2444
+ },
2445
+ singularize: function(str){
2446
+ var uncountable = lib.uncountableWords[str.toLowerCase()];
2447
+ if (uncountable) {
2448
+ return str;
2449
+ };
2450
+ var rules = lib.singularRules;
2451
+ for(var i = 0, l = rules.length; i < l; i++){
2452
+ if (str.match(rules[i][0])) {
2453
+ str = str.replace(rules[i][0], rules[i][1]);
2454
+ break;
2455
+ };
2456
+ }
2457
+
2458
+ return str;
2459
+ },
2460
+ // Removes leading and trailing whitespace
2461
+ // Examples:
2462
+ // lib.strip(" hello world! ") == "hello world!"
2463
+ strip: function(str){
2464
+ // implementation from Prototype.js
2465
+ return str.replace(/^\s+/, '').replace(/\s+$/, '');
2466
+ },
2467
+ // Converts a camelized string into a series of words separated by an
2468
+ // underscore (`_`).
2469
+ // Examples
2470
+ // lib.underscore('borderBottomWidth') == "border_bottom_width"
2471
+ // lib.underscore('border-bottom-width') == "border_bottom_width"
2472
+ // lib.underscore('Foo::Bar') == "foo_bar"
2473
+ underscore: function(str){
2474
+ // implementation from Prototype.js
2475
+ return str.replace(/::/g, '/')
2476
+ .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
2477
+ .replace(/([a-z\d])([A-Z])/g, '$1_$2')
2478
+ .replace(/-/g, '_')
2479
+ .toLowerCase();
2480
+ },
2481
+
2482
+ // add an uncountable word
2483
+ // fleck.uncountable('ninja', 'tsumani');
2484
+ uncountable: function(){
2485
+ for(var i=0,l=arguments.length; i<l; i++){
2486
+ lib.uncountableWords[arguments[i]] = true;
2487
+ }
2488
+ return lib;
2489
+ }
2490
+ };
2491
+
2492
+ return lib;
2493
+
2494
+ });
2495
+ }});
2496
+
2497
+ window.Wingman = require('wingman');
2498
+ })(window);