Template engine and code generator