Model repeat writer refactor

Refactor the writer, similar to what was done in https://github.com/dimagi/Vellum/pull/284

Best reviewed commit-by-commit.
This function calls `processChildren()` and returns immediately [if `mug` evaluates to false](https://github.com/dimagi/Vellum/pull/288/files#diff-7dec243e7443d2aa55101241b38a8575R203). As far as I know `mug.options` (`opts`) is always an object when the mug is not undefined or null.