asset-rack
Version:
Static Web Framework for Nodejs
61 lines (50 loc) • 2.17 kB
JavaScript
// Generated by CoffeeScript 1.6.3
(function() {
var Asset, Snockets, pathutil, _ref,
__hasProp = {}.hasOwnProperty,
__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; };
pathutil = require('path');
Snockets = require('snockets');
Asset = require('../index').Asset;
exports.SnocketsAsset = (function(_super) {
__extends(SnocketsAsset, _super);
function SnocketsAsset() {
_ref = SnocketsAsset.__super__.constructor.apply(this, arguments);
return _ref;
}
SnocketsAsset.prototype.mimetype = 'text/javascript';
SnocketsAsset.prototype.create = function(options) {
var e, file, filename, files, script, scripts, snockets, _i, _len;
try {
this.filename = pathutil.resolve(options.filename);
this.toWatch = pathutil.dirname(this.filename);
this.compress = options.compress || false;
this.debug = options.debug || false;
snockets = new Snockets();
if (this.debug) {
files = snockets.getCompiledChain(this.filename, {
async: false
});
scripts = [];
for (_i = 0, _len = files.length; _i < _len; _i++) {
file = files[_i];
script = file.js.replace(/\\/g, '\\\\').replace(/\n/g, '\\n').replace(/\r/g, '').replace(/'/g, '\\\'');
filename = pathutil.relative(pathutil.dirname(this.filename), file.filename).replace(/\\/g, '\/');
scripts.push("// " + filename + "\neval('" + script + "\\n//@ sourceURL=" + filename + "')\n");
}
this.contents = scripts.join('\n');
} else {
this.contents = snockets.getConcatenation(this.filename, {
async: false,
minify: this.compress
});
}
} catch (_error) {
e = _error;
this.emit('error', e);
}
return this.emit('created');
};
return SnocketsAsset;
})(Asset);
}).call(this);