Add field type, parsing, and failing test.
This commit is contained in:
parent
8a97258025
commit
ea89af6ae2
@ -51,7 +51,7 @@ var carto = {
|
||||
};
|
||||
|
||||
[ 'call', 'color', 'comment', 'definition', 'dimension',
|
||||
'directive', 'element', 'expression', 'filterset', 'filter',
|
||||
'directive', 'element', 'expression', 'filterset', 'filter', 'field',
|
||||
'keyword', 'layer', 'operation', 'quoted', 'imagefilter',
|
||||
'reference', 'rule', 'ruleset', 'selector', 'style', 'url', 'value',
|
||||
'variable', 'zoom', 'invalid', 'fontset'
|
||||
|
@ -423,6 +423,20 @@ carto.Parser = function Parser(env) {
|
||||
}
|
||||
},
|
||||
|
||||
// A reference to a Mapnik field, like
|
||||
//
|
||||
// [NAME]
|
||||
//
|
||||
// Behind the scenes, this has the same representation, but Carto
|
||||
// needs to be careful to warn when unsupported operations are used.
|
||||
field: function() {
|
||||
if (! $('[')) return;
|
||||
var field_name = $(/(^[a-zA-Z0-9\-_]+)/);
|
||||
if (! $(']')) return;
|
||||
if (field_name) return new tree.Field(field_name[1]);
|
||||
},
|
||||
|
||||
// This is a comparison operator
|
||||
comparison: function() {
|
||||
var str = $(/^=~|=|!=|<=|>=|<|>/);
|
||||
if (str) {
|
||||
@ -553,7 +567,9 @@ carto.Parser = function Parser(env) {
|
||||
variable: function() {
|
||||
var name;
|
||||
|
||||
if (input.charAt(i) === '@' && (name = $(/^(@[\w-]+)\s*:/))) { return name[1]; }
|
||||
if (input.charAt(i) === '@' && (name = $(/^(@[\w-]+)\s*:/))) {
|
||||
return name[1];
|
||||
}
|
||||
},
|
||||
|
||||
//
|
||||
@ -561,8 +577,12 @@ carto.Parser = function Parser(env) {
|
||||
// and can be found inside a rule's value.
|
||||
//
|
||||
entity: function() {
|
||||
return $(this.entities.literal) || $(this.entities.variable) || $(this.entities.url) ||
|
||||
$(this.entities.call) || $(this.entities.keyword);
|
||||
return $(this.entities.literal) ||
|
||||
$(this.entities.field) ||
|
||||
$(this.entities.variable) ||
|
||||
$(this.entities.url) ||
|
||||
$(this.entities.call) ||
|
||||
$(this.entities.keyword);
|
||||
},
|
||||
|
||||
//
|
||||
|
16
lib/carto/tree/field.js
Normal file
16
lib/carto/tree/field.js
Normal file
@ -0,0 +1,16 @@
|
||||
(function(tree) {
|
||||
|
||||
tree.Field = function Field(content) {
|
||||
this.value = content || '';
|
||||
this.is = 'field';
|
||||
};
|
||||
tree.Field.prototype = {
|
||||
toString: function(quotes) {
|
||||
return '[' + this.value + ']';
|
||||
},
|
||||
'eval': function() {
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
})(require('../tree'));
|
23
test/rendering/field.mml
Normal file
23
test/rendering/field.mml
Normal file
@ -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": [
|
||||
"field.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"
|
||||
}
|
||||
}]
|
||||
}
|
6
test/rendering/field.mss
Normal file
6
test/rendering/field.mss
Normal file
@ -0,0 +1,6 @@
|
||||
#world {
|
||||
text-name: [NAME];
|
||||
text-size: 11;
|
||||
text-face-name: "Georgia Regular", "Arial Italic";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user