def test_isEqualToNode(self): """ L{Text.isEqualToNode} returns C{True} if and only if passed a L{Text} which represents the same data. """ self.assertTrue( microdom.Text('foo', raw=True).isEqualToNode( microdom.Text('foo', raw=True))) self.assertFalse( microdom.Text('foo', raw=True).isEqualToNode( microdom.Text('foo', raw=False))) self.assertFalse( microdom.Text('foo', raw=True).isEqualToNode( microdom.Text('bar', raw=True)))
def factory_bugDisplay(self, request, node): rowNode = domhelpers.locateNodes([node], "rowOf", "bugDisplay")[0] node.removeChild(rowNode) bugList = self.model.world.perspectives.values() bugList.sort(lambda a, b: a.angst < b.angst) rank = 0 for bug in bugList: rank += 1 rnode = rowNode.cloneNode(1) node.appendChild(rnode) colNodes = domhelpers.locateNodes([rnode], "columnOf", "bugDisplay") bugDict = { "name": bug.perspectiveName, "angst": bug.angst, "rank": rank } for cn in colNodes: cn.appendChild( microdom.Text(str(bugDict[cn.getAttribute("columnName")]))) return node
def numberDocument(document, chapterNumber): """ Number the sections of the given document. A dot-separated chapter, section number is added to the beginning of each section, as defined by C{h2} nodes. @type document: A DOM Node or Document @param document: The input document which contains all of the content to be presented. @type chapterNumber: C{int} @param chapterNumber: The chapter number of this content in an overall document. @return: C{None} """ i = 1 for node in domhelpers.findNodesNamed(document, "h2"): node.childNodes = [microdom.Text("%s.%d " % (chapterNumber, i))] + node.childNodes i += 1
def insertPrevNextLinks(slides, filename, ext): for slide in slides: for name, offset in (("previous", -1), ("next", +1)): if (slide.pos > 0 and name == "previous") or \ (slide.pos < len(slides)-1 and name == "next"): for node in domhelpers.findElementsWithAttribute( slide.dom, "class", name): if node.tagName == 'a': node.setAttribute( 'href', '%s-%d%s' % (filename[0], slide.pos + offset, ext)) else: node.appendChild( microdom.Text(slides[slide.pos + offset].title)) else: for node in domhelpers.findElementsWithAttribute( slide.dom, "class", name): pos = 0 for child in node.parentNode.childNodes: if child is node: del node.parentNode.childNodes[pos] break pos += 1
def textelement(element, tag, text): el = microdom.Element(tag, preserveCase=1) el.appendChild(microdom.Text(text)) element.appendChild(el)