def _generate_tag_structure(cls, root, registry, tag_manager): tag_directory = Directory(tag_manager.dirname) tag_to_ref_str_map = {} for tag, subpages in sorted(tag_manager.tag_dict.items()): links = cls._yield_links_to_subpages(registry, subpages) tag_page_html = TAG_PAGE_TEMPLATE.format(tag_name=tag, links="\n".join( list(links))) tag_page = HtmlPage(tag_page_html, tag + ".html") tag_page.alt_title = tag tag_directory.add_file(tag_page) tag_ref_str = registry.register_item_as_ref_str(tag_page) tag_to_ref_str_map[tag] = tag_ref_str links = [] for tag, tag_ref in tag_to_ref_str_map.items(): no_items = len(tag_manager.tag_dict[tag]) no_tags = "(%s items)" if no_items > 1 else "(%s item)" links.append( LINK_TEMPLATE.format(page_name=tag, ref_str=tag_ref, no_tags=no_tags % no_items, description="")) tag_index_html = TAG_INDEX_TEMPLATE.format(links="\n".join(links)) tag_index_outer = HtmlPage(tag_index_html, "%s.html" % tag_manager.dirname) tag_index_outer.alt_title = tag_manager.alt_title root.add_subdir(tag_directory) root.add_file(tag_index_outer) tag_directory.add_copy_as_index(tag_index_outer) return tag_to_ref_str_map
def tree(): root = Directory("/") subdir = Directory("subdir") root.add_subdir(subdir) subdir.parent = root file_in_root = HtmlPage("<body><img src='subdir/img.jpg' /></body>", "file_in_root.html") root.add_file(file_in_root) file_in_root.parent = root file_in_subdir = HtmlPage( "<body><a href='../file_in_root.html'>asd</a></body>", 'file_in_subdir.html') subdir.add_file(file_in_subdir) file_in_subdir.parent = subdir image_in_subdir = Data('/subdir/img.jpg', 'IMG_CONTENT') subdir.add_file(image_in_subdir) image_in_subdir.parent = subdir return root