#34 closed enhancement (fixed)
Expand calls of py:def macros within attributes to text
Reported by: | cboos | Owned by: | cmlenz |
---|---|---|---|
Priority: | major | Milestone: | 0.2 |
Component: | Template processing | Version: | 0.1 |
Keywords: | Cc: |
Description
Currently, when one call a macro within an attribute, this evaluates to "<generator ...>". Instead, one would like to retrieve the text value of the macro's content.
Example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://markup.edgewall.org/" > <body> <py:def function="attr">${'xyz'}</py:def> <p value="${attr()}">...</p> <p py:attrs="{'value': attr(), 'test':1, 'none': None}">...</p> </body> </html>
Would currently be rendered as:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <body> <p value="<generator object at 0x00B81E18>">...</p> <p test="1" value="<generator object at 0x00B850F8>">...</p> </body> </html>
One would expect to get 'xyz' there instead.
Attachments (1)
Change History (5)
Changed 18 years ago by cboos
comment:1 Changed 18 years ago by cboos
With attachment:expand_pydefs-r230.patch, the result would be, as expected:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <body> <p value="xyz">...</p> <p test="1" value="xyz">...</p> </body> </html>
comment:2 Changed 18 years ago by cmlenz
- Status changed from new to assigned
I'm going for a simpler approach:
-
markup/template.py
910 910 value = substream 911 911 else: 912 912 values = [] 913 for subkind, subdata, subpos in substream: 914 if subkind is EXPR: 915 values.append(subdata.evaluate(ctxt)) 916 else: 913 for subkind, subdata, subpos in self._eval(substream, 914 ctxt): 915 if subkind is TEXT: 917 916 values.append(subdata) 918 value = [ unicode(x)for x in values if x is not None]917 value = [x for x in values if x is not None] 919 918 if not value: 920 919 continue 921 920 new_attrib.append((name, u''.join(value)))
comment:3 Changed 18 years ago by cmlenz
- Resolution set to fixed
- Status changed from assigned to closed
Checked in in [232].
comment:4 Changed 18 years ago by cboos
An example of what the patch fixed and what r232 doesn't fix:
(<a href="#file$idx" title="Show differences">${"%s%s%s" % ( plural(ndiffs,'diff'), (ndiffs and nprops) and ', ' or '', plural(nprops, 'prop'))}</a>)
... so for now the above has to be written:
(<a href="#file$idx" title="Show differences">${plural(ndiffs,'diff')}${(ndiffs and nprops) and ', ' or ''}${plural(nprops, 'prop')}</a>)
Note: See
TracTickets for help on using
tickets.
A possible implementation of the feature, on top of r230.