First hacks on bin/mess-up.

This commit is contained in:
Tom MacWright 2011-02-07 10:21:38 -05:00
parent 0e517bafaa
commit 91eeb44956

88
bin/mess-up Executable file
View File

@ -0,0 +1,88 @@
#!/usr/bin/env node
var xml2js = require('xml2js'),
fs = require('fs'),
_ = require('underscore')._,
path = require('path'),
sys = require('sys');
require.paths.unshift(path.join(__dirname, '../lib'), path.join(__dirname, '../lib/node'));
var mess = require('mess');
var args = process.argv.slice(1);
var options = {
silent: false,
json: false
};
args = args.filter(function (arg) {
var match;
if (match = arg.match(/^--?([a-z][0-9a-z-]*)$/i)) { arg = match[1] }
else { return arg }
/*
switch (arg) {
case 'h':
case 'help':
sys.puts("Usage: messc source");
sys.puts("Options:");
sys.puts(" -j\tParse JSON map manifest");
process.exit(0);
break;
}
*/
});
var input = args[1];
if (input && input[0] != '/') {
input = path.join(process.cwd(), input);
}
var output = args[2];
if (output && output[0] != '/') {
output = path.join(process.cwd(), output);
}
function upRule(xmlRule) {
this.filters = xmlRule.Filter ? this.upFilter(xmlRule.Filter) : [];
}
upRule.prototype.upFilter = function(xmlFilter) {
var filters = [];
console.log(xmlFilters);
var opXML = {
'<=': '&lt;=',
'>=': '&gt;=',
'=>': '&gt;=',
'!=': '!=',
'<': '&lt;',
'>': '&gt;',
'=': '='
};
var opre = new RegExp('(' + _.keys(opXML).join('|') + ')');
filters = xmlFilters.map(function(f) {
var element = f.match(/\[(\w+)\]/)[1];
var operator = f.match(opre)[1];
return element + ' ' + operator;
});
console.log(filters);
return filters;
}
upRule.prototype.toMSS = function() {
return this.filters.join('');
}
fs.readFile(input, 'utf-8', function (e, data) {
var rules = [];
var firstParser = new xml2js.Parser();
firstParser.addListener('end', function(mapnik_xml) {
mapnik_xml.Style.forEach(function(s) {
s.Rule.forEach(function(r) {
rules.push((new upRule(r)).toMSS());
});
});
}).parseString(data);
console.log(rules);
});