Created
July 9, 2013 06:33
-
-
Save dbankier/5955147 to your computer and use it in GitHub Desktop.
improved alloy.jmk for jade to support templates and includes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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