author | Sverre Rabbelier <srabbelier@gmail.com> |
Sun, 19 Oct 2008 00:34:33 +0000 | |
changeset 387 | c55195361cb6 |
parent 276 | 56357a92c110 |
child 390 | d12c95ade374 |
permissions | -rw-r--r-- |
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 |
|
086282e19995
Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
25 |
from soc.logic import menu |
086282e19995
Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
26 |
|
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 |
class HtmlMenu: |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
29 |
"""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
|
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 |
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
|
32 |
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
|
33 |
|
198
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
34 |
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
|
35 |
"""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
|
36 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
37 |
Args: |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
38 |
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
|
39 |
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
|
40 |
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
|
41 |
""" |
198
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
42 |
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
|
43 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
44 |
# 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
|
45 |
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
|
46 |
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
|
47 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
48 |
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
|
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 |
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
|
51 |
"""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
|
52 |
|
086282e19995
Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
53 |
Args: |
086282e19995
Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
54 |
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
|
55 |
(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
|
56 |
|
086282e19995
Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
57 |
Returns: |
086282e19995
Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
58 |
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
|
59 |
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
|
60 |
""" |
086282e19995
Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
61 |
tags = [] |
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 |
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
|
64 |
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
|
65 |
|
198
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
|
198
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
70 |
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
|
71 |
|
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 tags |
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 |
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
|
75 |
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
|
76 |
|
086282e19995
Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
77 |
|
198
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
78 |
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
|
79 |
"""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
|
80 |
""" |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
81 |
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
|
82 |
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
|
83 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
84 |
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
|
85 |
"""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
|
86 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
87 |
Args: |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
88 |
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
|
89 |
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
|
90 |
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
|
91 |
""" |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
92 |
# 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
|
93 |
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
|
94 |
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
|
95 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
96 |
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
|
97 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
98 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
99 |
class HtmlMenuItem: |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
100 |
"""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
|
101 |
""" |
086282e19995
Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
102 |
|
198
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
103 |
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
|
104 |
"""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
|
105 |
|
086282e19995
Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
106 |
Args: |
198
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
107 |
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
|
108 |
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
|
109 |
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
|
110 |
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
|
111 |
""" |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
112 |
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
|
113 |
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
|
114 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
115 |
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
|
116 |
"""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
|
117 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
118 |
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
|
119 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
120 |
Args: |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
121 |
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
|
122 |
(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
|
123 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
124 |
Returns: |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
125 |
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
|
126 |
to produce: |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
127 |
<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
|
128 |
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
|
129 |
""" |
198
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
130 |
# 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
|
131 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
132 |
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
|
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.value: |
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%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
|
136 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
137 |
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
|
138 |
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
|
139 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
140 |
return tags |
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 |
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
|
143 |
"""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
|
144 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
145 |
Args: |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
146 |
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
|
147 |
(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
|
148 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
149 |
Returns: |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
150 |
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
|
151 |
-OR- |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
152 |
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
|
153 |
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
|
154 |
""" |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
155 |
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
|
156 |
return [] |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
157 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
158 |
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
|
159 |
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
|
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 |
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
|
162 |
"""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
|
163 |
|
086282e19995
Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
164 |
Args: |
086282e19995
Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
165 |
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
|
166 |
(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
|
167 |
|
086282e19995
Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
168 |
Returns: |
086282e19995
Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
169 |
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
|
170 |
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
|
171 |
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
|
172 |
""" |
198
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
173 |
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
|
174 |
|
198
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
175 |
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
|
176 |
"""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
|
177 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
178 |
Args: |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
179 |
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
|
180 |
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
|
181 |
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
|
182 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
183 |
Returns: |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
184 |
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
|
185 |
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
|
186 |
""" |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
187 |
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
|
188 |
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
|
189 |
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
|
190 |
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
|
191 |
|
198
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
192 |
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
|
193 |
""" |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
194 |
""" |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
195 |
# 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
|
196 |
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
|
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 |
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
|
199 |
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
|
200 |
|
086282e19995
Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
201 |
|
198
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
202 |
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
|
203 |
"""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
|
204 |
""" |
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 |
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
|
207 |
"""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
|
208 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
209 |
Args: |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
210 |
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
|
211 |
(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
|
212 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
213 |
Returns: |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
214 |
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
|
215 |
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
|
216 |
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
|
217 |
""" |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
218 |
# 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
|
219 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
220 |
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
|
221 |
# if no URL, then not a link, so just display item.name as text |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
222 |
return [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
|
223 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
224 |
# URL supplied, so make an <a href="item.value">item.name</a> link |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
225 |
return ['%s<a href=' % indent, |
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
226 |
'%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
|
227 |
'%s>%s</a>' % (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
|
228 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
229 |
|
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 |
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
|
231 |
"""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
|
232 |
""" |
198
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
233 |
|
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
234 |
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
|
235 |
"""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
|
236 |
|
086282e19995
Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
237 |
Args: |
198
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
238 |
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
|
239 |
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
|
240 |
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
|
241 |
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
|
242 |
""" |
198
e4cbd0909520
Major refactoring, to switch from using inheritance from soc.logic.menu classes
Todd Larsen <tlarsen@google.com>
parents:
196
diff
changeset
|
243 |
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
|
244 |
|
086282e19995
Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
245 |
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
|
246 |
"""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
|
247 |
|
086282e19995
Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
248 |
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
|
249 |
""" |
086282e19995
Classes that wrap soc.logic.menu.Menu and soc.logic.menu.MenuItem to produce
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
250 |
return (['%s<li>' % 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 |
+ 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
|
252 |
+ ['%s</li>' % indent]) |