carto/build/syntaxgenerate

48 lines
1.6 KiB
Plaintext
Raw Normal View History

2011-02-08 04:10:58 +08:00
#!/usr/bin/env node
var path = require('path'),
fs = require('fs'),
2014-06-11 23:52:06 +08:00
_ = require('underscore')._;
2011-02-08 04:10:58 +08:00
var carto = require('../lib/carto');
var color_names = _.keys(carto.tree.Reference.data.colors);
var property_names = carto.tree.Reference.selectors;
var keyword_names = _.reduce(carto.tree.Reference.data.symbolizers,
function(memo, s) {
for (var i in s) {
if (_.isArray(s[i].type)) {
memo = memo.concat(s[i].type);
}
}
return memo;
}, []);
2011-02-11 22:59:07 +08:00
// TextMate
// --------
// Generate TextMate tmLanguage file for use in bundle
var tm_tmpl = fs.readFileSync(path.join(__dirname, 'tmlanguage_template.js'), 'utf-8');
2011-02-08 04:10:58 +08:00
fs.writeFile('carto.tmLanguage', _.template(tm_tmpl, {
2011-02-08 09:51:38 +08:00
color_names: color_names.filter(function(a) { return a; }).join('|'),
keyword_names: keyword_names.filter(function(a) { return a; }).join('|'),
property_names: property_names.filter(function(a) { return a; }).join('|')
2011-02-08 04:10:58 +08:00
}), function(err) {
if (!err) console.log('tmLanguage created');
});
2011-02-11 22:59:07 +08:00
// VIM
// ---
// Generate carto.syntax
var tm_tmpl = fs.readFileSync(path.join(__dirname, 'vimsyntax_template.js'), 'utf-8');
fs.writeFile('vim-carto/syntax/carto.vim', _.template(tm_tmpl, {
color_names: color_names.filter(function(a) { return a; }).join('\\|'),
keyword_names: keyword_names.filter(function(a) { return a; }).join('\\|'),
property_names: property_names.filter(function(a) {
return a;
}).map(function(a) {
return a.replace(/\-/g, '\\-');
}).join('\\|')
2011-02-11 22:59:07 +08:00
}), function(err) {
if (!err) console.log('carto.vim created');
});