diff --git a/lib/carto/tree/reference.js b/lib/carto/tree/reference.js index 49914f1..a5ded89 100644 --- a/lib/carto/tree/reference.js +++ b/lib/carto/tree/reference.js @@ -1,3 +1,9 @@ +/* + * Carto pulls in a reference from the `mapnik-reference` + * module. This file builds indexes from that file for its various + * options, and provides validation methods for property: value + * combinations. + */ (function(tree) { var _ = require('underscore'); @@ -101,31 +107,32 @@ tree.Reference.isFont = function(selector) { tree.Reference.validValue = function(env, selector, value) { var i, j; - if (value[0]) { - return tree.Reference.selector(selector).type == value[0].is; - } else { - // TODO: handle in reusable way - if (!tree.Reference.selector(selector)) { - return false; - } else if (value.value[0].is == 'keyword') { - return tree.Reference - .selector(selector).type - .indexOf(value.value[0].value) !== -1; - } else if (value.value[0].is == 'undefined') { - // caught earlier in the chain - ignore here so that - // error is not overridden - return true; - } else if (tree.Reference.selector(selector).type == 'numbers') { - for (i in value.value) { - if (value.value[i].is !== 'float') { - return false; - } + // TODO: handle in reusable way + if (!tree.Reference.selector(selector)) { + return false; + } else if (value.value[0].is == 'keyword') { + return tree.Reference + .selector(selector).type + .indexOf(value.value[0].value) !== -1; + } else if (value.value[0].is == 'undefined') { + // caught earlier in the chain - ignore here so that + // error is not overridden + return true; + } else if (tree.Reference.selector(selector).type == 'numbers') { + for (i in value.value) { + if (value.value[i].is !== 'float') { + return false; } + } + return true; + } else if (tree.Reference.selector(selector).type == 'functions') { + // For backwards compatibility, you can specify a string for `functions`-compatible + // values, though they will not be validated. + if (value.value[0].is === 'string') { return true; - } else if (tree.Reference.selector(selector).type == 'functions') { + } else { for (i in value.value) { for (j in value.value[i].value) { - console.log(value.value[i]); if (value.value[i].value[j].is !== 'call') { return false; } @@ -140,22 +147,22 @@ tree.Reference.validValue = function(env, selector, value) { } } return true; - } else { - if (tree.Reference.selector(selector).validate) { - var valid = false; - for (i = 0; i < value.value.length; i++) { - if (tree.Reference.selector(selector).type == value.value[i].is && - tree.Reference - ._validateValue - [tree.Reference.selector(selector).validate] - (env, value.value[i].value)) { - return true; - } + } + } else { + if (tree.Reference.selector(selector).validate) { + var valid = false; + for (i = 0; i < value.value.length; i++) { + if (tree.Reference.selector(selector).type == value.value[i].is && + tree.Reference + ._validateValue + [tree.Reference.selector(selector).validate] + (env, value.value[i].value)) { + return true; } - return valid; - } else { - return tree.Reference.selector(selector).type == value.value[0].is; } + return valid; + } else { + return tree.Reference.selector(selector).type == value.value[0].is; } } };