Factor out duplication from Jade and EJS compilers