# -*- coding: utf-8 -*- # -*- python -*- ## ## menuformat.py - template and output generation for the Lumiera.org navigation menu ## # Copyright (C) Lumiera.org # 2011, Hermann Vosseler # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. ##################################################################### import string import menugen #------------CONFIGURATION----------------------------- ENTRY_LENGTH = 17 #------------CONFIGURATION----------------------------- menuTemplate = ''' Navigation ''' def generateHTML(buildingBlocks): ''' instantiate the menu template, thereby expanding the placeholders based on the passed in variable mappings ''' engine = string.Template(menuTemplate) return engine.substitute(buildingBlocks) def expandButtonHTML(id): return '+' % id def menuEntryText(node): label = node.label if not label or len(label) > ENTRY_LENGTH: hover = 'title="%s"' % label label = menugen.titleFormatted(node.id) if len(label) > ENTRY_LENGTH: label = label[:ENTRY_LENGTH-3]+'...' else: hover = '' return (label, hover) class HtmlGenerator(menugen.Formatter): INDENT =' ' LEAF ='
  • $LABEL
  • ' PRE_SUB ='' def showNode(self, template, node): nodeID = node.menuPath() (visibleTxt, hover) = menuEntryText(node) self.show (self.format (template, ID=nodeID, URL=node.getUrl(), LABEL=visibleTxt, HOVER=hover, EXPANDBUTTON=expandButtonHTML(nodeID))) class ScriptGenerator(menugen.Formatter): INDENT =' ' LEAF ="menuTable.addNode ('$ID', '$URL', '$PARENT')" PRE_SUB ="menuTable.addNode ('$ID', '$URL', '$PARENT', isSubmenu=true)" POST_SUB ='//(end $ID)' def showNode(self, template, node): self.show (self.format (template, ID=node.menuPath(), URL=node.getUrl(), PARENT=node.getParentUrl()))