Refactor write_docs to split the documentation generation from file writing

Splitting the data generation from persistence allows it to be accessed without
having to read from the file system, like for example a special Rails controller
action that calls the generation method and outputs the JSON. Also, should make
it easier to maintain it.