Merge branch 'master' of github.com:CartoDB/carto
This commit is contained in:
commit
d95967247d
@ -209,12 +209,6 @@ CartoCSS.prototype = {
|
|||||||
var value = rule.value.value[0].value[0].value.value;
|
var value = rule.value.value[0].value[0].value.value;
|
||||||
this.imageURLs.push(value);
|
this.imageURLs.push(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
rule.toXML(parse_env, {});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.options.strict && parse_env.errors.message) {
|
|
||||||
throw new Error(parse_env.errors.message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
layer.frames = [];
|
layer.frames = [];
|
||||||
@ -244,6 +238,14 @@ CartoCSS.prototype = {
|
|||||||
var done = {};
|
var done = {};
|
||||||
for(var i = 0; i < defs.length; ++i) {
|
for(var i = 0; i < defs.length; ++i) {
|
||||||
var def = defs[i];
|
var def = defs[i];
|
||||||
|
|
||||||
|
if (this.options.strict) {
|
||||||
|
def.toXML(parse_env, {});
|
||||||
|
if (parse_env.errors.message) {
|
||||||
|
throw new Error(parse_env.errors.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var k = defKey(def);
|
var k = defKey(def);
|
||||||
var layer = layers[k];
|
var layer = layers[k];
|
||||||
if(!done[k]) {
|
if(!done[k]) {
|
||||||
@ -279,14 +281,14 @@ CartoCSS.prototype = {
|
|||||||
|
|
||||||
carto.RendererJS = function (options) {
|
carto.RendererJS = function (options) {
|
||||||
this.options = options || {};
|
this.options = options || {};
|
||||||
var reference = this.options.reference || require('./torque-reference').version.latest;
|
|
||||||
tree.Reference.setData(reference);
|
|
||||||
this.options.mapnik_version = this.options.mapnik_version || 'latest';
|
this.options.mapnik_version = this.options.mapnik_version || 'latest';
|
||||||
|
this.reference = this.options.reference || require('./torque-reference').version.latest;
|
||||||
this.options.strict = this.options.hasOwnProperty('strict') ? this.options.strict : false;
|
this.options.strict = this.options.hasOwnProperty('strict') ? this.options.strict : false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Prepare a javascript object which contains the layers
|
// Prepare a javascript object which contains the layers
|
||||||
carto.RendererJS.prototype.render = function render(cartocss, callback) {
|
carto.RendererJS.prototype.render = function render(cartocss, callback) {
|
||||||
|
tree.Reference.setData(this.reference);
|
||||||
return new CartoCSS(cartocss, this.options);
|
return new CartoCSS(cartocss, this.options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +92,9 @@ tree.Filterset.prototype.toJS = function(env) {
|
|||||||
val = filter._val.toString(true);
|
val = filter._val.toString(true);
|
||||||
}
|
}
|
||||||
var attrs = "data";
|
var attrs = "data";
|
||||||
|
if (op === '=~') {
|
||||||
|
return "(" + attrs + "['" + filter.key.value + "'] + '').match(" + (val.is === 'string' ? "'" + val.toString().replace(/'/g, "\\'") + "'" : val) + ")";
|
||||||
|
}
|
||||||
return attrs + "['" + filter.key.value + "'] " + op + " " + (val.is === 'string' ? "'" + val.toString().replace(/'/g, "\\'") + "'" : val);
|
return attrs + "['" + filter.key.value + "'] " + op + " " + (val.is === 'string' ? "'" + val.toString().replace(/'/g, "\\'") + "'" : val);
|
||||||
}).join(' && ');
|
}).join(' && ');
|
||||||
};
|
};
|
||||||
|
@ -36,7 +36,9 @@ tree.Value.prototype = {
|
|||||||
v = "'" + v + "'";
|
v = "'" + v + "'";
|
||||||
} else if (val.is === 'field') {
|
} else if (val.is === 'field') {
|
||||||
// replace [variable] by ctx['variable']
|
// replace [variable] by ctx['variable']
|
||||||
v = v.replace(/\[(.*)\]/g, "data['$1']");
|
v = v.replace(/\[([^\]]*)\]/g, function(matched) {
|
||||||
|
return matched.replace(/\[(.*)\]/g, "data['$1']");
|
||||||
|
});
|
||||||
}else if (val.is === 'call') {
|
}else if (val.is === 'call') {
|
||||||
v = JSON.stringify({
|
v = JSON.stringify({
|
||||||
name: val.name,
|
name: val.name,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "carto",
|
"name": "carto",
|
||||||
"version": "0.15.1-cdb1",
|
"version": "0.15.1-cdb3",
|
||||||
"description": "CartoCSS Stylesheet Compiler",
|
"description": "CartoCSS Stylesheet Compiler",
|
||||||
"url": "https://github.com/cartodb/carto",
|
"url": "https://github.com/cartodb/carto",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -106,7 +106,9 @@ describe('RendererJS Strict Mode', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
after(function() {
|
after(function() {
|
||||||
|
if (this.referenceData) {
|
||||||
tree.Reference.setData(this.referenceData);
|
tree.Reference.setData(this.referenceData);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail if a feature is not supported and strict is turned on', function () {
|
it('should fail if a feature is not supported and strict is turned on', function () {
|
||||||
@ -122,9 +124,6 @@ describe('RendererJS Strict Mode', function() {
|
|||||||
function rendererStrictModeOffTest(RendererJS) {
|
function rendererStrictModeOffTest(RendererJS) {
|
||||||
return function () {
|
return function () {
|
||||||
var shader = RendererJS.render(style);
|
var shader = RendererJS.render(style);
|
||||||
assert.ok(shader.parse_env);
|
|
||||||
assert.ok(shader.parse_env.errors);
|
|
||||||
assert.ok(shader.parse_env.errors.message.match(expectedErrorMessageRegex));
|
|
||||||
|
|
||||||
assert.ok(shader.layers);
|
assert.ok(shader.layers);
|
||||||
assert.equal(shader.layers.length, 2);
|
assert.equal(shader.layers.length, 2);
|
||||||
@ -135,8 +134,15 @@ describe('RendererJS Strict Mode', function() {
|
|||||||
new carto.RendererJS({reference: reference, mapnik_version: '1.0.0' })
|
new carto.RendererJS({reference: reference, mapnik_version: '1.0.0' })
|
||||||
));
|
));
|
||||||
|
|
||||||
it('should pass if a feature is not supported but strict is turned off', rendererStrictModeOffTest(
|
it('should pass if a feature is not supported but strict is turned off', function () {
|
||||||
new carto.RendererJS({reference: reference, mapnik_version: '1.0.0', strict: false })
|
new carto.RendererJS({reference: reference, mapnik_version: '1.0.0', strict: false })
|
||||||
));
|
});
|
||||||
|
|
||||||
|
it('should pass if a feature is supported and strict is turned on', function () {
|
||||||
|
var RendererJS = new carto.RendererJS({reference: reference, mapnik_version: '1.0.0', strict: true });
|
||||||
|
var cartocss = '#layer { line-width: 10 }';
|
||||||
|
var shader = RendererJS.render(cartocss);
|
||||||
|
assert.ok(shader);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var carto = require('../lib/carto');
|
var carto = require('../lib/carto');
|
||||||
|
|
||||||
describe('RenderingJS', function() {
|
describe('RenderingJS', function() {
|
||||||
var shader;
|
var shader;
|
||||||
var style = [
|
var style = [
|
||||||
@ -184,4 +183,45 @@ describe('RenderingJS', function() {
|
|||||||
assert.equal(st.args[2].args[0].value, 10);
|
assert.equal(st.args[2].args[0].value, 10);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should work with multiple operands", function(){
|
||||||
|
var css = [
|
||||||
|
'#layer {',
|
||||||
|
' marker-width: [value] * [value] * 0.5;',
|
||||||
|
'}'
|
||||||
|
].join('\n');
|
||||||
|
var shader = (new carto.RendererJS({ debug: false })).render(css);
|
||||||
|
var layer = shader.getLayers()[0];
|
||||||
|
var width = layer.shader['marker-width'].style({value: 4}, {zoom: 1});
|
||||||
|
assert.equal(width, 8);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not throw `ReferenceError` with `=~` operator", function(){
|
||||||
|
var css = [
|
||||||
|
'#layer[name=~".*wadus*"] {',
|
||||||
|
' marker-width: 14;',
|
||||||
|
'}'
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
|
assert.doesNotThrow(function () {
|
||||||
|
var shader = (new carto.RendererJS({})).render(css);
|
||||||
|
var layer = shader.getLayers()[0];
|
||||||
|
var value = layer.shader['marker-width'].style({ name: 'wadus' }, { zoom: 1 });
|
||||||
|
assert.equal(value, 14);
|
||||||
|
}, ReferenceError);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("`=~` operator should support numbers", function(){
|
||||||
|
var css = [
|
||||||
|
'#layer[value=~"^10"] {',
|
||||||
|
' marker-width: 14;',
|
||||||
|
'}'
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
|
assert.doesNotThrow(function () {
|
||||||
|
var shader = (new carto.RendererJS({})).render(css);
|
||||||
|
var layer = shader.getLayers()[0];
|
||||||
|
var value = layer.shader['marker-width'].style({ value: 10 }, { zoom: 1 });
|
||||||
|
assert.equal(value, 14);
|
||||||
|
}, Error);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user