Skip to content

Instantly share code, notes, and snippets.

@dbankier
Created July 9, 2013 06:33
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 dbankier/5955147 to your computer and use it in GitHub Desktop.
Save dbankier/5955147 to your computer and use it in GitHub Desktop.
improved alloy.jmk for jade to support templates and includes
task("pre:compile", function(event,logger) {
var wrench = require("wrench"),
fs = require("fs"),
jade = require("jade"),
view_root = event.dir.project,
path = require("path");
event.alloyConfig.xml = [];
wrench.readdirSyncRecursive(view_root).forEach(function(view) {
if (view.match(/.jade$/)
&& view.indexOf("templates") === -1
&& view.indexOf("includes") === -1) {
event.alloyConfig.xml.push(view.replace(/\.jade$/, ".xml"));
try {
fs.writeFileSync(
path.join(view_root,view.replace(/\.jade$/, ".xml")),
jade.compile(fs.readFileSync(path.join(view_root,view)).toString(),
{filename: path.join(view_root, view),
pretty: true})(event));
} catch(e) {
logger.error("ERROR: " + view + "\n" + JSON.stringify(e));
process.exit(1);
}
}
});
});
task("post:compile",function(event,logger){
var fs = require("fs"),
view_root = event.dir.project,
path = require("path");
event.alloyConfig.xml.forEach(function(view){
if (!view.match(/index.xml/g)) {
fs.unlinkSync(path.join(view_root, view));
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment