Hook for defining custom function (like the jQuery.fn): .. sourcecode:: python >>> fn = lambda: this.map(lambda i, el: PyQuery(this).outerHtml()) >>> PyQuery.fn.listOuterHtml = fn >>> S = PyQuery( ... ' Coffee Tea Milk</
| 1491 | return self |
| 1492 | |
| 1493 | class Fn(object): |
| 1494 | """Hook for defining custom function (like the jQuery.fn): |
| 1495 | |
| 1496 | .. sourcecode:: python |
| 1497 | |
| 1498 | >>> fn = lambda: this.map(lambda i, el: PyQuery(this).outerHtml()) |
| 1499 | >>> PyQuery.fn.listOuterHtml = fn |
| 1500 | >>> S = PyQuery( |
| 1501 | ... '<ol> <li>Coffee</li> <li>Tea</li> <li>Milk</li> </ol>') |
| 1502 | >>> S('li').listOuterHtml() |
| 1503 | ['<li>Coffee</li>', '<li>Tea</li>', '<li>Milk</li>'] |
| 1504 | |
| 1505 | """ |
| 1506 | def __setattr__(self, name, func): |
| 1507 | def fn(self, *args, **kwargs): |
| 1508 | func.__globals__['this'] = self |
| 1509 | return func(*args, **kwargs) |
| 1510 | fn.__name__ = name |
| 1511 | setattr(PyQuery, name, fn) |
| 1512 | fn = Fn() |
| 1513 | |
| 1514 | ######## |