diff --git a/lib/carto/functions.js b/lib/carto/functions.js index 47129ef..f569589 100644 --- a/lib/carto/functions.js +++ b/lib/carto/functions.js @@ -94,6 +94,13 @@ tree.functions = { return hsla(hsl); }, + replace: function (entity, a, b) { + if (entity.is === 'field') { + return entity.toString + '.replace(' + a.toString() + ', ' + b.toString() + ')'; + } else { + return entity.replace(a, b); + } + }, // // Copyright (c) 2006-2009 Hampton Catlin, Nathan Weizenbaum, and Chris Eppstein // http://sass-lang.com diff --git a/lib/carto/tree/dimension.js b/lib/carto/tree/dimension.js index dfa7de2..471e439 100644 --- a/lib/carto/tree/dimension.js +++ b/lib/carto/tree/dimension.js @@ -35,8 +35,12 @@ tree.Dimension.prototype = { // conversions such that `100cm + 10mm` would yield // `101cm`. operate: function(op, other) { - return new tree.Dimension(tree.operate(op, this.value, other.value), - this.unit || other.unit); + if (other.is === 'field') { + return new tree.Quoted('', this.value + op + other.toString()); + } else { + return new tree.Dimension(tree.operate(op, this.value, other.value), + this.unit || other.unit); + } } }; diff --git a/lib/carto/tree/field.js b/lib/carto/tree/field.js index f6ebe8d..e18eb39 100644 --- a/lib/carto/tree/field.js +++ b/lib/carto/tree/field.js @@ -11,6 +11,9 @@ tree.Field.prototype = { }, 'eval': function() { return this; + }, + operate: function(op, other) { + return new tree.Quoted('', this.toString() + op + other.toString()); } }; diff --git a/lib/carto/tree/quoted.js b/lib/carto/tree/quoted.js index 885e4c5..67d0add 100644 --- a/lib/carto/tree/quoted.js +++ b/lib/carto/tree/quoted.js @@ -16,8 +16,13 @@ tree.Quoted.prototype = { }, operate: function(op, other) { - return new tree.Quoted(this.quote, - tree.operate(op, this.toString(), other.toString())); + if (other.is !== 'string') { + return new tree.Quoted(this.quote, + this.toString() + op + other.toString()); + } else { + return new tree.Quoted(this.quote, + tree.operate(op, this.toString(), other.toString())); + } } }; diff --git a/test/rendering/building_height.mml b/test/rendering/building_height.mml new file mode 100644 index 0000000..79ba517 --- /dev/null +++ b/test/rendering/building_height.mml @@ -0,0 +1,23 @@ +{ + "srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over", + "Stylesheet": [ + "building_height.mss" + ], + "Layer": [{ + "name": "world", + "srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over", + "Datasource": { + "file": "http://tilemill-data.s3.amazonaws.com/test_data/shape_demo.zip", + "type": "shape" + } + }, + { + "class": "new", + "name": "countries", + "srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over", + "Datasource": { + "file": "http://tilemill-data.s3.amazonaws.com/test_data/shape_demo.zip", + "type": "shape" + } + }] +} diff --git a/test/rendering/building_height.mss b/test/rendering/building_height.mss new file mode 100644 index 0000000..6122c84 --- /dev/null +++ b/test/rendering/building_height.mss @@ -0,0 +1,4 @@ +@n: 4; +#world { + building-height: 2 * 3 * [HEIGHT] + 2 + [NOTHEIGHT] + (@n * 2); +}