diff --git a/lib/mess/tree/definition.js b/lib/mess/tree/definition.js index fc74cfa..c77d2c9 100644 --- a/lib/mess/tree/definition.js +++ b/lib/mess/tree/definition.js @@ -21,9 +21,14 @@ tree.Definition.prototype.filter_symbolizer = function(symbolizer) { }; tree.Definition.prototype.symbolizers = function() { - return this.rules.map(function(rule) { - return rule.symbolizer; - }); + // reduce used to make the result of this + // an array of unique values. + return this.rules.reduce(function(memo, rule) { + if (memo.indexOf(rule.symbolizer) == -1) { + memo.push(rule.symbolizer); + } + return memo; + }, []); }; /** @@ -45,18 +50,31 @@ tree.Definition.prototype.inherit_from = function(definition) { }; tree.Definition.prototype.toXML = function() { - var rules = this.rules.map(function(rule) { + var sym = this.symbolizers(); + if (sym.length !== 1) { + throw { + message: 'A single symbolizer is expected' + + 'in definition compilation' + } + } else { sym = sym[0]; } + + var symname = sym.charAt(0).toUpperCase() + + sym.slice(1).replace(/\-./, function(str) { + return str[1].toUpperCase(); + }) + 'Symbolizer'; + var rules = ' <' + symname + ' ' + this.rules.map(function(rule) { return rule.toCSS(); - }); + }).join('\n ') + '/>'; + var filters = this.selector.filters.map(function(filter) { return filter.toXML(); }); - return ' \n' + + return ' \n ' + filters.join('\n ') + '\n' + - rules.join('\n') + - '\n \n'; + rules + + '\n \n'; }; })(require('mess/tree'));