Fixing bug with nesting multiple levels

Fixes an error made in a previous fix, which didn't account for multiple levels of nesting when sanitizing the module name for generators.

This was especially apparent in mixins (and utils), as those import the function for use in the associated test, so I added a test for that.

Somebody mentioned this in irc, but I can't remember who. Thanks to that person!