# -*- coding: utf-8 -*- # # Copyright (C) 2008 Wouter Bolsterlee # # This macro is put in the public domain by the author. Do whatever you want # with it, but it would be nice if your improvements somehow come back to me. # from trac.wiki.api import WikiSystem from trac.util.html import html, escape from trac.wiki.macros import WikiMacroBase class SiblingNavMacro(WikiMacroBase): ''' Show a navigation TOC of the current page hiearchy with a list of sibling pages of the current page. ''' def render_macro(self, req, name, content): current_page = req.args.get('page', 'WikiStart') prefix = content or current_page hierarchy = prefix.split('/') if len(hierarchy) <= 1: hierarchy.append('__DUMMY__') wiki = WikiSystem(self.env) elements = [] # Build items for sibling pages (if any) sibling_items = [] for page in sorted(wiki.get_pages(hierarchy[0]+'/')): page_name = wiki.format_page_name(page[page.rfind('/')+1:]) link = html.A(page_name, href=req.href.wiki(page)) if page == current_page: li = html.LI(link, class_='active') else: li = html.LI(link) sibling_items.append(li) if not sibling_items: return None # Build titles for parent pages for level in hierarchy[0:-1]: title = u'↑ %s' % wiki.format_page_name(level) elements.append(html.H4(html.A(title, href=req.href.wiki(level)))) # Add the list of items elements.append(html.UL(sibling_items)) # Wrapper div for styling div = html.DIV(elements, class_='wiki-toc') # Output return div