2010-07-25 03:15:12 -04:00
|
|
|
(function() {
|
2010-07-13 22:16:19 -04:00
|
|
|
var compact, count, del, ends, extend, flatten, helpers, include, indexOf, merge, starts;
|
2010-03-14 17:48:43 -04:00
|
|
|
helpers = (exports.helpers = {});
|
2010-06-12 19:05:13 -04:00
|
|
|
helpers.indexOf = (indexOf = function(array, item, from) {
|
2010-09-20 22:13:08 -04:00
|
|
|
var _len, _ref, index, other;
|
2010-05-14 23:40:04 -04:00
|
|
|
if (array.indexOf) {
|
|
|
|
return array.indexOf(item, from);
|
|
|
|
}
|
2010-09-20 21:56:18 -04:00
|
|
|
_ref = array;
|
2010-09-20 22:13:08 -04:00
|
|
|
for (index = 0, _len = _ref.length; index < _len; index++) {
|
2010-09-20 21:56:18 -04:00
|
|
|
other = _ref[index];
|
2010-05-14 23:40:04 -04:00
|
|
|
if (other === item && (!from || (from <= index))) {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
});
|
|
|
|
helpers.include = (include = function(list, value) {
|
2010-06-12 19:05:13 -04:00
|
|
|
return indexOf(list, value) >= 0;
|
2010-03-10 09:47:02 -05:00
|
|
|
});
|
2010-05-14 23:40:04 -04:00
|
|
|
helpers.starts = (starts = function(string, literal, start) {
|
2010-03-09 21:24:30 -05:00
|
|
|
return string.substring(start, (start || 0) + literal.length) === literal;
|
2010-03-10 09:47:02 -05:00
|
|
|
});
|
2010-07-13 22:16:19 -04:00
|
|
|
helpers.ends = (ends = function(string, literal, back) {
|
|
|
|
var start;
|
|
|
|
start = string.length - literal.length - ((typeof back !== "undefined" && back !== null) ? back : 0);
|
|
|
|
return string.substring(start, start + literal.length) === literal;
|
|
|
|
});
|
2010-05-14 23:40:04 -04:00
|
|
|
helpers.compact = (compact = function(array) {
|
2010-09-20 22:13:08 -04:00
|
|
|
var _i, _len, _ref, _result, item;
|
2010-09-20 21:56:18 -04:00
|
|
|
_result = []; _ref = array;
|
2010-09-20 22:13:08 -04:00
|
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
2010-09-20 21:56:18 -04:00
|
|
|
item = _ref[_i];
|
2010-08-11 00:40:15 -04:00
|
|
|
if (item) {
|
2010-09-19 08:29:15 -04:00
|
|
|
_result.push(item);
|
2010-08-14 11:42:19 -04:00
|
|
|
}
|
2010-03-09 21:24:30 -05:00
|
|
|
}
|
2010-09-19 08:29:15 -04:00
|
|
|
return _result;
|
2010-03-10 09:47:02 -05:00
|
|
|
});
|
2010-05-14 23:40:04 -04:00
|
|
|
helpers.count = (count = function(string, letter) {
|
2010-03-09 21:24:30 -05:00
|
|
|
var num, pos;
|
|
|
|
num = 0;
|
2010-06-12 19:05:13 -04:00
|
|
|
pos = indexOf(string, letter);
|
2010-03-09 21:24:30 -05:00
|
|
|
while (pos !== -1) {
|
|
|
|
num += 1;
|
2010-06-12 19:05:13 -04:00
|
|
|
pos = indexOf(string, letter, pos + 1);
|
2010-03-09 21:24:30 -05:00
|
|
|
}
|
|
|
|
return num;
|
2010-03-10 09:47:02 -05:00
|
|
|
});
|
2010-05-14 23:40:04 -04:00
|
|
|
helpers.merge = (merge = function(options, overrides) {
|
2010-09-20 22:13:08 -04:00
|
|
|
var _ref, fresh, key, val;
|
2010-03-09 21:24:30 -05:00
|
|
|
fresh = {};
|
2010-09-20 21:56:18 -04:00
|
|
|
_ref = options;
|
|
|
|
for (key in _ref) {
|
|
|
|
val = _ref[key];
|
2010-03-23 00:18:50 -04:00
|
|
|
(fresh[key] = val);
|
2010-07-15 21:18:35 -04:00
|
|
|
}
|
2010-03-09 21:24:30 -05:00
|
|
|
if (overrides) {
|
2010-09-20 22:13:08 -04:00
|
|
|
_ref = overrides;
|
|
|
|
for (key in _ref) {
|
|
|
|
val = _ref[key];
|
2010-03-23 00:18:50 -04:00
|
|
|
(fresh[key] = val);
|
2010-07-15 21:18:35 -04:00
|
|
|
}
|
2010-03-09 21:24:30 -05:00
|
|
|
}
|
|
|
|
return fresh;
|
2010-03-10 09:47:02 -05:00
|
|
|
});
|
2010-05-14 23:40:04 -04:00
|
|
|
helpers.extend = (extend = function(object, properties) {
|
2010-09-20 21:56:18 -04:00
|
|
|
var _ref, _result, key, val;
|
|
|
|
_result = []; _ref = properties;
|
|
|
|
for (key in _ref) {
|
|
|
|
val = _ref[key];
|
2010-09-19 08:29:15 -04:00
|
|
|
_result.push(object[key] = val);
|
2010-07-15 21:18:35 -04:00
|
|
|
}
|
2010-09-19 08:29:15 -04:00
|
|
|
return _result;
|
2010-03-16 01:53:25 -04:00
|
|
|
});
|
2010-05-14 23:40:04 -04:00
|
|
|
helpers.flatten = (flatten = function(array) {
|
2010-09-20 22:13:08 -04:00
|
|
|
var _i, _len, _ref, item, memo;
|
2010-03-09 21:24:30 -05:00
|
|
|
memo = [];
|
2010-09-20 21:56:18 -04:00
|
|
|
_ref = array;
|
2010-09-20 22:13:08 -04:00
|
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
2010-09-20 21:56:18 -04:00
|
|
|
item = _ref[_i];
|
2010-08-11 00:40:15 -04:00
|
|
|
if (item instanceof Array) {
|
|
|
|
memo = memo.concat(item);
|
|
|
|
} else {
|
|
|
|
memo.push(item);
|
2010-08-14 11:42:19 -04:00
|
|
|
}
|
2010-03-09 21:24:30 -05:00
|
|
|
}
|
|
|
|
return memo;
|
2010-03-10 09:47:02 -05:00
|
|
|
});
|
2010-05-14 23:40:04 -04:00
|
|
|
helpers.del = (del = function(obj, key) {
|
2010-03-09 21:24:30 -05:00
|
|
|
var val;
|
|
|
|
val = obj[key];
|
|
|
|
delete obj[key];
|
|
|
|
return val;
|
2010-03-10 09:47:02 -05:00
|
|
|
});
|
2010-09-21 03:53:58 -04:00
|
|
|
}).call(this);
|