asset-rack
Version:
Static Web Framework for Nodejs
89 lines (76 loc) • 2.73 kB
JavaScript
// Generated by CoffeeScript 1.6.3
(function() {
var Asset, async, fs, mime, pathutil, walk, _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; };
fs = require('fs');
pathutil = require('path');
async = require('async');
mime = require('mime');
Asset = require('../.').Asset;
walk = require('../util').walk;
exports.DynamicAssets = (function(_super) {
__extends(DynamicAssets, _super);
function DynamicAssets() {
_ref = DynamicAssets.__super__.constructor.apply(this, arguments);
return _ref;
}
DynamicAssets.prototype.create = function(options) {
var _this = this;
this.dirname = pathutil.resolve(options.dirname);
this.toWatch = this.dirname;
this.type = options.type, this.urlPrefix = options.urlPrefix, this.options = options.options, this.filter = options.filter, this.rewriteExt = options.rewriteExt;
if (this.urlPrefix == null) {
this.urlPrefix = '/';
}
if (this.urlPrefix.slice(-1) !== '/') {
this.urlPrefix += '/';
}
if (this.type.prototype.mimetype != null) {
if (this.rewriteExt == null) {
this.rewriteExt = mime.extensions[this.type.prototype.mimetype];
}
}
if ((this.rewriteExt != null) && this.rewriteExt[0] !== '.') {
this.rewriteExt = '.' + this.rewriteExt;
}
if (this.options == null) {
this.options = {};
}
this.options.hash = this.hash;
this.options.maxAge = this.maxAge;
this.assets = [];
return walk(this.dirname, {
ignoreFolders: true,
filter: this.filter
}, function(file, done) {
var k, opts, url, v, _ref1;
url = pathutil.dirname(file.relpath);
url = url.split(pathutil.sep);
if (url[0] === '.') {
url = [];
}
if (_this.rewriteExt != null) {
url.push(file.namenoext + _this.rewriteExt);
} else {
url.push(file.name);
}
opts = {
url: _this.urlPrefix + url.join('/'),
filename: file.path
};
_ref1 = _this.options;
for (k in _ref1) {
if (!__hasProp.call(_ref1, k)) continue;
v = _ref1[k];
opts[k] = v;
}
_this.addAsset(new _this.type(opts));
return done();
}, function() {
return _this.emit('created');
});
};
return DynamicAssets;
})(Asset);
}).call(this);