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.
Good point. I improved the docs:
- https://github.com/dimagi/Vellum/pull/288/files#diff-fb1b9e010259d16ab20a8186e2d67b23R365
- https://github.com/dimagi/Vellum/pull/288/files#diff-4af05febdf3520f832e8317dd7797dedR413