Fixed bug which stopped Loader.generate from working if there are missing directories

Loader.generate would error on line 191, where file_put_contents() was trying to access directories which did not exist.

Unless you can think of a nicer/better way to do this. Please access my pull request.