Merge branch 'master' of github.com:CartoDB/carto
This commit is contained in:
commit
d95967247d
@ -57,7 +57,7 @@ CartoCSS.Layer.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* return the symbolizers that need to be rendered with
|
||||
* return the symbolizers that need to be rendered with
|
||||
* this style. The order is the rendering order.
|
||||
* @returns a list with 3 possible values 'line', 'marker', 'polygon'
|
||||
*/
|
||||
@ -99,7 +99,7 @@ CartoCSS.Layer.prototype = {
|
||||
|
||||
//
|
||||
// given a geoemtry type returns the transformed one acording the CartoCSS
|
||||
// For points there are two kind of types: point and sprite, the first one
|
||||
// For points there are two kind of types: point and sprite, the first one
|
||||
// is a circle, second one is an image sprite
|
||||
//
|
||||
// the other geometry types are the same than geojson (polygon, linestring...)
|
||||
@ -206,15 +206,9 @@ CartoCSS.prototype = {
|
||||
for(var u = 0; u<def.rules.length; u++){
|
||||
var rule = def.rules[u];
|
||||
if(rule.name === "marker-file" || rule.name === "point-file"){
|
||||
var value = rule.value.value[0].value[0].value.value;
|
||||
this.imageURLs.push(value);
|
||||
var value = rule.value.value[0].value[0].value.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 = [];
|
||||
@ -244,6 +238,14 @@ CartoCSS.prototype = {
|
||||
var done = {};
|
||||
for(var i = 0; i < defs.length; ++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 layer = layers[k];
|
||||
if(!done[k]) {
|
||||
@ -279,14 +281,14 @@ CartoCSS.prototype = {
|
||||
|
||||
carto.RendererJS = function (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.reference = this.options.reference || require('./torque-reference').version.latest;
|
||||
this.options.strict = this.options.hasOwnProperty('strict') ? this.options.strict : false;
|
||||
};
|
||||
|
||||
// Prepare a javascript object which contains the layers
|
||||
carto.RendererJS.prototype.render = function render(cartocss, callback) {
|
||||
tree.Reference.setData(this.reference);
|
||||
return new CartoCSS(cartocss, this.options);
|
||||
}
|
||||
|
||||
|
@ -92,6 +92,9 @@ tree.Filterset.prototype.toJS = function(env) {
|
||||
val = filter._val.toString(true);
|
||||
}
|
||||
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);
|
||||
}).join(' && ');
|
||||
};
|
||||
|
@ -36,7 +36,9 @@ tree.Value.prototype = {
|
||||
v = "'" + v + "'";
|
||||
} else if (val.is === 'field') {
|
||||
// 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') {
|
||||
v = JSON.stringify({
|
||||
name: val.name,
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "carto",
|
||||
"version": "0.15.1-cdb1",
|
||||
"version": "0.15.1-cdb3",
|
||||
"description": "CartoCSS Stylesheet Compiler",
|
||||
"url": "https://github.com/cartodb/carto",
|
||||
"repository": {
|
||||
|
@ -106,7 +106,9 @@ describe('RendererJS Strict Mode', function() {
|
||||
});
|
||||
|
||||
after(function() {
|
||||
tree.Reference.setData(this.referenceData);
|
||||
if (this.referenceData) {
|
||||
tree.Reference.setData(this.referenceData);
|
||||
}
|
||||
});
|
||||
|
||||
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) {
|
||||
return function () {
|
||||
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.equal(shader.layers.length, 2);
|
||||
@ -135,8 +134,15 @@ describe('RendererJS Strict Mode', function() {
|
||||
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 })
|
||||
));
|
||||
});
|
||||
|
||||
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,23 +1,22 @@
|
||||
|
||||
var assert = require('assert');
|
||||
var carto = require('../lib/carto');
|
||||
|
||||
describe('RenderingJS', function() {
|
||||
var shader;
|
||||
var style = [
|
||||
'#world {',
|
||||
'line-width: 2;',
|
||||
'line-color: #f00;',
|
||||
'[frame-offset = 1] {',
|
||||
'line-width: 3;',
|
||||
'}',
|
||||
'[frame-offset = 2] {',
|
||||
'line-width: 3;',
|
||||
'}',
|
||||
'}',
|
||||
'',
|
||||
'#worls[frame-offset = 10] {',
|
||||
'line-width: 4;',
|
||||
'#world {',
|
||||
'line-width: 2;',
|
||||
'line-color: #f00;',
|
||||
'[frame-offset = 1] {',
|
||||
'line-width: 3;',
|
||||
'}',
|
||||
'[frame-offset = 2] {',
|
||||
'line-width: 3;',
|
||||
'}',
|
||||
'}',
|
||||
'',
|
||||
'#worls[frame-offset = 10] {',
|
||||
'line-width: 4;',
|
||||
'}'
|
||||
].join('\n');
|
||||
|
||||
@ -184,4 +183,45 @@ describe('RenderingJS', function() {
|
||||
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