From 265554813b2ccdce9c4a609f7262305d7b33745f Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Fri, 22 Jun 2012 18:06:15 -0400 Subject: [PATCH] Update results for temporary image-transform renaming, update reference to mapnik-reference to point to the transforms branch, prep a changelog message --- CHANGELOG.md | 4 ++ lib/carto/tree/call.js | 44 ++++++++++++++++------ lib/carto/tree/reference.js | 18 +++++++++ package.json | 2 +- test/rendering/transforms.result | 2 +- test/rendering/transforms_backwards.result | 2 +- 6 files changed, 57 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3854c57..91220d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog +### 0.8.0 + +* Supports function syntax for transforms, optionally with variables and arguments. + ### 0.7.0 * Support an `opacity` property on any style that is a style-level property diff --git a/lib/carto/tree/call.js b/lib/carto/tree/call.js index 191b85c..d1a2fb6 100644 --- a/lib/carto/tree/call.js +++ b/lib/carto/tree/call.js @@ -1,8 +1,5 @@ (function(tree) { -// -// A function call node. -// tree.Call = function Call(name, args, index) { this.is = 'call'; @@ -53,26 +50,49 @@ tree.Call.prototype = { }; } } else { - return this; - // return new tree.Anonymous(this.name + - // '(' + args.map(function(a) { return a.toString(); }).join(', ') + ')'); + var fn = tree.Reference.mapnikFunction(this.name); + if (!fn) { + env.error({ + message: 'unknown function ' + this.name, + index: this.index, + type: 'runtime', + filename: this.filename + }); + return { + is: 'undefined', + value: 'undefined' + }; + } + if (fn[1] !== args.length) { + env.error({ + message: 'function ' + this.name + ' takes ' + + fn[1] + ' arguments and was given ' + args.length, + index: this.index, + type: 'runtime', + filename: this.filename + }); + return { + is: 'undefined', + value: 'undefined' + }; + } else { + // Save the evaluated versions of arguments + this.args = args; + return this; + } } }, toString: function(env, format) { if (format === 'image-filter') { if (this.args.length) { - return this.name + ':' + this.args.map(function(a) { - return a.eval(env); - }).join(','); + return this.name + ':' + this.args.join(','); } else { return this.name; } } else { if (this.args.length) { - return this.name + '(' + this.args.map(function(a) { - return a.eval(env); - }).join(',') + ')'; + return this.name + '(' + this.args.join(',') + ')'; } else { return this.name; } diff --git a/lib/carto/tree/reference.js b/lib/carto/tree/reference.js index a5ded89..7a81cdc 100644 --- a/lib/carto/tree/reference.js +++ b/lib/carto/tree/reference.js @@ -65,6 +65,24 @@ tree.Reference.symbolizer = function(selector) { } }; +/* + * For transform properties and image-filters, + * mapnik has its own functions. + */ +tree.Reference.mapnikFunction = function(name) { + var functions = []; + for (var i in tree.Reference.data.symbolizers) { + for (var j in tree.Reference.data.symbolizers[i]) { + if (tree.Reference.data.symbolizers[i][j].type === 'functions') { + functions = functions.concat(tree.Reference.data.symbolizers[i][j].functions); + } + } + } + return _.find(functions, function(f) { + return f[0] === name; + }); +}; + tree.Reference.requiredPropertyList = function(symbolizer_name) { if (this.required_prop_list_cache[symbolizer_name]) { return this.required_prop_list_cache[symbolizer_name]; diff --git a/package.json b/package.json index f07837e..ae1c170 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ }, "dependencies": { "underscore": "~1.3.3", - "mapnik-reference": "~2.1.0", + "mapnik-reference": "https://github.com/mapnik/mapnik-reference/zipball/transform-functions", "xml2js": "~0.1.13" }, "devDependencies": { diff --git a/test/rendering/transforms.result b/test/rendering/transforms.result index bda0bab..80c5961 100644 --- a/test/rendering/transforms.result +++ b/test/rendering/transforms.result @@ -5,7 +5,7 @@ - +