diff -r ec1dcd70b97e -r 661ab830e921 app/soc/views/helper/html_menu.py --- a/app/soc/views/helper/html_menu.py Thu Nov 20 21:01:18 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,251 +0,0 @@ -#!/usr/bin/python2.5 -# -# Copyright 2008 the Melange authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Helpers for displaying arbitrarily nested menus as HTML lists. -""" - -__authors__ = [ - '"Todd Larsen" ', - ] - - -class HtmlMenu: - """Ordered collection of MenuItem objects as

...

paragraphs. - """ - ITEM_PREFIX_FMT = '%(indent)s

' - ITEM_SUFFIX_FMT = '%(indent)s

' - - def __init__(self, menu, item_class=None): - """Wraps an soc.logic.menu.Menu in order to render it as HTML. - - Args: - menu: an soc.logic.menu.Menu object - item_class: style used to render the MenuItems contained in menu; - default is None, which causes AHrefMenuItem to be used - """ - self._menu = menu - - # workaround for circular dependency between AHrefMenuItem and this class - if not item_class: - item_class = AHrefMenuItem - - self._item_class = item_class - - def getHtmlTags(self, indent): - """Returns list of HTML tags for arbitrarily nested items in the menu. - - Args: - indent: string prepended to the beginning of each line of output - (usually consists entirely of spaces) - - Returns: - a list of strings that can be joined with '\n' into a single string - to produce an entire list in HTML - """ - tags = [] - - if self._menu.items: - tags.append(self.ITEM_PREFIX_FMT % {'indent': indent}) - - for item in self._menu.items: - tags.extend(self._item_class( - item, menu_class=self.__class__).getHtmlTags(indent + ' ')) - - tags.append(self.ITEM_SUFFIX_FMT % {'indent': indent}) - - return tags - - def __str__(self): - return '\n'.join(self.getHtmlTags('')) - - -class UlMenu(HtmlMenu): - """Ordered collection of MenuItem objects as a