2013-03-04 22:07:16 +00:00
|
|
|
// Generated by CoffeeScript 1.6.1
|
2010-07-25 07:15:12 +00:00
|
|
|
(function() {
|
2013-03-06 20:45:47 +00:00
|
|
|
var buildLocationData, extend, flatten, normalizePath, _ref;
|
2011-09-18 22:16:39 +00:00
|
|
|
|
2010-09-25 00:29:44 +00:00
|
|
|
exports.starts = function(string, literal, start) {
|
2010-09-25 00:18:47 +00:00
|
|
|
return literal === string.substr(start, literal.length);
|
|
|
|
};
|
2011-09-18 22:16:39 +00:00
|
|
|
|
2010-09-25 00:29:44 +00:00
|
|
|
exports.ends = function(string, literal, back) {
|
2010-09-26 14:28:48 +00:00
|
|
|
var len;
|
|
|
|
len = literal.length;
|
|
|
|
return literal === string.substr(string.length - len - (back || 0), len);
|
2010-09-25 00:18:47 +00:00
|
|
|
};
|
2011-09-18 22:16:39 +00:00
|
|
|
|
2010-09-25 00:29:44 +00:00
|
|
|
exports.compact = function(array) {
|
2010-11-09 05:17:08 +00:00
|
|
|
var item, _i, _len, _results;
|
|
|
|
_results = [];
|
2010-10-22 01:51:06 +00:00
|
|
|
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
2010-10-01 22:26:37 +00:00
|
|
|
item = array[_i];
|
2012-04-10 18:57:45 +00:00
|
|
|
if (item) {
|
|
|
|
_results.push(item);
|
|
|
|
}
|
2010-03-10 02:24:30 +00:00
|
|
|
}
|
2010-11-09 05:17:08 +00:00
|
|
|
return _results;
|
2010-09-25 00:18:47 +00:00
|
|
|
};
|
2011-09-18 22:16:39 +00:00
|
|
|
|
2010-12-13 10:51:57 +00:00
|
|
|
exports.count = function(string, substr) {
|
2010-03-10 02:24:30 +00:00
|
|
|
var num, pos;
|
2010-10-20 17:29:06 +00:00
|
|
|
num = pos = 0;
|
2012-04-10 18:57:45 +00:00
|
|
|
if (!substr.length) {
|
|
|
|
return 1 / 0;
|
|
|
|
}
|
2010-12-13 10:51:57 +00:00
|
|
|
while (pos = 1 + string.indexOf(substr, pos)) {
|
2010-09-25 00:18:47 +00:00
|
|
|
num++;
|
2010-03-10 02:24:30 +00:00
|
|
|
}
|
|
|
|
return num;
|
2010-09-25 00:18:47 +00:00
|
|
|
};
|
2011-09-18 22:16:39 +00:00
|
|
|
|
2010-09-25 00:29:44 +00:00
|
|
|
exports.merge = function(options, overrides) {
|
2010-09-25 00:18:47 +00:00
|
|
|
return extend(extend({}, options), overrides);
|
|
|
|
};
|
2011-09-18 22:16:39 +00:00
|
|
|
|
2010-10-20 17:29:06 +00:00
|
|
|
extend = exports.extend = function(object, properties) {
|
2010-10-19 15:07:10 +00:00
|
|
|
var key, val;
|
2010-10-01 22:26:37 +00:00
|
|
|
for (key in properties) {
|
|
|
|
val = properties[key];
|
2010-09-26 14:28:48 +00:00
|
|
|
object[key] = val;
|
2010-03-10 02:24:30 +00:00
|
|
|
}
|
2010-09-25 00:18:47 +00:00
|
|
|
return object;
|
2010-10-20 17:29:06 +00:00
|
|
|
};
|
2011-09-18 22:16:39 +00:00
|
|
|
|
2010-10-20 17:29:06 +00:00
|
|
|
exports.flatten = flatten = function(array) {
|
2010-11-02 03:58:03 +00:00
|
|
|
var element, flattened, _i, _len;
|
2010-09-28 18:28:05 +00:00
|
|
|
flattened = [];
|
2010-10-22 01:51:06 +00:00
|
|
|
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
2010-10-01 22:26:37 +00:00
|
|
|
element = array[_i];
|
2010-09-29 00:12:37 +00:00
|
|
|
if (element instanceof Array) {
|
2010-09-28 18:28:05 +00:00
|
|
|
flattened = flattened.concat(flatten(element));
|
|
|
|
} else {
|
|
|
|
flattened.push(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return flattened;
|
2010-10-20 17:29:06 +00:00
|
|
|
};
|
2011-09-18 22:16:39 +00:00
|
|
|
|
2010-09-25 00:29:44 +00:00
|
|
|
exports.del = function(obj, key) {
|
2010-03-10 02:24:30 +00:00
|
|
|
var val;
|
|
|
|
val = obj[key];
|
|
|
|
delete obj[key];
|
|
|
|
return val;
|
2010-09-25 00:18:47 +00:00
|
|
|
};
|
2011-09-18 22:16:39 +00:00
|
|
|
|
2010-09-28 12:52:51 +00:00
|
|
|
exports.last = function(array, back) {
|
|
|
|
return array[array.length - (back || 0) - 1];
|
|
|
|
};
|
2011-12-14 15:39:20 +00:00
|
|
|
|
2012-05-16 19:50:34 +00:00
|
|
|
exports.some = (_ref = Array.prototype.some) != null ? _ref : function(fn) {
|
|
|
|
var e, _i, _len;
|
|
|
|
for (_i = 0, _len = this.length; _i < _len; _i++) {
|
|
|
|
e = this[_i];
|
|
|
|
if (fn(e)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2013-03-05 02:45:57 +00:00
|
|
|
exports.invertLiterate = function(code) {
|
|
|
|
var line, lines, match;
|
|
|
|
lines = (function() {
|
|
|
|
var _i, _len, _ref1, _results;
|
|
|
|
_ref1 = code.split('\n');
|
|
|
|
_results = [];
|
|
|
|
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
|
|
|
line = _ref1[_i];
|
|
|
|
if (match = /^([ ]{4}|\t)/.exec(line)) {
|
|
|
|
_results.push(line.slice(match[0].length));
|
|
|
|
} else {
|
|
|
|
_results.push('# ' + line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
})();
|
|
|
|
return lines.join('\n');
|
|
|
|
};
|
|
|
|
|
2012-11-15 20:35:01 +00:00
|
|
|
buildLocationData = function(first, last) {
|
|
|
|
if (!last) {
|
|
|
|
return first;
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
first_line: first.first_line,
|
|
|
|
first_column: first.first_column,
|
|
|
|
last_line: last.last_line,
|
|
|
|
last_column: last.last_column
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.addLocationDataFn = function(first, last) {
|
|
|
|
return function(obj) {
|
|
|
|
if (((typeof obj) === 'object') && (!!obj['updateLocationDataIfMissing'])) {
|
|
|
|
obj.updateLocationDataIfMissing(buildLocationData(first, last));
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2012-11-17 00:09:56 +00:00
|
|
|
exports.locationDataToString = function(obj) {
|
|
|
|
var locationData;
|
2013-01-14 20:20:35 +00:00
|
|
|
if (("2" in obj) && ("first_line" in obj[2])) {
|
|
|
|
locationData = obj[2];
|
2012-11-17 00:09:56 +00:00
|
|
|
} else if ("first_line" in obj) {
|
|
|
|
locationData = obj;
|
|
|
|
}
|
|
|
|
if (locationData) {
|
|
|
|
return ("" + (locationData.first_line + 1) + ":" + (locationData.first_column + 1) + "-") + ("" + (locationData.last_line + 1) + ":" + (locationData.last_column + 1));
|
|
|
|
} else {
|
|
|
|
return "No location data";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-03-04 22:07:16 +00:00
|
|
|
exports.baseFileName = function(file, stripExt) {
|
2013-03-04 21:40:39 +00:00
|
|
|
var parts;
|
2013-03-04 22:07:16 +00:00
|
|
|
if (stripExt == null) {
|
|
|
|
stripExt = false;
|
|
|
|
}
|
2013-03-04 21:40:39 +00:00
|
|
|
parts = file.split('/');
|
|
|
|
file = parts[parts.length - 1];
|
2013-03-04 22:07:16 +00:00
|
|
|
if (!stripExt) {
|
|
|
|
return file;
|
|
|
|
}
|
2013-03-04 21:40:39 +00:00
|
|
|
parts = file.split('.');
|
|
|
|
parts.pop();
|
|
|
|
if (parts[parts.length - 1] === 'coffee') {
|
|
|
|
parts.pop();
|
|
|
|
}
|
|
|
|
return parts.join('.');
|
|
|
|
};
|
|
|
|
|
2013-02-28 02:54:17 +00:00
|
|
|
exports.isCoffee = function(file) {
|
|
|
|
return /\.((lit)?coffee|coffee\.md)$/.test(file);
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.isLiterate = function(file) {
|
|
|
|
return /\.(litcoffee|coffee\.md)$/.test(file);
|
|
|
|
};
|
|
|
|
|
2013-03-06 20:45:47 +00:00
|
|
|
exports.normalizePath = normalizePath = function(path, removeTrailingSlash) {
|
|
|
|
var i, parts, root, _ref1;
|
|
|
|
if (removeTrailingSlash == null) {
|
|
|
|
removeTrailingSlash = false;
|
|
|
|
}
|
|
|
|
root = false;
|
|
|
|
parts = path.split('/');
|
|
|
|
i = 0;
|
|
|
|
if (parts.length > 1 && parts[i] === '') {
|
|
|
|
parts.splice(i, 1);
|
|
|
|
root = true;
|
|
|
|
}
|
|
|
|
while (i < parts.length) {
|
|
|
|
if ((_ref1 = parts[i]) === '.' || _ref1 === '') {
|
|
|
|
if ((i === parts.length - 1) && !removeTrailingSlash) {
|
|
|
|
parts[i] = '';
|
|
|
|
i++;
|
|
|
|
} else {
|
|
|
|
parts.splice(i, 1);
|
|
|
|
}
|
|
|
|
} else if (parts[i] === '..') {
|
|
|
|
if (i === 0 || (i && parts[i - 1] === '..')) {
|
|
|
|
i++;
|
|
|
|
} else {
|
|
|
|
parts.splice(i - 1, 2);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (root) {
|
|
|
|
if (parts.length === 0) {
|
|
|
|
return '/';
|
|
|
|
}
|
|
|
|
if (parts.length[0] === '..') {
|
|
|
|
throw new Error("Invalid path: " + path);
|
|
|
|
}
|
|
|
|
parts.unshift('');
|
|
|
|
}
|
|
|
|
return parts.join('/');
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.relativePath = function(from, to, cwd) {
|
|
|
|
var answer, _i, _ref1;
|
|
|
|
if (cwd == null) {
|
|
|
|
cwd = null;
|
|
|
|
}
|
|
|
|
if (cwd) {
|
|
|
|
from = cwd + "/" + from;
|
|
|
|
to = cwd + "/" + to;
|
|
|
|
}
|
|
|
|
from = (normalizePath(from)).split('/');
|
|
|
|
to = (normalizePath(to)).split('/');
|
|
|
|
while (from.length > 0 && to.length > 0 && from[0] === to[0]) {
|
|
|
|
from.shift();
|
|
|
|
to.shift();
|
|
|
|
}
|
|
|
|
if (from.length && from[0] === "..") {
|
|
|
|
throw new Error("'cwd' must be specified if 'from' references parent directory: " + (from.join('/')) + " -> " + (to.join('/')));
|
|
|
|
}
|
|
|
|
answer = "";
|
|
|
|
if (from.length > 1) {
|
|
|
|
for (_i = 0, _ref1 = from.length - 1; 0 <= _ref1 ? _i < _ref1 : _i > _ref1; 0 <= _ref1 ? _i++ : _i--) {
|
|
|
|
answer += "../";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return answer + ("" + (to.join('/')));
|
|
|
|
};
|
|
|
|
|
2010-09-21 07:53:58 +00:00
|
|
|
}).call(this);
|