|
From: Luke O. <lu...@me...> - 2003-05-09 19:36:52
|
If anyone's interested, I've made modifications to FFK to support the
extraHTML argument from FFK 0.3, for adding attributes within an HTML
tag (we use it for javascript events and CSS classes primarily, for
instance).
This was done with a change to SimpleHTMLGen.Tag to support
'extraHTML' as a special argument (full python below), and then
adding 'extraHTML=self._extraHTMLCode(options)' to the html.input( )
blocks if appropriate. (_extraHTMLCode utility method was already
written by Ian, but not used anywhere, due to the mismatch between
arbitrary attribs and the HTMLGen system, I assume.)
I'm not sure I'm entirely happy with the result, it removes some of
the cleanliness of the HTMLGen process, and users can screw
themselves by putting already-used attrs in extraHTML, but that's how
it's always been. :)
Enjoy,
- Luke
------
SimpleHTMLGen.py:
def Tag(tag, *args, **kw):
if kw.has_key("c"):
assert not args, "The special 'c' keyword argument cannot be
used in conjunction with non-keyword arguments"
args = kw["c"]
del kw["c"]
if type(args) not in (type(()), type([])):
args = (args,)
extraHTML = ''
if kw.has_key("extraHTML"):
extraHTML = " %s" % kw["extraHTML"]
del kw["extraHTML"]
htmlArgs = [' %s="%s"' % (attrEncode(attr), htmlEncode(value))
for attr, value in kw.items()
if value is not Exclude]
if not args and emptyTags.has_key(tag):
if blockTags.has_key(tag):
return "<%s%s%s/>\n" % (tag, "".join(htmlArgs),extraHTML)
else:
return "<%s%s%s/>" % (tag, "".join(htmlArgs),extraHTML)
else:
if blockTags.has_key(tag):
return "<%s%s%s>\n%s\n</%s>\n" % (
tag,
"".join(htmlArgs),
extraHTML,
"".join(map(str, args)),
tag)
else:
return "<%s%s%s>%s</%s>" % (
tag,
"".join(htmlArgs),
extraHTML,
"".join(map(str, args)),
tag)
|