UNPKG

asset-rack

Version:

Static Web Framework for Nodejs

62 lines (45 loc) 1.73 kB
// Generated by CoffeeScript 1.6.3 (function() { var Asset, DynamicAssets, StaticAsset, async, fs, mime, 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; }; fs = require('fs'); pathutil = require('path'); async = require('async'); mime = require('mime'); Asset = require('../.').Asset; DynamicAssets = require('./dynamic').DynamicAssets; StaticAsset = (function(_super) { __extends(StaticAsset, _super); function StaticAsset() { _ref = StaticAsset.__super__.constructor.apply(this, arguments); return _ref; } StaticAsset.prototype.create = function(options) { var _this = this; this.filename = pathutil.resolve(options.filename); if (this.mimetype == null) { this.mimetype = mime.types[pathutil.extname(this.filename).slice(1)] || 'text/plain'; } return fs.readFile(this.filename, function(error, data) { if (error != null) { return _this.emit('error', error); } return _this.emit('created', { contents: data }); }); }; return StaticAsset; })(Asset); exports.StaticAssets = (function(_super) { __extends(StaticAssets, _super); function StaticAssets(options) { if (options != null) { options.type = StaticAsset; } StaticAssets.__super__.constructor.call(this, options); } return StaticAssets; })(DynamicAssets); }).call(this);