public void generate(Book b, File directory) throws IOException {
// FreeMarker configuration
Configuration cfg = new Configuration();
cfg.setDirectoryForTemplateLoading(templateDir);
cfg.setObjectWrapper(new BeansWrapper());
List<String> dirTree = createDirTree(b, directory);
StringBuffer sb = new BookToTOC().generateTOC(b, cfg, dirTree);
File root = saveToFile(new File(directory, dirTree.get(0)), sb);