Support backwards-compatibility for functions
type specified as
strings, like in `point-transform`
This commit is contained in:
parent
5ff9051104
commit
593092fedd
@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user