(refactor) use function hoisting with pass-func

When passing functions, use function hoisting. This puts the angular
chain closer to the top of the file. It also simplifies the
generator's templates and reduces code duplication inside templates.