Output valid XML

This commit is contained in:
Tom MacWright 2011-01-20 16:32:59 -05:00
parent c78c9b2818
commit c0121f7682

View File

@ -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,17 +50,30 @@ 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 ' <Rule>\n' +
return ' <Rule>\n ' +
filters.join('\n ') + '\n' +
rules.join('\n') +
rules +
'\n </Rule>\n';
};