substituteParams: function()

in xooki.js [227:259]


    substituteParams: function(/*string*/template, /* object - optional or ... */hash) {
    // borrowed from dojo
    // summary:
    //	Performs parameterized substitutions on a string. Throws an exception if any parameter is unmatched.
    //
    // description:
    //	For example,
    //		dojo.string.substituteParams("File '${0}' is not found in directory '${1}'.","foo.html","/temp");
    //	returns
    //		"File 'foo.html' is not found in directory '/temp'."
    //
    // template: the original string template with ${values} to be replaced
    // hash: name/value pairs (type object) to provide substitutions.  Alternatively, substitutions may be
    //	included as an array
    
        var map;
        if (typeof hash == "object" && hash.length) { // array
            map = {};
            for (var i in hash) {
                map[i+""] = hash[i];
            }
        } else {
            map = hash;
        }
    
    	return template.replace(/\$\{(\w+)\}/g, function(match, key){
    		if(typeof(map[key]) != "undefined" && map[key] != null){
    			return map[key];
    		}
    		xooki.warn("Substitution not found: " + key);
    		return key;
    	}); // string
	},