lib/relations/CacheManifestEntry.js

lib/ AssetGraph.js errors.js index.js query.js
assets/ Asset.js Atom.js CacheManifest.js CoffeeScript.js Css.js Flash.js Gif.js Htc.js Html.js I18n.js Ico.js Image.js JavaScript.js Jpeg.js Json.js KnockoutJsTemplate.js Less.js Png.js Rss.js StaticUrlMap.js Stylus.js Text.js Xml.js index.js
relations/ CacheManifestEntry.js CssAlphaImageLoader.js CssBehavior.js CssFontFaceSrc.js CssImage.js CssImport.js CssUrlTokenRelation.js HtmlAlternateLink.js HtmlAnchor.js HtmlAppleTouchStartupImage.js HtmlApplet.js HtmlAudio.js HtmlCacheManifest.js HtmlConditionalComment.js HtmlDataBindAttribute.js HtmlEdgeSideInclude.js HtmlEmbed.js HtmlFrame.js HtmlIFrame.js HtmlIFrameSrcDoc.js HtmlImage.js HtmlInlineScriptTemplate.js HtmlKnockoutContainerless.js HtmlObject.js HtmlRelation.js HtmlRequireJsMain.js HtmlScript.js HtmlShortcutIcon.js HtmlStyle.js HtmlStyleAttribute.js HtmlVideo.js HtmlVideoPoster.js JavaScriptAmdDefine.js JavaScriptAmdRequire.js JavaScriptCommonJsRequire.js JavaScriptExtJsRequire.js JavaScriptGetStaticUrl.js JavaScriptGetText.js JavaScriptInclude.js JavaScriptShimRequire.js JavaScriptTrHtml.js Relation.js StaticUrlMapEntry.js index.js
resolvers/ data.js extJs4Dir.js file.js fixedDirectory.js http.js index.js javascript.js
transforms/ addCacheManifest.js bundleRelations.js bundleRequireJs.js compileCoffeeScriptToJavaScript.js compileLessToCss.js compileStylusToCss.js compressJavaScript.js convertCssImportsToHtmlStyles.js convertHtmlStylesToInlineCssImports.js convertStylesheetsToInlineStyles.js drawGraph.js executeJavaScriptInOrder.js externalizeRelations.js flattenStaticIncludes.js inlineCssImagesWithLegacyFallback.js inlineRelations.js loadAssets.js mergeIdenticalAssets.js minifyAssets.js moveAssets.js moveAssetsInOrder.js populate.js prettyPrintAssets.js pullGlobalsIntoVariables.js registerRequireJsConfig.js removeAssets.js removeRelations.js setAssetContentType.js setAssetEncoding.js setAssetExtension.js setHtmlImageDimensions.js startOverIfAssetSourceFilesChange.js writeAssetsToDisc.js writeAssetsToStdout.js writeStatsToStderr.js
util/ deepCopy.js extendWithGettersAndSetters.js fsTools.js getImageInfoFromBuffers.js memoizeAsyncAccessor.js uniqueId.js urlTools.js
var util = require('util'),
    _ = require('underscore'),
    extendWithGettersAndSetters = require('../util/extendWithGettersAndSetters'),
    Relation = require('./Relation');

function CacheManifestEntry(config) {
    Relation.call(this, config);
}

util.inherits(CacheManifestEntry, Relation);

extendWithGettersAndSetters(CacheManifestEntry.prototype, {
    get href() {
        return this.node.tokens[this.node.tokens.length - 1];
    },

    set href(href) {
        // In the CACHE section and NETWORK sections there's only one token per entry,
        // in FALLBACK there's the online url followed by the offline url (the one we want).
        // Just overwrite the last token with the url:
        if (this.sectionName === 'FALLBACK') {
            this.node.tokens[1] = href;
        } else {
            this.node.tokens[0] = href;
        }
    },

    inline: function () {
        throw new Error("CacheManifestEntry.inline(): Not supported.");
    },

    attach: function (asset, position, adjacentRelation) {
        this.from = asset;
        if (!this.sectionName) {
            this.sectionName = 'CACHE';
        }
        // FIXME: Doesn't work with FALLBACK entries where there're two tokens.
        this.node = {
            tokens: []
        };
        if (!(this.sectionName in asset.parseTree)) {
            asset.parseTree[this.sectionName] = [];
        }
        asset.parseTree[this.sectionName].push(this.node);

        return Relation.prototype.attach.call(this, asset, position, adjacentRelation);
        this.refreshHref();
    },

    detach: function () {
        var indexInSection = this.from.parseTree[this.sectionName].indexOf(this.node);
        if (indexInSection === -1) {
            throw new Error("CacheManifestEntry.detach: Relation not found in the " + this.sectionName + " section");
        }
        this.from.parseTree[this.sectionName].splice(indexInSection, 1);
        return Relation.prototype.detach.call(this);
    }
});

module.exports = CacheManifestEntry;