Skip to content

Instantly share code, notes, and snippets.

@masylum
Created December 1, 2011 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masylum/1418000 to your computer and use it in GitHub Desktop.
Save masylum/1418000 to your computer and use it in GitHub Desktop.
jader.js
var dir = __dirname + '/app/templates/conversations'
, finder = require('findit').find(dir)
, fs = require('fs')
, _ = require('underscore')
, templates = {}
, num_templates = 0
, all_scanned = false
, jade = require('jade');
function startServer() {
console.log(templates);
}
finder.on('file', function (file) {
if (file.indexOf('.jade') > 0) {
num_templates += 1;
fs.readFile(file, 'utf-8', function (err, data) {
if (err) {
console.error(err);
}
// Ruby stuff
data = _.template(data)({
t: function (s) {
// implement t
return s;
}
});
templates[file.replace(dir + '/', '')] = jade.compile(data, {self: true, compileDebug: false, filename: file});
num_templates -= 1;
if (all_scanned && ! num_templates) {
startServer();
}
});
}
});
finder.on('end', function (file) {
all_scanned = true;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment