Support for exporting optional classes; prune empty directives.

The exporter now supports optional classes, and removes empty directives from the output.