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.
Plugin writer integration is now possible, which cleans up the core.