emerson 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,6 @@
1
1
  require 'rails'
2
+ require 'emerson/rails/engine'
2
3
 
3
4
  module Emerson
4
- module Rails
5
- autoload :Engine, 'emerson/rails'
6
- end
5
+ module Rails ; end
7
6
  end
@@ -1,3 +1,3 @@
1
1
  module Emerson
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -5,9 +5,10 @@
5
5
  // For all details and documentation:
6
6
  // http://coolerator.net
7
7
 
8
- //= require emerson/base.js
9
- //= require emerson/util.js
10
- //= require emerson/http.js
11
- //= require emerson/sink.js
12
- //= require emerson/view.js
8
+ //= require underscore
9
+ //= require emerson/base
10
+ //= require emerson/util
11
+ //= require emerson/http
12
+ //= require emerson/sink
13
+ //= require emerson/view
13
14
  // @private
@@ -0,0 +1,1072 @@
1
+ // Underscore.js 1.3.3
2
+ // (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
3
+ // Underscore is freely distributable under the MIT license.
4
+ // Portions of Underscore are inspired or borrowed from Prototype,
5
+ // Oliver Steele's Functional, and John Resig's Micro-Templating.
6
+ // For all details and documentation:
7
+ // http://documentcloud.github.com/underscore
8
+
9
+ (function() {
10
+
11
+ // Baseline setup
12
+ // --------------
13
+
14
+ // Establish the root object, `window` in the browser, or `global` on the server.
15
+ var root = this;
16
+
17
+ // Save the previous value of the `_` variable.
18
+ var previousUnderscore = root._;
19
+
20
+ // Establish the object that gets returned to break out of a loop iteration.
21
+ var breaker = {};
22
+
23
+ // Save bytes in the minified (but not gzipped) version:
24
+ var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
25
+
26
+ // Create quick reference variables for speed access to core prototypes.
27
+ var push = ArrayProto.push,
28
+ slice = ArrayProto.slice,
29
+ unshift = ArrayProto.unshift,
30
+ toString = ObjProto.toString,
31
+ hasOwnProperty = ObjProto.hasOwnProperty;
32
+
33
+ // All **ECMAScript 5** native function implementations that we hope to use
34
+ // are declared here.
35
+ var
36
+ nativeForEach = ArrayProto.forEach,
37
+ nativeMap = ArrayProto.map,
38
+ nativeReduce = ArrayProto.reduce,
39
+ nativeReduceRight = ArrayProto.reduceRight,
40
+ nativeFilter = ArrayProto.filter,
41
+ nativeEvery = ArrayProto.every,
42
+ nativeSome = ArrayProto.some,
43
+ nativeIndexOf = ArrayProto.indexOf,
44
+ nativeLastIndexOf = ArrayProto.lastIndexOf,
45
+ nativeIsArray = Array.isArray,
46
+ nativeKeys = Object.keys,
47
+ nativeBind = FuncProto.bind;
48
+
49
+ // Create a safe reference to the Underscore object for use below.
50
+ var _ = function(obj) { return new wrapper(obj); };
51
+
52
+ // Export the Underscore object for **Node.js**, with
53
+ // backwards-compatibility for the old `require()` API. If we're in
54
+ // the browser, add `_` as a global object via a string identifier,
55
+ // for Closure Compiler "advanced" mode.
56
+ if (typeof exports !== 'undefined') {
57
+ if (typeof module !== 'undefined' && module.exports) {
58
+ exports = module.exports = _;
59
+ }
60
+ exports._ = _;
61
+ } else {
62
+ root['_'] = _;
63
+ }
64
+
65
+ // Current version.
66
+ _.VERSION = '1.3.3';
67
+
68
+ // Collection Functions
69
+ // --------------------
70
+
71
+ // The cornerstone, an `each` implementation, aka `forEach`.
72
+ // Handles objects with the built-in `forEach`, arrays, and raw objects.
73
+ // Delegates to **ECMAScript 5**'s native `forEach` if available.
74
+ var each = _.each = _.forEach = function(obj, iterator, context) {
75
+ if (obj == null) return;
76
+ if (nativeForEach && obj.forEach === nativeForEach) {
77
+ obj.forEach(iterator, context);
78
+ } else if (obj.length === +obj.length) {
79
+ for (var i = 0, l = obj.length; i < l; i++) {
80
+ if (i in obj && iterator.call(context, obj[i], i, obj) === breaker) return;
81
+ }
82
+ } else {
83
+ for (var key in obj) {
84
+ if (_.has(obj, key)) {
85
+ if (iterator.call(context, obj[key], key, obj) === breaker) return;
86
+ }
87
+ }
88
+ }
89
+ };
90
+
91
+ // Return the results of applying the iterator to each element.
92
+ // Delegates to **ECMAScript 5**'s native `map` if available.
93
+ _.map = _.collect = function(obj, iterator, context) {
94
+ var results = [];
95
+ if (obj == null) return results;
96
+ if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
97
+ each(obj, function(value, index, list) {
98
+ results[results.length] = iterator.call(context, value, index, list);
99
+ });
100
+ if (obj.length === +obj.length) results.length = obj.length;
101
+ return results;
102
+ };
103
+
104
+ // **Reduce** builds up a single result from a list of values, aka `inject`,
105
+ // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available.
106
+ _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
107
+ var initial = arguments.length > 2;
108
+ if (obj == null) obj = [];
109
+ if (nativeReduce && obj.reduce === nativeReduce) {
110
+ if (context) iterator = _.bind(iterator, context);
111
+ return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
112
+ }
113
+ each(obj, function(value, index, list) {
114
+ if (!initial) {
115
+ memo = value;
116
+ initial = true;
117
+ } else {
118
+ memo = iterator.call(context, memo, value, index, list);
119
+ }
120
+ });
121
+ if (!initial) throw new TypeError('Reduce of empty array with no initial value');
122
+ return memo;
123
+ };
124
+
125
+ // The right-associative version of reduce, also known as `foldr`.
126
+ // Delegates to **ECMAScript 5**'s native `reduceRight` if available.
127
+ _.reduceRight = _.foldr = function(obj, iterator, memo, context) {
128
+ var initial = arguments.length > 2;
129
+ if (obj == null) obj = [];
130
+ if (nativeReduceRight && obj.reduceRight === nativeReduceRight) {
131
+ if (context) iterator = _.bind(iterator, context);
132
+ return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
133
+ }
134
+ var reversed = _.toArray(obj).reverse();
135
+ if (context && !initial) iterator = _.bind(iterator, context);
136
+ return initial ? _.reduce(reversed, iterator, memo, context) : _.reduce(reversed, iterator);
137
+ };
138
+
139
+ // Return the first value which passes a truth test. Aliased as `detect`.
140
+ _.find = _.detect = function(obj, iterator, context) {
141
+ var result;
142
+ any(obj, function(value, index, list) {
143
+ if (iterator.call(context, value, index, list)) {
144
+ result = value;
145
+ return true;
146
+ }
147
+ });
148
+ return result;
149
+ };
150
+
151
+ // Return all the elements that pass a truth test.
152
+ // Delegates to **ECMAScript 5**'s native `filter` if available.
153
+ // Aliased as `select`.
154
+ _.filter = _.select = function(obj, iterator, context) {
155
+ var results = [];
156
+ if (obj == null) return results;
157
+ if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context);
158
+ each(obj, function(value, index, list) {
159
+ if (iterator.call(context, value, index, list)) results[results.length] = value;
160
+ });
161
+ return results;
162
+ };
163
+
164
+ // Return all the elements for which a truth test fails.
165
+ _.reject = function(obj, iterator, context) {
166
+ var results = [];
167
+ if (obj == null) return results;
168
+ each(obj, function(value, index, list) {
169
+ if (!iterator.call(context, value, index, list)) results[results.length] = value;
170
+ });
171
+ return results;
172
+ };
173
+
174
+ // Determine whether all of the elements match a truth test.
175
+ // Delegates to **ECMAScript 5**'s native `every` if available.
176
+ // Aliased as `all`.
177
+ _.every = _.all = function(obj, iterator, context) {
178
+ var result = true;
179
+ if (obj == null) return result;
180
+ if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context);
181
+ each(obj, function(value, index, list) {
182
+ if (!(result = result && iterator.call(context, value, index, list))) return breaker;
183
+ });
184
+ return !!result;
185
+ };
186
+
187
+ // Determine if at least one element in the object matches a truth test.
188
+ // Delegates to **ECMAScript 5**'s native `some` if available.
189
+ // Aliased as `any`.
190
+ var any = _.some = _.any = function(obj, iterator, context) {
191
+ iterator || (iterator = _.identity);
192
+ var result = false;
193
+ if (obj == null) return result;
194
+ if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
195
+ each(obj, function(value, index, list) {
196
+ if (result || (result = iterator.call(context, value, index, list))) return breaker;
197
+ });
198
+ return !!result;
199
+ };
200
+
201
+ // Determine if a given value is included in the array or object using `===`.
202
+ // Aliased as `contains`.
203
+ _.include = _.contains = function(obj, target) {
204
+ var found = false;
205
+ if (obj == null) return found;
206
+ if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1;
207
+ found = any(obj, function(value) {
208
+ return value === target;
209
+ });
210
+ return found;
211
+ };
212
+
213
+ // Invoke a method (with arguments) on every item in a collection.
214
+ _.invoke = function(obj, method) {
215
+ var args = slice.call(arguments, 2);
216
+ return _.map(obj, function(value) {
217
+ return (_.isFunction(method) ? method || value : value[method]).apply(value, args);
218
+ });
219
+ };
220
+
221
+ // Convenience version of a common use case of `map`: fetching a property.
222
+ _.pluck = function(obj, key) {
223
+ return _.map(obj, function(value){ return value[key]; });
224
+ };
225
+
226
+ // Return the maximum element or (element-based computation).
227
+ _.max = function(obj, iterator, context) {
228
+ if (!iterator && _.isArray(obj) && obj[0] === +obj[0]) return Math.max.apply(Math, obj);
229
+ if (!iterator && _.isEmpty(obj)) return -Infinity;
230
+ var result = {computed : -Infinity};
231
+ each(obj, function(value, index, list) {
232
+ var computed = iterator ? iterator.call(context, value, index, list) : value;
233
+ computed >= result.computed && (result = {value : value, computed : computed});
234
+ });
235
+ return result.value;
236
+ };
237
+
238
+ // Return the minimum element (or element-based computation).
239
+ _.min = function(obj, iterator, context) {
240
+ if (!iterator && _.isArray(obj) && obj[0] === +obj[0]) return Math.min.apply(Math, obj);
241
+ if (!iterator && _.isEmpty(obj)) return Infinity;
242
+ var result = {computed : Infinity};
243
+ each(obj, function(value, index, list) {
244
+ var computed = iterator ? iterator.call(context, value, index, list) : value;
245
+ computed < result.computed && (result = {value : value, computed : computed});
246
+ });
247
+ return result.value;
248
+ };
249
+
250
+ // Shuffle an array.
251
+ _.shuffle = function(obj) {
252
+ var shuffled = [], rand;
253
+ each(obj, function(value, index, list) {
254
+ rand = Math.floor(Math.random() * (index + 1));
255
+ shuffled[index] = shuffled[rand];
256
+ shuffled[rand] = value;
257
+ });
258
+ return shuffled;
259
+ };
260
+
261
+ // Sort the object's values by a criterion produced by an iterator.
262
+ _.sortBy = function(obj, val, context) {
263
+ var iterator = _.isFunction(val) ? val : function(obj) { return obj[val]; };
264
+ return _.pluck(_.map(obj, function(value, index, list) {
265
+ return {
266
+ value : value,
267
+ criteria : iterator.call(context, value, index, list)
268
+ };
269
+ }).sort(function(left, right) {
270
+ var a = left.criteria, b = right.criteria;
271
+ if (a === void 0) return 1;
272
+ if (b === void 0) return -1;
273
+ return a < b ? -1 : a > b ? 1 : 0;
274
+ }), 'value');
275
+ };
276
+
277
+ // Groups the object's values by a criterion. Pass either a string attribute
278
+ // to group by, or a function that returns the criterion.
279
+ _.groupBy = function(obj, val) {
280
+ var result = {};
281
+ var iterator = _.isFunction(val) ? val : function(obj) { return obj[val]; };
282
+ each(obj, function(value, index) {
283
+ var key = iterator(value, index);
284
+ (result[key] || (result[key] = [])).push(value);
285
+ });
286
+ return result;
287
+ };
288
+
289
+ // Use a comparator function to figure out the smallest index at which
290
+ // an object should be inserted so as to maintain order. Uses binary search.
291
+ _.sortedIndex = function(array, obj, iterator) {
292
+ iterator || (iterator = _.identity);
293
+ var value = iterator(obj);
294
+ var low = 0, high = array.length;
295
+ while (low < high) {
296
+ var mid = (low + high) >> 1;
297
+ iterator(array[mid]) < value ? low = mid + 1 : high = mid;
298
+ }
299
+ return low;
300
+ };
301
+
302
+ // Safely convert anything iterable into a real, live array.
303
+ _.toArray = function(obj) {
304
+ if (!obj) return [];
305
+ if (_.isArray(obj)) return slice.call(obj);
306
+ if (_.isArguments(obj)) return slice.call(obj);
307
+ if (obj.toArray && _.isFunction(obj.toArray)) return obj.toArray();
308
+ return _.values(obj);
309
+ };
310
+
311
+ // Return the number of elements in an object.
312
+ _.size = function(obj) {
313
+ return _.isArray(obj) ? obj.length : _.keys(obj).length;
314
+ };
315
+
316
+ // Array Functions
317
+ // ---------------
318
+
319
+ // Get the first element of an array. Passing **n** will return the first N
320
+ // values in the array. Aliased as `head` and `take`. The **guard** check
321
+ // allows it to work with `_.map`.
322
+ _.first = _.head = _.take = function(array, n, guard) {
323
+ return (n != null) && !guard ? slice.call(array, 0, n) : array[0];
324
+ };
325
+
326
+ // Returns everything but the last entry of the array. Especially useful on
327
+ // the arguments object. Passing **n** will return all the values in
328
+ // the array, excluding the last N. The **guard** check allows it to work with
329
+ // `_.map`.
330
+ _.initial = function(array, n, guard) {
331
+ return slice.call(array, 0, array.length - ((n == null) || guard ? 1 : n));
332
+ };
333
+
334
+ // Get the last element of an array. Passing **n** will return the last N
335
+ // values in the array. The **guard** check allows it to work with `_.map`.
336
+ _.last = function(array, n, guard) {
337
+ if ((n != null) && !guard) {
338
+ return slice.call(array, Math.max(array.length - n, 0));
339
+ } else {
340
+ return array[array.length - 1];
341
+ }
342
+ };
343
+
344
+ // Returns everything but the first entry of the array. Aliased as `tail`.
345
+ // Especially useful on the arguments object. Passing an **index** will return
346
+ // the rest of the values in the array from that index onward. The **guard**
347
+ // check allows it to work with `_.map`.
348
+ _.rest = _.tail = function(array, index, guard) {
349
+ return slice.call(array, (index == null) || guard ? 1 : index);
350
+ };
351
+
352
+ // Trim out all falsy values from an array.
353
+ _.compact = function(array) {
354
+ return _.filter(array, function(value){ return !!value; });
355
+ };
356
+
357
+ // Return a completely flattened version of an array.
358
+ _.flatten = function(array, shallow) {
359
+ return (function flatten(input, output) {
360
+ each(input, function(value) {
361
+ if (_.isArray(value)) {
362
+ shallow ? push.apply(output, value) : flatten(value, output);
363
+ } else {
364
+ output.push(value);
365
+ }
366
+ });
367
+ return output;
368
+ })(array, []);
369
+ };
370
+
371
+ // Return a version of the array that does not contain the specified value(s).
372
+ _.without = function(array) {
373
+ return _.difference(array, slice.call(arguments, 1));
374
+ };
375
+
376
+ // Produce a duplicate-free version of the array. If the array has already
377
+ // been sorted, you have the option of using a faster algorithm.
378
+ // Aliased as `unique`.
379
+ _.uniq = _.unique = function(array, isSorted, iterator) {
380
+ var initial = iterator ? _.map(array, iterator) : array;
381
+ var results = [];
382
+ // The `isSorted` flag is irrelevant if the array only contains two elements.
383
+ if (array.length < 3) isSorted = true;
384
+ _.reduce(initial, function(memo, value, index) {
385
+ if (isSorted ? _.last(memo) !== value || !memo.length : !_.include(memo, value)) {
386
+ memo.push(value);
387
+ results.push(array[index]);
388
+ }
389
+ return memo;
390
+ }, []);
391
+ return results;
392
+ };
393
+
394
+ // Produce an array that contains the union: each distinct element from all of
395
+ // the passed-in arrays.
396
+ _.union = function() {
397
+ return _.uniq(_.flatten(arguments, true));
398
+ };
399
+
400
+ // Produce an array that contains every item shared between all the
401
+ // passed-in arrays. (Aliased as "intersect" for back-compat.)
402
+ _.intersection = _.intersect = function(array) {
403
+ var rest = slice.call(arguments, 1);
404
+ return _.filter(_.uniq(array), function(item) {
405
+ return _.every(rest, function(other) {
406
+ return _.indexOf(other, item) >= 0;
407
+ });
408
+ });
409
+ };
410
+
411
+ // Take the difference between one array and a number of other arrays.
412
+ // Only the elements present in just the first array will remain.
413
+ _.difference = function(array) {
414
+ var rest = _.flatten(slice.call(arguments, 1), true);
415
+ return _.filter(array, function(value){ return !_.include(rest, value); });
416
+ };
417
+
418
+ // Zip together multiple lists into a single array -- elements that share
419
+ // an index go together.
420
+ _.zip = function() {
421
+ var args = slice.call(arguments);
422
+ var length = _.max(_.pluck(args, 'length'));
423
+ var results = new Array(length);
424
+ for (var i = 0; i < length; i++) results[i] = _.pluck(args, "" + i);
425
+ return results;
426
+ };
427
+
428
+ // If the browser doesn't supply us with indexOf (I'm looking at you, **MSIE**),
429
+ // we need this function. Return the position of the first occurrence of an
430
+ // item in an array, or -1 if the item is not included in the array.
431
+ // Delegates to **ECMAScript 5**'s native `indexOf` if available.
432
+ // If the array is large and already in sort order, pass `true`
433
+ // for **isSorted** to use binary search.
434
+ _.indexOf = function(array, item, isSorted) {
435
+ if (array == null) return -1;
436
+ var i, l;
437
+ if (isSorted) {
438
+ i = _.sortedIndex(array, item);
439
+ return array[i] === item ? i : -1;
440
+ }
441
+ if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item);
442
+ for (i = 0, l = array.length; i < l; i++) if (i in array && array[i] === item) return i;
443
+ return -1;
444
+ };
445
+
446
+ // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available.
447
+ _.lastIndexOf = function(array, item) {
448
+ if (array == null) return -1;
449
+ if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) return array.lastIndexOf(item);
450
+ var i = array.length;
451
+ while (i--) if (i in array && array[i] === item) return i;
452
+ return -1;
453
+ };
454
+
455
+ // Generate an integer Array containing an arithmetic progression. A port of
456
+ // the native Python `range()` function. See
457
+ // [the Python documentation](http://docs.python.org/library/functions.html#range).
458
+ _.range = function(start, stop, step) {
459
+ if (arguments.length <= 1) {
460
+ stop = start || 0;
461
+ start = 0;
462
+ }
463
+ step = arguments[2] || 1;
464
+
465
+ var len = Math.max(Math.ceil((stop - start) / step), 0);
466
+ var idx = 0;
467
+ var range = new Array(len);
468
+
469
+ while(idx < len) {
470
+ range[idx++] = start;
471
+ start += step;
472
+ }
473
+
474
+ return range;
475
+ };
476
+
477
+ // Function (ahem) Functions
478
+ // ------------------
479
+
480
+ // Reusable constructor function for prototype setting.
481
+ var ctor = function(){};
482
+
483
+ // Create a function bound to a given object (assigning `this`, and arguments,
484
+ // optionally). Binding with arguments is also known as `curry`.
485
+ // Delegates to **ECMAScript 5**'s native `Function.bind` if available.
486
+ // We check for `func.bind` first, to fail fast when `func` is undefined.
487
+ _.bind = function bind(func, context) {
488
+ var bound, args;
489
+ if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
490
+ if (!_.isFunction(func)) throw new TypeError;
491
+ args = slice.call(arguments, 2);
492
+ return bound = function() {
493
+ if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments)));
494
+ ctor.prototype = func.prototype;
495
+ var self = new ctor;
496
+ var result = func.apply(self, args.concat(slice.call(arguments)));
497
+ if (Object(result) === result) return result;
498
+ return self;
499
+ };
500
+ };
501
+
502
+ // Bind all of an object's methods to that object. Useful for ensuring that
503
+ // all callbacks defined on an object belong to it.
504
+ _.bindAll = function(obj) {
505
+ var funcs = slice.call(arguments, 1);
506
+ if (funcs.length == 0) funcs = _.functions(obj);
507
+ each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); });
508
+ return obj;
509
+ };
510
+
511
+ // Memoize an expensive function by storing its results.
512
+ _.memoize = function(func, hasher) {
513
+ var memo = {};
514
+ hasher || (hasher = _.identity);
515
+ return function() {
516
+ var key = hasher.apply(this, arguments);
517
+ return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
518
+ };
519
+ };
520
+
521
+ // Delays a function for the given number of milliseconds, and then calls
522
+ // it with the arguments supplied.
523
+ _.delay = function(func, wait) {
524
+ var args = slice.call(arguments, 2);
525
+ return setTimeout(function(){ return func.apply(null, args); }, wait);
526
+ };
527
+
528
+ // Defers a function, scheduling it to run after the current call stack has
529
+ // cleared.
530
+ _.defer = function(func) {
531
+ return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1)));
532
+ };
533
+
534
+ // Returns a function, that, when invoked, will only be triggered at most once
535
+ // during a given window of time.
536
+ _.throttle = function(func, wait) {
537
+ var context, args, timeout, throttling, more, result;
538
+ var whenDone = _.debounce(function(){ more = throttling = false; }, wait);
539
+ return function() {
540
+ context = this; args = arguments;
541
+ var later = function() {
542
+ timeout = null;
543
+ if (more) func.apply(context, args);
544
+ whenDone();
545
+ };
546
+ if (!timeout) timeout = setTimeout(later, wait);
547
+ if (throttling) {
548
+ more = true;
549
+ } else {
550
+ throttling = true;
551
+ result = func.apply(context, args);
552
+ }
553
+ whenDone();
554
+ return result;
555
+ };
556
+ };
557
+
558
+ // Returns a function, that, as long as it continues to be invoked, will not
559
+ // be triggered. The function will be called after it stops being called for
560
+ // N milliseconds. If `immediate` is passed, trigger the function on the
561
+ // leading edge, instead of the trailing.
562
+ _.debounce = function(func, wait, immediate) {
563
+ var timeout;
564
+ return function() {
565
+ var context = this, args = arguments;
566
+ var later = function() {
567
+ timeout = null;
568
+ if (!immediate) func.apply(context, args);
569
+ };
570
+ var callNow = immediate && !timeout;
571
+ clearTimeout(timeout);
572
+ timeout = setTimeout(later, wait);
573
+ if (callNow) func.apply(context, args);
574
+ };
575
+ };
576
+
577
+ // Returns a function that will be executed at most one time, no matter how
578
+ // often you call it. Useful for lazy initialization.
579
+ _.once = function(func) {
580
+ var ran = false, memo;
581
+ return function() {
582
+ if (ran) return memo;
583
+ ran = true;
584
+ return memo = func.apply(this, arguments);
585
+ };
586
+ };
587
+
588
+ // Returns the first function passed as an argument to the second,
589
+ // allowing you to adjust arguments, run code before and after, and
590
+ // conditionally execute the original function.
591
+ _.wrap = function(func, wrapper) {
592
+ return function() {
593
+ var args = [func].concat(slice.call(arguments, 0));
594
+ return wrapper.apply(this, args);
595
+ };
596
+ };
597
+
598
+ // Returns a function that is the composition of a list of functions, each
599
+ // consuming the return value of the function that follows.
600
+ _.compose = function() {
601
+ var funcs = arguments;
602
+ return function() {
603
+ var args = arguments;
604
+ for (var i = funcs.length - 1; i >= 0; i--) {
605
+ args = [funcs[i].apply(this, args)];
606
+ }
607
+ return args[0];
608
+ };
609
+ };
610
+
611
+ // Returns a function that will only be executed after being called N times.
612
+ _.after = function(times, func) {
613
+ if (times <= 0) return func();
614
+ return function() {
615
+ if (--times < 1) { return func.apply(this, arguments); }
616
+ };
617
+ };
618
+
619
+ // Object Functions
620
+ // ----------------
621
+
622
+ // Retrieve the names of an object's properties.
623
+ // Delegates to **ECMAScript 5**'s native `Object.keys`
624
+ _.keys = nativeKeys || function(obj) {
625
+ if (obj !== Object(obj)) throw new TypeError('Invalid object');
626
+ var keys = [];
627
+ for (var key in obj) if (_.has(obj, key)) keys[keys.length] = key;
628
+ return keys;
629
+ };
630
+
631
+ // Retrieve the values of an object's properties.
632
+ _.values = function(obj) {
633
+ return _.map(obj, _.identity);
634
+ };
635
+
636
+ // Return a sorted list of the function names available on the object.
637
+ // Aliased as `methods`
638
+ _.functions = _.methods = function(obj) {
639
+ var names = [];
640
+ for (var key in obj) {
641
+ if (_.isFunction(obj[key])) names.push(key);
642
+ }
643
+ return names.sort();
644
+ };
645
+
646
+ // Extend a given object with all the properties in passed-in object(s).
647
+ _.extend = function(obj) {
648
+ each(slice.call(arguments, 1), function(source) {
649
+ for (var prop in source) {
650
+ obj[prop] = source[prop];
651
+ }
652
+ });
653
+ return obj;
654
+ };
655
+
656
+ // Return a copy of the object only containing the whitelisted properties.
657
+ _.pick = function(obj) {
658
+ var result = {};
659
+ each(_.flatten(slice.call(arguments, 1)), function(key) {
660
+ if (key in obj) result[key] = obj[key];
661
+ });
662
+ return result;
663
+ };
664
+
665
+ // Fill in a given object with default properties.
666
+ _.defaults = function(obj) {
667
+ each(slice.call(arguments, 1), function(source) {
668
+ for (var prop in source) {
669
+ if (obj[prop] == null) obj[prop] = source[prop];
670
+ }
671
+ });
672
+ return obj;
673
+ };
674
+
675
+ // Create a (shallow-cloned) duplicate of an object.
676
+ _.clone = function(obj) {
677
+ if (!_.isObject(obj)) return obj;
678
+ return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
679
+ };
680
+
681
+ // Invokes interceptor with the obj, and then returns obj.
682
+ // The primary purpose of this method is to "tap into" a method chain, in
683
+ // order to perform operations on intermediate results within the chain.
684
+ _.tap = function(obj, interceptor) {
685
+ interceptor(obj);
686
+ return obj;
687
+ };
688
+
689
+ // Internal recursive comparison function for `isEqual`.
690
+ function eq(a, b, stack) {
691
+ // Identical objects are equal. `0 === -0`, but they aren't identical.
692
+ // See the Harmony `egal` proposal: http://wiki.ecmascript.org/doku.php?id=harmony:egal.
693
+ if (a === b) return a !== 0 || 1 / a == 1 / b;
694
+ // A strict comparison is necessary because `null == undefined`.
695
+ if (a == null || b == null) return a === b;
696
+ // Unwrap any wrapped objects.
697
+ if (a._chain) a = a._wrapped;
698
+ if (b._chain) b = b._wrapped;
699
+ // Invoke a custom `isEqual` method if one is provided.
700
+ if (a.isEqual && _.isFunction(a.isEqual)) return a.isEqual(b);
701
+ if (b.isEqual && _.isFunction(b.isEqual)) return b.isEqual(a);
702
+ // Compare `[[Class]]` names.
703
+ var className = toString.call(a);
704
+ if (className != toString.call(b)) return false;
705
+ switch (className) {
706
+ // Strings, numbers, dates, and booleans are compared by value.
707
+ case '[object String]':
708
+ // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
709
+ // equivalent to `new String("5")`.
710
+ return a == String(b);
711
+ case '[object Number]':
712
+ // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for
713
+ // other numeric values.
714
+ return a != +a ? b != +b : (a == 0 ? 1 / a == 1 / b : a == +b);
715
+ case '[object Date]':
716
+ case '[object Boolean]':
717
+ // Coerce dates and booleans to numeric primitive values. Dates are compared by their
718
+ // millisecond representations. Note that invalid dates with millisecond representations
719
+ // of `NaN` are not equivalent.
720
+ return +a == +b;
721
+ // RegExps are compared by their source patterns and flags.
722
+ case '[object RegExp]':
723
+ return a.source == b.source &&
724
+ a.global == b.global &&
725
+ a.multiline == b.multiline &&
726
+ a.ignoreCase == b.ignoreCase;
727
+ }
728
+ if (typeof a != 'object' || typeof b != 'object') return false;
729
+ // Assume equality for cyclic structures. The algorithm for detecting cyclic
730
+ // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
731
+ var length = stack.length;
732
+ while (length--) {
733
+ // Linear search. Performance is inversely proportional to the number of
734
+ // unique nested structures.
735
+ if (stack[length] == a) return true;
736
+ }
737
+ // Add the first object to the stack of traversed objects.
738
+ stack.push(a);
739
+ var size = 0, result = true;
740
+ // Recursively compare objects and arrays.
741
+ if (className == '[object Array]') {
742
+ // Compare array lengths to determine if a deep comparison is necessary.
743
+ size = a.length;
744
+ result = size == b.length;
745
+ if (result) {
746
+ // Deep compare the contents, ignoring non-numeric properties.
747
+ while (size--) {
748
+ // Ensure commutative equality for sparse arrays.
749
+ if (!(result = size in a == size in b && eq(a[size], b[size], stack))) break;
750
+ }
751
+ }
752
+ } else {
753
+ // Objects with different constructors are not equivalent.
754
+ if ('constructor' in a != 'constructor' in b || a.constructor != b.constructor) return false;
755
+ // Deep compare objects.
756
+ for (var key in a) {
757
+ if (_.has(a, key)) {
758
+ // Count the expected number of properties.
759
+ size++;
760
+ // Deep compare each member.
761
+ if (!(result = _.has(b, key) && eq(a[key], b[key], stack))) break;
762
+ }
763
+ }
764
+ // Ensure that both objects contain the same number of properties.
765
+ if (result) {
766
+ for (key in b) {
767
+ if (_.has(b, key) && !(size--)) break;
768
+ }
769
+ result = !size;
770
+ }
771
+ }
772
+ // Remove the first object from the stack of traversed objects.
773
+ stack.pop();
774
+ return result;
775
+ }
776
+
777
+ // Perform a deep comparison to check if two objects are equal.
778
+ _.isEqual = function(a, b) {
779
+ return eq(a, b, []);
780
+ };
781
+
782
+ // Is a given array, string, or object empty?
783
+ // An "empty" object has no enumerable own-properties.
784
+ _.isEmpty = function(obj) {
785
+ if (obj == null) return true;
786
+ if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
787
+ for (var key in obj) if (_.has(obj, key)) return false;
788
+ return true;
789
+ };
790
+
791
+ // Is a given value a DOM element?
792
+ _.isElement = function(obj) {
793
+ return !!(obj && obj.nodeType == 1);
794
+ };
795
+
796
+ // Is a given value an array?
797
+ // Delegates to ECMA5's native Array.isArray
798
+ _.isArray = nativeIsArray || function(obj) {
799
+ return toString.call(obj) == '[object Array]';
800
+ };
801
+
802
+ // Is a given variable an object?
803
+ _.isObject = function(obj) {
804
+ return obj === Object(obj);
805
+ };
806
+
807
+ // Is a given variable an arguments object?
808
+ // Define a fallback version of the method in browsers (ahem, IE), where
809
+ // there isn't any inspectable "Arguments" type.
810
+ _.isArguments = function(obj) {
811
+ return toString.call(obj) == '[object Arguments]';
812
+ };
813
+ if (!_.isArguments(arguments)) {
814
+ _.isArguments = function(obj) {
815
+ return !!(obj && _.has(obj, 'callee'));
816
+ };
817
+ }
818
+
819
+ // Is a given value a function?
820
+ _.isFunction = function(obj) {
821
+ return toString.call(obj) == '[object Function]';
822
+ };
823
+
824
+ // Is a given value a string?
825
+ _.isString = function(obj) {
826
+ return toString.call(obj) == '[object String]';
827
+ };
828
+
829
+ // Is a given value a number?
830
+ _.isNumber = function(obj) {
831
+ return toString.call(obj) == '[object Number]';
832
+ };
833
+
834
+ // Is a given object a finite number?
835
+ _.isFinite = function(obj) {
836
+ return _.isNumber(obj) && isFinite(obj);
837
+ };
838
+
839
+ // Is the given value `NaN`?
840
+ _.isNaN = function(obj) {
841
+ // `NaN` is the only value for which `===` is not reflexive.
842
+ return obj !== obj;
843
+ };
844
+
845
+ // Is a given value a boolean?
846
+ _.isBoolean = function(obj) {
847
+ return obj === true || obj === false || toString.call(obj) == '[object Boolean]';
848
+ };
849
+
850
+ // Is a given value a date?
851
+ _.isDate = function(obj) {
852
+ return toString.call(obj) == '[object Date]';
853
+ };
854
+
855
+ // Is the given value a regular expression?
856
+ _.isRegExp = function(obj) {
857
+ return toString.call(obj) == '[object RegExp]';
858
+ };
859
+
860
+ // Is a given value equal to null?
861
+ _.isNull = function(obj) {
862
+ return obj === null;
863
+ };
864
+
865
+ // Is a given variable undefined?
866
+ _.isUndefined = function(obj) {
867
+ return obj === void 0;
868
+ };
869
+
870
+ // Does an object have the given "own" property?
871
+ _.has = function(obj, key) {
872
+ return hasOwnProperty.call(obj, key);
873
+ };
874
+
875
+ // Utility Functions
876
+ // -----------------
877
+
878
+ // Run Underscore.js in *noConflict* mode, returning the `_` variable to its
879
+ // previous owner. Returns a reference to the Underscore object.
880
+ _.noConflict = function() {
881
+ root._ = previousUnderscore;
882
+ return this;
883
+ };
884
+
885
+ // Keep the identity function around for default iterators.
886
+ _.identity = function(value) {
887
+ return value;
888
+ };
889
+
890
+ // Run a function **n** times.
891
+ _.times = function(n, iterator, context) {
892
+ for (var i = 0; i < n; i++) iterator.call(context, i);
893
+ };
894
+
895
+ // Escape a string for HTML interpolation.
896
+ _.escape = function(string) {
897
+ return (''+string)
898
+ .replace(/&/g, '&amp;')
899
+ .replace(/</g, '&lt;')
900
+ .replace(/>/g, '&gt;')
901
+ .replace(/"/g, '&quot;')
902
+ .replace(/'/g, '&#x27;')
903
+ .replace(/\//g,'&#x2F;');
904
+ };
905
+
906
+ // If the value of the named property is a function then invoke it;
907
+ // otherwise, return it.
908
+ _.result = function(object, property) {
909
+ if (object == null) return null;
910
+ var value = object[property];
911
+ return _.isFunction(value) ? value.call(object) : value;
912
+ };
913
+
914
+ // Add your own custom functions to the Underscore object, ensuring that
915
+ // they're correctly added to the OOP wrapper as well.
916
+ _.mixin = function(obj) {
917
+ each(_.functions(obj), function(name){
918
+ addToWrapper(name, _[name] = obj[name]);
919
+ });
920
+ };
921
+
922
+ // Generate a unique integer id (unique within the entire client session).
923
+ // Useful for temporary DOM ids.
924
+ var idCounter = 0;
925
+ _.uniqueId = function(prefix) {
926
+ var id = idCounter++;
927
+ return prefix ? prefix + id : id;
928
+ };
929
+
930
+ // By default, Underscore uses ERB-style template delimiters, change the
931
+ // following template settings to use alternative delimiters.
932
+ _.templateSettings = {
933
+ evaluate : /<%([\s\S]+?)%>/g,
934
+ interpolate : /<%=([\s\S]+?)%>/g,
935
+ escape : /<%-([\s\S]+?)%>/g
936
+ };
937
+
938
+ // When customizing `templateSettings`, if you don't want to define an
939
+ // interpolation, evaluation or escaping regex, we need one that is
940
+ // guaranteed not to match.
941
+ var noMatch = /.^/;
942
+
943
+ // Certain characters need to be escaped so that they can be put into a
944
+ // string literal.
945
+ var escapes = {
946
+ '\\': '\\',
947
+ "'": "'",
948
+ 'r': '\r',
949
+ 'n': '\n',
950
+ 't': '\t',
951
+ 'u2028': '\u2028',
952
+ 'u2029': '\u2029'
953
+ };
954
+
955
+ for (var p in escapes) escapes[escapes[p]] = p;
956
+ var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g;
957
+ var unescaper = /\\(\\|'|r|n|t|u2028|u2029)/g;
958
+
959
+ // Within an interpolation, evaluation, or escaping, remove HTML escaping
960
+ // that had been previously added.
961
+ var unescape = function(code) {
962
+ return code.replace(unescaper, function(match, escape) {
963
+ return escapes[escape];
964
+ });
965
+ };
966
+
967
+ // JavaScript micro-templating, similar to John Resig's implementation.
968
+ // Underscore templating handles arbitrary delimiters, preserves whitespace,
969
+ // and correctly escapes quotes within interpolated code.
970
+ _.template = function(text, data, settings) {
971
+ settings = _.defaults(settings || {}, _.templateSettings);
972
+
973
+ // Compile the template source, taking care to escape characters that
974
+ // cannot be included in a string literal and then unescape them in code
975
+ // blocks.
976
+ var source = "__p+='" + text
977
+ .replace(escaper, function(match) {
978
+ return '\\' + escapes[match];
979
+ })
980
+ .replace(settings.escape || noMatch, function(match, code) {
981
+ return "'+\n((__t=(" + unescape(code) + "))==null?'':_.escape(__t))+\n'";
982
+ })
983
+ .replace(settings.interpolate || noMatch, function(match, code) {
984
+ return "'+\n((__t=(" + unescape(code) + "))==null?'':__t)+\n'";
985
+ })
986
+ .replace(settings.evaluate || noMatch, function(match, code) {
987
+ return "';\n" + unescape(code) + "\n;__p+='";
988
+ }) + "';\n";
989
+
990
+ // If a variable is not specified, place data values in local scope.
991
+ if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
992
+
993
+ source = "var __t,__p='',__j=Array.prototype.join," +
994
+ "print=function(){__p+=__j.call(arguments,'')};\n" +
995
+ source + "return __p;\n";
996
+
997
+ var render = new Function(settings.variable || 'obj', '_', source);
998
+ if (data) return render(data, _);
999
+ var template = function(data) {
1000
+ return render.call(this, data, _);
1001
+ };
1002
+
1003
+ // Provide the compiled function source as a convenience for precompilation.
1004
+ template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}';
1005
+
1006
+ return template;
1007
+ };
1008
+
1009
+ // Add a "chain" function, which will delegate to the wrapper.
1010
+ _.chain = function(obj) {
1011
+ return _(obj).chain();
1012
+ };
1013
+
1014
+ // The OOP Wrapper
1015
+ // ---------------
1016
+
1017
+ // If Underscore is called as a function, it returns a wrapped object that
1018
+ // can be used OO-style. This wrapper holds altered versions of all the
1019
+ // underscore functions. Wrapped objects may be chained.
1020
+ var wrapper = function(obj) { this._wrapped = obj; };
1021
+
1022
+ // Expose `wrapper.prototype` as `_.prototype`
1023
+ _.prototype = wrapper.prototype;
1024
+
1025
+ // Helper function to continue chaining intermediate results.
1026
+ var result = function(obj, chain) {
1027
+ return chain ? _(obj).chain() : obj;
1028
+ };
1029
+
1030
+ // A method to easily add functions to the OOP wrapper.
1031
+ var addToWrapper = function(name, func) {
1032
+ wrapper.prototype[name] = function() {
1033
+ var args = slice.call(arguments);
1034
+ unshift.call(args, this._wrapped);
1035
+ return result(func.apply(_, args), this._chain);
1036
+ };
1037
+ };
1038
+
1039
+ // Add all of the Underscore functions to the wrapper object.
1040
+ _.mixin(_);
1041
+
1042
+ // Add all mutator Array functions to the wrapper.
1043
+ each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
1044
+ var method = ArrayProto[name];
1045
+ wrapper.prototype[name] = function() {
1046
+ var obj = this._wrapped;
1047
+ method.apply(obj, arguments);
1048
+ if ((name == 'shift' || name == 'splice') && obj.length === 0) delete obj[0];
1049
+ return result(obj, this._chain);
1050
+ };
1051
+ });
1052
+
1053
+ // Add all accessor Array functions to the wrapper.
1054
+ each(['concat', 'join', 'slice'], function(name) {
1055
+ var method = ArrayProto[name];
1056
+ wrapper.prototype[name] = function() {
1057
+ return result(method.apply(this._wrapped, arguments), this._chain);
1058
+ };
1059
+ });
1060
+
1061
+ // Start chaining a wrapped Underscore object.
1062
+ wrapper.prototype.chain = function() {
1063
+ this._chain = true;
1064
+ return this;
1065
+ };
1066
+
1067
+ // Extracts the result from a wrapped and chained object.
1068
+ wrapper.prototype.value = function() {
1069
+ return this._wrapped;
1070
+ };
1071
+
1072
+ }).call(this);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emerson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -38,6 +38,7 @@ files:
38
38
  - vendor/assets/javascripts/emerson/sink.js
39
39
  - vendor/assets/javascripts/emerson/util.js
40
40
  - vendor/assets/javascripts/emerson/view.js
41
+ - vendor/assets/javascripts/underscore.js
41
42
  homepage: https://github.com/coreyti/emerson
42
43
  licenses: []
43
44
  post_install_message: