Use object.keys to iterate over objects
This commit is contained in:
parent
fb8fd5121e
commit
3e571b4ce8
@ -120,7 +120,7 @@ o._releaseTemplateLock = function(owner, tpl_id, callback) {
|
|||||||
this._redisCmd('HDEL', [this.key_usr_tpl_lck({owner:owner}), tpl_id], callback);
|
this._redisCmd('HDEL', [this.key_usr_tpl_lck({owner:owner}), tpl_id], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
o._reValidIdentifier = /^[a-zA-Z][0-9a-zA-Z_]*$/;
|
var _reValidIdentifier = /^[a-zA-Z][0-9a-zA-Z_]*$/;
|
||||||
o._checkInvalidTemplate = function(template) {
|
o._checkInvalidTemplate = function(template) {
|
||||||
if ( template.version != '0.0.1' ) {
|
if ( template.version != '0.0.1' ) {
|
||||||
return new Error("Unsupported template version " + template.version);
|
return new Error("Unsupported template version " + template.version);
|
||||||
@ -129,21 +129,25 @@ o._checkInvalidTemplate = function(template) {
|
|||||||
if ( ! tplname ) {
|
if ( ! tplname ) {
|
||||||
return new Error("Missing template name");
|
return new Error("Missing template name");
|
||||||
}
|
}
|
||||||
if ( ! tplname.match(this._reValidIdentifier) ) {
|
if ( ! tplname.match(_reValidIdentifier) ) {
|
||||||
return new Error("Invalid characters in template name '" + tplname + "'");
|
return new Error("Invalid characters in template name '" + tplname + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
var phold = template.placeholders;
|
var placeholders = template.placeholders || {};
|
||||||
for (var k in phold) {
|
|
||||||
if ( ! k.match(this._reValidIdentifier) ) {
|
var placeholderKeys = Object.keys(placeholders);
|
||||||
return new Error("Invalid characters in placeholder name '" + k + "'");
|
for (var i = 0, len = placeholderKeys.length; i < len; i++) {
|
||||||
}
|
var placeholderKey = placeholderKeys[i];
|
||||||
if ( ! phold[k].hasOwnProperty('default') ) {
|
|
||||||
return new Error("Missing default for placeholder '" + k + "'");
|
if (!placeholderKey.match(_reValidIdentifier)) {
|
||||||
}
|
return new Error("Invalid characters in placeholder name '" + placeholderKey + "'");
|
||||||
if ( ! phold[k].hasOwnProperty('type') ) {
|
}
|
||||||
return new Error("Missing type for placeholder '" + k + "'");
|
if ( ! placeholders[placeholderKey].hasOwnProperty('default') ) {
|
||||||
}
|
return new Error("Missing default for placeholder '" + placeholderKey + "'");
|
||||||
|
}
|
||||||
|
if ( ! placeholders[placeholderKey].hasOwnProperty('type') ) {
|
||||||
|
return new Error("Missing type for placeholder '" + placeholderKey + "'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check certificate validity
|
// Check certificate validity
|
||||||
@ -545,8 +549,8 @@ _replaceVars = function(str, params) {
|
|||||||
};
|
};
|
||||||
o.instance = function(template, params) {
|
o.instance = function(template, params) {
|
||||||
var all_params = {};
|
var all_params = {};
|
||||||
var phold = template.placeholders;
|
var phold = template.placeholders || {};
|
||||||
for (var k in phold) {
|
Object.keys(phold).forEach(function(k) {
|
||||||
var val = params.hasOwnProperty(k) ? params[k] : phold[k].default;
|
var val = params.hasOwnProperty(k) ? params[k] : phold[k].default;
|
||||||
var type = phold[k].type;
|
var type = phold[k].type;
|
||||||
// properly escape
|
// properly escape
|
||||||
@ -578,7 +582,7 @@ o.instance = function(template, params) {
|
|||||||
throw new Error("Invalid placeholder type '" + type + "'");
|
throw new Error("Invalid placeholder type '" + type + "'");
|
||||||
}
|
}
|
||||||
all_params[k] = val;
|
all_params[k] = val;
|
||||||
}
|
});
|
||||||
|
|
||||||
// NOTE: we're deep-cloning the layergroup here
|
// NOTE: we're deep-cloning the layergroup here
|
||||||
var layergroup = JSON.parse(JSON.stringify(template.layergroup));
|
var layergroup = JSON.parse(JSON.stringify(template.layergroup));
|
||||||
|
Loading…
Reference in New Issue
Block a user