UNPKG

eyeglass

Version:
76 lines 3.01 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const AssetsSource_1 = __importDefault(require("./AssetsSource")); const stringUtils = __importStar(require("../util/strings")); const URI_1 = require("../util/URI"); class AssetsCollection { constructor(options) { this.options = options; this.sass = options.eyeglass.engines.sass; this.sources = []; } /** * adds an AssetsSource to the collection * @param {String} src - the source directory of the assets * @param {Object} opts - the options to pass @see AssetsSource * @returns {AssetsCollection} returns the instance of AssetsCollection for chaining */ addSource(src, opts) { this.sources.push(new AssetsSource_1.default(src, opts)); return this; } /** * returns the scss to register all the assets * @param {String} name - the namespace to use * @returns {String} the scss representation of the asset registration */ asAssetImport(name) { // builds the scss to register all the assets // this will look something like... // @import "eyeglass/assets"; // @include asset-register-all("namespace", // "path/to/foo.png": ( // filepath: "/absolute/namespace/path/to/foo.png", // uri: "namespace/path/to/foo.png" // ), // ); let contents = [ '@import "eyeglass/assets";', ]; for (let source of this.sources) { // get the assets for the entry let assets = source.getAssets(name); let namespace = (stringUtils.quoteJS(this.sass, assets.namespace) || "null"); contents.push(`@include asset-register-all(${namespace}, (`); for (let asset of assets.files) { let url = URI_1.URI.sass(this.sass, asset.name); let uri = URI_1.URI.sass(this.sass, asset.uri); let filepath = URI_1.URI.sass(this.sass, asset.sourcePath); contents.push(` ${url}: (filepath: ${filepath}, uri: ${uri}),`); } contents.push("));"); } return contents.join("\n"); } /** * Build a string suitable for caching an instance of this * @returns {String} the cache key */ cacheKey(name) { return this.sources.map(function (source) { return source.cacheKey(name); }).sort().join("\x00"); } } exports.default = AssetsCollection; //# sourceMappingURL=AssetsCollection.js.map