/* UriTemplates Template Processor - Version: @VERSION - Dated: @DATE (c) marc.portier@gmail.com - 2011-2012 Licensed under APLv2 (http://opensource.org/licenses/Apache-2.0) */ ; var uritemplate = (function() { // Below are the functions we originally used from jQuery. // The implementations below are often more naive then what is inside jquery, but they suffice for our needs. function isFunction(fn) { return typeof fn == 'function'; } function isEmptyObject (obj) { for(var name in obj){ return false; } return true; } function extend(base, newprops) { for (var name in newprops) { base[name] = newprops[name]; } return base; } /** * Create a runtime cache around retrieved values from the context. * This allows for dynamic (function) results to be kept the same for multiple * occuring expansions within one template. * Note: Uses key-value tupples to be able to cache null values as well. */ //TODO move this into prep-processing function CachingContext(context) { this.raw = context; this.cache = {}; } CachingContext.prototype.get = function(key) { var val = this.lookupRaw(key); var result = val; if (isFunction(val)) { // check function-result-cache var tupple = this.cache[key]; if (tupple !== null && tupple !== undefined) { result = tupple.val; } else { result = val(this.raw); this.cache[key] = {key: key, val: result}; // NOTE: by storing tupples we make sure a null return is validly consistent too in expansions } } return result; }; 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