The purpose of this function is to assist in building an
XHTML element that may have class
attributes attached that come from multiple sources. It
accepts a variable number of arguments, each of which
specifies zero or more CSS class names in the form
described in Section 14.2, “class-dict”.
For example, et.CLASS('a', 'b') would return
the dictionary {'class': 'a b'}. The
manifest constants defined in Section 13.4, “CSS constants”, which have names starting with “CSS_”, specify CSS classes in this way.
The purpose of the combineCss() function,
then, is to produce a class-dict dictionary
that combines class names from multiple sources. The
function takes a variable number of arguments, each of
which can be either None or a class-dict. If none of the arguments specify any
class names, it returns an empty dictionary, otherwise it
returns a class-dict that includes all the
specified class names.
# - - - c o m b i n e C s s
def combineCss(*cssList):
'''Build a class-dict from multiple class-dicts.
[ cssList is a list whose members are either class-dicts
or None ->
if cssList is empty or contains only None elements ->
return a new, empty dictionary
else ->
return a class-dict representing all the class names
named in cssList ]
'''
#-- 1
nameList = []
#-- 2
# [ nameList +:= classes named in cssList ]
for d in cssList:
#-- 2 body
# [ if d is None ->
# I
# else ->
# nameList +:= classes named in d ]
if d is not None:
nameList += d['class'].split()
#-- 3
if len(nameList) == 0:
return {}
else:
return {'class': ' '.join(nameList)}