app/soc/views/helper/html_menu.py
author Sverre Rabbelier <srabbelier@gmail.com>
Thu, 13 Nov 2008 16:40:05 +0000
changeset 477 8a8b1bd035c4
parent 449 a4dc4c9e7356
permissions -rw-r--r--
Moved from docs -> document
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
195
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     2
#
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     4
#
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     8
#
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    10
#
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    15
# limitations under the License.
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    16
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    17
"""Helpers for displaying arbitrarily nested menus as HTML lists.
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    18
"""
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    19
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    20
__authors__ = [
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    21
  '"Todd Larsen" <tlarsen@google.com>',
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    22
  ]
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    23
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    24
198
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    25
class HtmlMenu:
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    26
  """Ordered collection of MenuItem objects as <p>...</p> paragraphs.
195
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    27
  """
198
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    28
  ITEM_PREFIX_FMT = '%(indent)s<p>'
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    29
  ITEM_SUFFIX_FMT = '%(indent)s</p>'
195
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    30
198
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    31
  def __init__(self, menu, item_class=None):
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    32
    """Wraps an soc.logic.menu.Menu in order to render it as HTML.
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    33
    
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    34
    Args:
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    35
      menu: an soc.logic.menu.Menu object
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    36
      item_class: style used to render the MenuItems contained in menu;
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    37
        default is None, which causes AHrefMenuItem to be used  
195
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    38
    """
198
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    39
    self._menu = menu
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    40
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    41
    # workaround for circular dependency between AHrefMenuItem and this class
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    42
    if not item_class:
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    43
      item_class = AHrefMenuItem
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    44
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    45
    self._item_class = item_class
195
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    46
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    47
  def getHtmlTags(self, indent):
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    48
    """Returns list of HTML tags for arbitrarily nested items in the menu.
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    49
    
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    50
    Args:
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    51
      indent: string prepended to the beginning of each line of output
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    52
        (usually consists entirely of spaces)
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    53
        
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    54
    Returns:
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    55
      a list of strings that can be joined with '\n' into a single string
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    56
      to produce an entire <ul>...</ul> list in HTML
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    57
    """
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    58
    tags = []
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    59
198
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    60
    if self._menu.items:
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    61
      tags.append(self.ITEM_PREFIX_FMT % {'indent': indent})
195
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    62
198
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    63
      for item in self._menu.items:
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    64
        tags.extend(self._item_class(
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    65
            item, menu_class=self.__class__).getHtmlTags(indent + ' '))
195
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    66
    
198
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    67
      tags.append(self.ITEM_SUFFIX_FMT % {'indent': indent})
195
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    68
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    69
    return tags
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    70
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    71
  def __str__(self):
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    72
    return '\n'.join(self.getHtmlTags(''))
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    73
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    74
198
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    75
class UlMenu(HtmlMenu):
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    76
  """Ordered collection of MenuItem objects as a <ul> list.
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    77
  """
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    78
  ITEM_PREFIX_FMT = '%(indent)s<ul>'
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    79
  ITEM_SUFFIX_FMT = '%(indent)s</ul>'
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    80
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    81
  def __init__(self, menu, item_class=None):
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    82
    """Wraps an soc.logic.menu.Menu in order to render it as HTML.
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    83
    
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    84
    Args:
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    85
      menu: an soc.logic.menu.Menu object
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    86
      item_class: style used to render the MenuItems contained in menu;
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    87
        default is None, which causes LiMenuItem to be used  
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    88
    """
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    89
    # workaround for circular dependency between LiMenuItem and this class
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    90
    if not item_class:
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    91
      item_class = LiMenuItem
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    92
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    93
    HtmlMenu.__init__(self, menu, item_class=item_class)
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    94
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    95
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    96
class HtmlMenuItem:
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
    97
  """Base class for specific MenuItem wrappers used by HtmlMenu sub-classes.
195
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    98
  """
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    99
  
198
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   100
  def __init__(self, item, menu_class=HtmlMenu):
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   101
    """Wraps an soc.logic.menu.MenuItem in order to render it as HTML.
195
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   102
    
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   103
    Args:
198
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   104
      item: an soc.logic.menu.MenuItem object to wrap, in order to produce
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   105
        a representation of it as HTML tags later
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   106
      menu_class: a class derived from HtmlMenu, used to style any sub-menu
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   107
        of the MenuItem; default is HtmlMenu
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   108
    """
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   109
    self._item = self.escapeItem(item)
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   110
    self._menu_class = menu_class
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   111
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   112
  def getItemHtmlTags(self, indent):
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   113
    """Returns list of HTML tags for the menu item itself.
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   114
    
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   115
    This method is intended to be overridden by sub-classes.
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   116
    
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   117
    Args:
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   118
      indent: string prepended to the beginning of each line of output
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   119
        (usually consists entirely of spaces)
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   120
        
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   121
    Returns:
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   122
      a list of strings that can be joined with '\n' into a single string
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   123
      to produce:
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   124
        <b>name</b> value <i>(annotation)</i>
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   125
      with value and/or <i>(annotation)</i> omitted if either is missing
195
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   126
    """
198
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   127
    # TODO(tlarsen): implement "selected" style
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   128
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   129
    tags = ['%s<b>%s</b>' % (indent, self._item.name)]
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   130
    
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   131
    if self._item.value:
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   132
      tags.append('%s%s' % (indent, self._item.value))
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   133
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   134
    if self._item.annotation:
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   135
      tags.append('%s<i>(%s)</i>' % (indent, self._item.annotation))
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   136
      
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   137
    return tags
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   138
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   139
  def getSubMenuHtmlTags(self, indent):
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   140
    """Returns list of HTML tags for any sub-menu, if one exists.
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   141
    
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   142
    Args:
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   143
      indent: string prepended to the beginning of each line of output
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   144
        (usually consists entirely of spaces)
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   145
        
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   146
    Returns:
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   147
      an empty list if there is no sub-menu
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   148
        -OR-
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   149
      the list of HTML tags that render the entire sub-menu (depends on the
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   150
      menu_class that was provided to __init__()
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   151
    """
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   152
    if not self._item.sub_menu:
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   153
      return []
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   154
  
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   155
    return self._menu_class(self._item.sub_menu,
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   156
        item_class=self.__class__).getHtmlTags(indent)
195
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   157
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   158
  def getHtmlTags(self, indent):
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   159
    """Returns list of HTML tags for a menu item (and possibly its sub-menus).
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   160
    
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   161
    Args:
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   162
      indent: string prepended to the beginning of each line of output
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   163
        (usually consists entirely of spaces)
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   164
        
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   165
    Returns:
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   166
      a list of strings that can be joined with '\n' into a single string
198
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   167
      to produce an HTML representation of the wrapped MenuItem, with
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   168
      arbitrarily nested sub-menus possibly appended
195
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   169
    """
198
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   170
    return self.getItemHtmlTags(indent) + self.getSubMenuHtmlTags(indent)
195
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   171
198
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   172
  def escapeItem(self, item):
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   173
    """HTML-escapes possibly user-supplied fields to prevent XSS.
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   174
    
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   175
    Args:
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   176
      item: an soc.logic.menu.MenuItem that is altered in-place; the
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   177
        fields that are potentially user-provided (name, value, annotation)
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   178
        are escaped using self.escapeText()
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   179
        
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   180
    Returns:
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   181
      the originally supplied item, for convenience, so that this method can
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   182
      be combined with an assignment
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   183
    """
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   184
    item.name = self.escapeText(item.name)
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   185
    item.value = self.escapeText(item.value)
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   186
    item.annotation = self.escapeText(item.annotation)
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   187
    return item
195
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   188
198
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   189
  def escapeText(self, text):
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   190
    """
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   191
    """
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   192
    # TODO(tlarsen): user-supplied content *must* be escaped to prevent XSS
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   193
    return text
195
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   194
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   195
  def __str__(self):
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   196
    return '\n'.join(self.getHtmlTags(''))
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   197
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   198
198
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   199
class AHrefMenuItem(HtmlMenuItem):
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   200
  """Provides HTML menu item properties as attributes as an <a href> link. 
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   201
  """
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   202
  
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   203
  def getItemHtmlTags(self, indent):
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   204
    """Returns list of HTML tags for the menu item itself.
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   205
    
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   206
    Args:
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   207
      indent: string prepended to the beginning of each line of output
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   208
        (usually consists entirely of spaces)
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   209
        
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   210
    Returns:
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   211
      a list of strings that can be joined with '\n' into a single string
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   212
      to produce an <a href="...">...</a> link, or just the MenuItem.name
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   213
      as plain text if there was no AHrefMenuItem.value URL
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   214
    """
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   215
    # TODO(tlarsen): implement "selected" style
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   216
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   217
    if not self._item.value:
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   218
      # if no URL, then not a link, so just display item.name as text
423
25665d645fa8 Add javascript expandable menus.
Augie Fackler <durin42@gmail.com>
parents: 420
diff changeset
   219
      return ['%s<span>%s</span>' % (indent, self._item.name)]
198
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   220
  
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   221
    # URL supplied, so make an <a href="item.value">item.name</a> link
449
a4dc4c9e7356 Allowing + and - to be clicked in the menu
Dmitri Gaskin <dmitrig01@gmail.com>
parents: 423
diff changeset
   222
    return ['%s<span><a href="%s">%s</a></span>' % (indent, self._item.value, self._item.name)]
198
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   223
195
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   224
class LiMenuItem(AHrefMenuItem):
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   225
  """Provides HTML menu item properties as attributes as an <li> list item.
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   226
  """
198
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   227
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   228
  def __init__(self, item, menu_class=UlMenu):
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   229
    """Wraps an soc.logic.menu.MenuItem in order to render it as HTML.
195
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   230
    
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   231
    Args:
198
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   232
      item: an soc.logic.menu.MenuItem object to wrap, in order to produce
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   233
        a representation of it as HTML tags later
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   234
      menu_class: a class derived from HtmlMenu, used to style any sub-menu
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   235
        of the MenuItem; default is UlMenu
195
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   236
    """
198
e4cbd0909520 Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents: 196
diff changeset
   237
    AHrefMenuItem.__init__(self, item, menu_class=menu_class)
195
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   238
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   239
  def getHtmlTags(self, indent):
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   240
    """Returns <a href> link wrapped as an <li> list item.
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   241
    
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   242
    See also AHrefMenuItem.getHtmlTags().
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   243
    """
423
25665d645fa8 Add javascript expandable menus.
Augie Fackler <durin42@gmail.com>
parents: 420
diff changeset
   244
    if self._item.sub_menu:
25665d645fa8 Add javascript expandable menus.
Augie Fackler <durin42@gmail.com>
parents: 420
diff changeset
   245
      css_class = 'expandable'
25665d645fa8 Add javascript expandable menus.
Augie Fackler <durin42@gmail.com>
parents: 420
diff changeset
   246
    else:
25665d645fa8 Add javascript expandable menus.
Augie Fackler <durin42@gmail.com>
parents: 420
diff changeset
   247
      css_class = 'leaf'
25665d645fa8 Add javascript expandable menus.
Augie Fackler <durin42@gmail.com>
parents: 420
diff changeset
   248
    
25665d645fa8 Add javascript expandable menus.
Augie Fackler <durin42@gmail.com>
parents: 420
diff changeset
   249
    return (['%s<li class="%s">' % (indent, css_class)]
195
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   250
            + AHrefMenuItem.getHtmlTags(self, indent + ' ')
086282e19995 Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   251
            + ['%s</li>' % indent])