Allow moduleName to be a function

If you store your templates in a hierarchy which matches module names,
you can now automatically generate templates in the right module.

Added tests and updated documentation