Alien-Web-HalBrowser

 view release on metacpan or  search on metacpan

share/vendor/js/uritemplates.js  view on Meta::CPAN

CachingContext.prototype.lookupRaw = function(key) {
    return CachingContext.lookup(this, this.raw, key);
};

CachingContext.lookup = function(me, context, key) {
    var result = context[key];
    if (result !== undefined) {
        return result;
    } else {
        var keyparts = key.split('.');
        var i = 0, keysplits = keyparts.length - 1;
        for (i = 0; i<keysplits; i++) {
            var leadKey = keyparts.slice(0, keysplits - i).join('.');
            var trailKey = keyparts.slice(-i-1).join('.');
            var leadContext = context[leadKey];
            if (leadContext !== undefined) {
                return CachingContext.lookup(me, leadContext, trailKey);
            }
        }
        return undefined;
    }
};


function UriTemplate(set) {
    this.set = set;
}

UriTemplate.prototype.expand = function(context) {
    var cache = new CachingContext(context);
    var res = "";
    var i = 0, cnt = this.set.length;
    for (i = 0; i<cnt; i++ ) {
        res += this.set[i].expand(cache);
    }
    return res;
};

//TODO: change since draft-0.6 about characters in literals
/* extract:
The characters outside of expressions in a URI Template string are intended to be copied literally to the URI-reference if the character is allowed in a URI (reserved / unreserved / pct-encoded) or, if not allowed, copied to the URI-reference in its ...
*/
function Literal(txt ) {
    this.txt = txt;
}

Literal.prototype.expand = function() {
    return this.txt;
};



var RESERVEDCHARS_RE = new RegExp("[:/?#\\[\\]@!$&()*+,;=']","g");
function encodeNormal(val) {
    return encodeURIComponent(val).replace(RESERVEDCHARS_RE, function(s) {return escape(s);} );
}

//var SELECTEDCHARS_RE = new RegExp("[]","g");
function encodeReserved(val) {
    //return encodeURI(val).replace(SELECTEDCHARS_RE, function(s) {return escape(s)} );
    return encodeURI(val); // no need for additional replace if selected-chars is empty
}


function addUnNamed(name, key, val) {
    return key + (key.length > 0 ? "=" : "") + val;
}

function addNamed(name, key, val, noName) {
    noName = noName || false;
    if (noName) { name = ""; }
    
    if (!key || key.length === 0)  {
        key = name;
    }
    return key + (key.length > 0 ? "=" : "") + val;
}

function addLabeled(name, key, val, noName) {
    noName = noName || false;
    if (noName) { name = ""; }
    
    if (!key || key.length === 0)  {
        key = name;
    }
    return key + (key.length > 0 && val ? "=" : "") + val;
}


var simpleConf = { 
    prefix : "",     joiner : ",",     encode : encodeNormal,    builder : addUnNamed
};
var reservedConf = { 
    prefix : "",     joiner : ",",     encode : encodeReserved,  builder : addUnNamed
};
var fragmentConf = { 
    prefix : "#",    joiner : ",",     encode : encodeReserved,  builder : addUnNamed
};
var pathParamConf = { 
    prefix : ";",    joiner : ";",     encode : encodeNormal,    builder : addLabeled
};
var formParamConf = { 
    prefix : "?",    joiner : "&",     encode : encodeNormal,    builder : addNamed
};
var formContinueConf = { 
    prefix : "&",    joiner : "&",     encode : encodeNormal,    builder : addNamed
};
var pathHierarchyConf = { 
    prefix : "/",    joiner : "/",     encode : encodeNormal,    builder : addUnNamed
};
var labelConf = { 
    prefix : ".",    joiner : ".",     encode : encodeNormal,    builder : addUnNamed
};


function Expression(conf, vars ) {
    extend(this, conf);
    this.vars = vars;
}

Expression.build = function(ops, vars) {



( run in 0.759 second using v1.01-cache-2.11-cpan-d7f47b0818f )