Extract templates and automate their compilation