Some refactoring to make all per-XXX templates get generated. refs #474, #475, #476, #477